"use strict";
exports.id = 7264;
exports.ids = [7264];
exports.modules = {

/***/ 347264:
/***/ (function(__unused_webpack_module, exports) {


/*
 *  This file is part of CoCalc: Copyright © 2022 Sagemath, Inc.
 *  License: AGPLv3 s.t. "Commons Clause" – see LICENSE.md for details
 */
var __values = (this && this.__values) || function(o) {
    var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
    if (m) return m.call(o);
    if (o && typeof o.length === "number") return {
        next: function () {
            if (o && i >= o.length) o = void 0;
            return { value: o && o[i++], done: !o };
        }
    };
    throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
};
Object.defineProperty(exports, "__esModule", ({ value: true }));
exports.emailBelongsToDomain = exports.getEmailDomain = exports.checkRequiredSSO = void 0;
function checkRequiredSSO(opts) {
    var e_1, _a, e_2, _b;
    var email = opts.email, strategies = opts.strategies, specificStrategy = opts.specificStrategy;
    // 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;
    var emailDomain = getEmailDomain(email);
    if (!emailDomain)
        return;
    try {
        for (var strategies_1 = __values(strategies), strategies_1_1 = strategies_1.next(); !strategies_1_1.done; strategies_1_1 = strategies_1.next()) {
            var strategy = strategies_1_1.value;
            if (specificStrategy && specificStrategy !== strategy.name)
                continue;
            try {
                for (var _c = (e_2 = void 0, __values(strategy.exclusiveDomains)), _d = _c.next(); !_d.done; _d = _c.next()) {
                    var ssoDomain = _d.value;
                    if (emailBelongsToDomain(emailDomain, ssoDomain)) {
                        return strategy;
                    }
                }
            }
            catch (e_2_1) { e_2 = { error: e_2_1 }; }
            finally {
                try {
                    if (_d && !_d.done && (_b = _c.return)) _b.call(_c);
                }
                finally { if (e_2) throw e_2.error; }
            }
        }
    }
    catch (e_1_1) { e_1 = { error: e_1_1 }; }
    finally {
        try {
            if (strategies_1_1 && !strategies_1_1.done && (_a = strategies_1.return)) _a.call(strategies_1);
        }
        finally { if (e_1) throw e_1.error; }
    }
}
exports.checkRequiredSSO = checkRequiredSSO;
function getEmailDomain(email) {
    return email.trim().toLowerCase().split("@")[1];
}
exports.getEmailDomain = getEmailDomain;
function emailBelongsToDomain(emailDomain, ssoDomain) {
    return emailDomain === ssoDomain || emailDomain.endsWith(".".concat(ssoDomain));
}
exports.emailBelongsToDomain = emailBelongsToDomain;
//# sourceMappingURL=check-required-sso.js.map

/***/ })

};
;