UNPKG

@arc-publishing/sdk-identity

Version:
47 lines 2.19 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.initiateOIDC = void 0; var tslib_1 = require("tslib"); var constants_1 = require("./constants"); var APIErrorResponse_1 = require("../serviceHelpers/APIErrorResponse"); var identity_1 = tslib_1.__importDefault(require("./identity")); var JSONResponseHandler_1 = tslib_1.__importDefault(require("../serviceHelpers/JSONResponseHandler")); var initiateOIDC = function (oidcClientId, scopes, redirect, isApple) { if (redirect === void 0) { redirect = true; } if (isApple === void 0) { isApple = false; } return tslib_1.__awaiter(void 0, void 0, void 0, function () { return tslib_1.__generator(this, function (_a) { return [2, fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v2/oidc/").concat(oidcClientId, "/initiate"), { method: 'GET', headers: tslib_1.__assign({}, constants_1.headers) }) .then(JSONResponseHandler_1.default) .then(function (json) { if ((0, APIErrorResponse_1.isAPIErrorResponse)(json)) { throw json; } else { if (redirect) { if (scopes && scopes.length) { var url = new URL(json.url); url.searchParams.set('scope', scopes.join(' ')); if (isApple) { url.searchParams.set('response_mode', 'form_post'); } window.location.href = url.toString(); } else { window.location.href = json.url; } } else { return json; } } })]; }); }); }; exports.initiateOIDC = initiateOIDC; exports.default = exports.initiateOIDC; //# sourceMappingURL=initiateOIDC.js.map