UNPKG

n8n

Version:

n8n Workflow Automation Tool

49 lines 2.31 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.handleLdapLogin = void 0; const typedi_1 = require("typedi"); const InternalHooks_1 = require("../../InternalHooks"); const ldap_service_1 = require("../../Ldap/ldap.service"); const helpers_1 = require("../../Ldap/helpers"); const handleLdapLogin = async (loginId, password) => { var _a; if (!(0, helpers_1.isLdapEnabled)()) return undefined; const ldapService = typedi_1.Container.get(ldap_service_1.LdapService); if (!ldapService.config.loginEnabled) return undefined; const { loginIdAttribute, userFilter } = ldapService.config; const ldapUser = await ldapService.findAndAuthenticateLdapUser(loginId, password, loginIdAttribute, userFilter); if (!ldapUser) return undefined; const [ldapId, ldapAttributesValues] = (0, helpers_1.mapLdapAttributesToUser)(ldapUser, ldapService.config); const { email: emailAttributeValue } = ldapAttributesValues; if (!ldapId || !emailAttributeValue) return undefined; const ldapAuthIdentity = await (0, helpers_1.getAuthIdentityByLdapId)(ldapId); if (!ldapAuthIdentity) { const emailUser = await (0, helpers_1.getUserByEmail)(emailAttributeValue); if (emailUser && emailUser.email === emailAttributeValue) { const identity = await (0, helpers_1.createLdapAuthIdentity)(emailUser, ldapId); await (0, helpers_1.updateLdapUserOnLocalDb)(identity, ldapAttributesValues); } else { const user = await (0, helpers_1.createLdapUserOnLocalDb)(ldapAttributesValues, ldapId); void typedi_1.Container.get(InternalHooks_1.InternalHooks).onUserSignup(user, { user_type: 'ldap', was_disabled_ldap_user: false, }); return user; } } else { if (ldapAuthIdentity.user) { if (ldapAuthIdentity.user.disabled) return undefined; await (0, helpers_1.updateLdapUserOnLocalDb)(ldapAuthIdentity, ldapAttributesValues); } } return (_a = (await (0, helpers_1.getAuthIdentityByLdapId)(ldapId))) === null || _a === void 0 ? void 0 : _a.user; }; exports.handleLdapLogin = handleLdapLogin; //# sourceMappingURL=ldap.js.map