@cocalc/server
Version:
CoCalc server functionality: functions used by either the hub and the next.js server
45 lines • 1.69 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const pool_1 = __importDefault(require("@cocalc/database/pool"));
const parse_domain_1 = require("parse-domain");
async function isDomainExclusiveSSO(email_address) {
if (!email_address) {
return;
}
const raw_domain = email_address.split("@")[1]?.trim().toLowerCase();
if (!raw_domain) {
return;
}
const exclusiveDomains = await getExclusiveDomains();
if (exclusiveDomains.length == 0) {
// For most servers, this is the case.
return;
}
const parsed = (0, parse_domain_1.parseDomain)(raw_domain);
if (parsed.type != parse_domain_1.ParseResultType.Listed) {
// Domain not in the public suffix list
return;
}
const { domain, topLevelDomains } = parsed;
const canonical = [domain ?? "", ...topLevelDomains].join(".");
if (exclusiveDomains.includes(canonical)) {
return canonical;
}
}
exports.default = isDomainExclusiveSSO;
async function getExclusiveDomains() {
const pool = (0, pool_1.default)("minutes"); // exclusive sso is meant for a on prem settings where config RARELY changes.
const { rows } = await pool.query("SELECT conf#>'{exclusive_domains}' as exclusive_domains FROM passport_settings");
const v = [];
for (const row of rows) {
const { exclusive_domains } = row;
if (exclusive_domains) {
v.push(...exclusive_domains);
}
}
return v;
}
//# sourceMappingURL=is-domain-exclusive-sso.js.map