UNPKG

@cocalc/server

Version:

CoCalc server functionality: functions used by either the hub and the next.js server

39 lines 1.5 kB
"use strict"; /* * This file is part of CoCalc: Copyright © 2022 Sagemath, Inc. * License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details */ Object.defineProperty(exports, "__esModule", { value: true }); exports.emailBelongsToDomain = exports.getEmailDomain = exports.checkRequiredSSO = void 0; function checkRequiredSSO(opts) { const { email, strategies, specificStrategy } = opts; // if the domain of email is contained in any of the strategie's exclusiveDomain array, return that strategy's name if (email == null) return; if (strategies == null || strategies.length === 0) return; if (email.indexOf("@") === -1) return; const emailDomain = getEmailDomain(email); if (!emailDomain) return; for (const strategy of strategies) { if (specificStrategy && specificStrategy !== strategy.name) continue; for (const ssoDomain of strategy.exclusiveDomains) { if (emailBelongsToDomain(emailDomain, ssoDomain)) { return strategy; } } } } exports.checkRequiredSSO = checkRequiredSSO; function getEmailDomain(email) { return email.trim().toLowerCase().split("@")[1]; } exports.getEmailDomain = getEmailDomain; function emailBelongsToDomain(emailDomain, ssoDomain) { return emailDomain === ssoDomain || emailDomain.endsWith(`.${ssoDomain}`); } exports.emailBelongsToDomain = emailBelongsToDomain; //# sourceMappingURL=check-required-sso.js.map