UNPKG

@sap-cloud-sdk/connectivity

Version:

SAP Cloud SDK for JavaScript connectivity

33 lines 841 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.getIssuerSubdomain = getIssuerSubdomain; const url_1 = require("url"); /** * @internal */ function getIssuerSubdomain(decodedJwt) { const iss = decodedJwt?.iss; if (iss) { if (!isValidUrl(iss)) { throw new Error(`Issuer URL in JWT is not a valid URL: "${iss}".`); } return getHost(new url_1.URL(iss)).split('.')[0]; } } function getHost(url) { const { host } = url; if (!host || host.indexOf('.') === -1) { throw new Error(`Failed to determine sub-domain: invalid host in "${url}".`); } return host; } function isValidUrl(url) { try { new url_1.URL(url); return true; } catch { return false; } } //# sourceMappingURL=subdomain-replacer.js.map