UNPKG

@arc-publishing/sdk-identity

Version:
43 lines 1.92 kB
import { __assign, __awaiter, __generator } from "tslib"; import { headers } from './constants'; import { isAPIErrorResponse } from '../serviceHelpers/APIErrorResponse'; import Identity from './identity'; import JSONResponseHandler from '../serviceHelpers/JSONResponseHandler'; export var initiateOIDC = function (oidcClientId, scopes, redirect, isApple) { if (redirect === void 0) { redirect = true; } if (isApple === void 0) { isApple = false; } return __awaiter(void 0, void 0, void 0, function () { return __generator(this, function (_a) { return [2, fetch("".concat(Identity.apiOrigin, "/identity/public/v2/oidc/").concat(oidcClientId, "/initiate"), { method: 'GET', headers: __assign({}, headers) }) .then(JSONResponseHandler) .then(function (json) { if (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; } } })]; }); }); }; export default initiateOIDC; //# sourceMappingURL=initiateOIDC.js.map