ya-express-ntlm
Version:
81 lines • 3.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.prepareOptions = void 0;
const af_color_1 = require("af-color");
const interfaces_1 = require("./interfaces");
const debug_1 = require("./express-ntlm/debug");
const constants_1 = require("./express-ntlm/lib/constants");
const prepareOptions = (options) => {
const opt = (options || {});
// As proxyId we use the domain name obtained from challenge messages
// or from the getDomain() function
if (typeof opt.getProxyId !== 'function') {
opt.getProxyId = (rsn) => {
const proxyId = rsn.req.ntlm.domain || rsn.options.getDomain(rsn) || 'foo';
(0, debug_1.debugNtlmLdapProxyId)(`↑ ${proxyId}`);
return proxyId;
};
}
if (typeof opt.onMessageType2 !== 'function') {
opt.onMessageType2 = (rsn, messageType2Parsed, _proxyCache, _proxyId) => {
if (messageType2Parsed.domain) {
(0, debug_1.debugNtlmLdapProxyId)(`↓ ${messageType2Parsed.domain}`);
rsn.req.ntlm.domain = messageType2Parsed.domain;
}
};
}
if (typeof opt.getCachedUserData !== 'function') {
opt.getCachedUserData = (rsn) => rsn.req.socket?.ntlm || {};
}
if (typeof opt.addCachedUserData !== 'function') {
opt.addCachedUserData = (rsn, userData) => {
rsn.req.socket.ntlm = userData;
};
}
if (typeof opt.getStrategy !== 'function') {
opt.getStrategy = () => interfaces_1.EAuthStrategy.NTLM;
}
if (typeof opt.getTlsOptions !== 'function') {
opt.getTlsOptions = () => undefined;
}
if (typeof opt.getDomainControllers !== 'function') {
opt.getDomainControllers = () => ['ldap://alfa.com'];
}
if (typeof opt.getDomain !== 'function') {
opt.getDomain = () => 'ALFA';
}
if (typeof opt.getAuthDelay !== 'function') {
opt.getAuthDelay = () => constants_1.DELAY_BETWEEN_USER_AUTHENTICATE_CHALLENGES_MILLIS;
}
if (typeof opt.handleHttpError400 !== 'function') {
opt.handleHttpError400 = (res, message) => {
const msg = message?.message || message || 'Bad request (during NTLM authentication)';
(0, debug_1.debugNtlmAuthFlow)(`${af_color_1.red}HTTP 400: ${message?.stack || msg}`);
res.status(400).send(`HTTP 400: ${msg}`);
};
}
if (typeof opt.handleHttpError403 !== 'function') {
opt.handleHttpError403 = (rsn) => {
const { req, res } = rsn;
const { username, domain, uri } = req.ntlm || {};
const msg = `HTTP 403: User ${username} did not pass authorization in the "${domain}" domain / ${uri}`;
(0, debug_1.debugNtlmAuthFlow)(af_color_1.red + msg);
res.status(403).send(msg);
};
}
if (typeof opt.handleHttpError500 !== 'function') {
opt.handleHttpError500 = (res, message) => {
const msg = message?.message || message || 'Internal server error (during NTLM authentication)';
(0, debug_1.debugNtlmAuthFlow)(`${af_color_1.red}HTTP 500: ${message?.stack || msg}`);
res.status(500).send(`HTTP 500: ${msg}`);
};
}
if (typeof opt.handleSuccessAuthentication !== 'function') {
opt.handleSuccessAuthentication = (rsn) => {
rsn.next();
};
}
return opt;
};
exports.prepareOptions = prepareOptions;
//# sourceMappingURL=prepare-options.js.map