UNPKG

@arc-publishing/sdk-identity

Version:
54 lines 2.7 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); var tslib_1 = require("tslib"); var constants_1 = require("./constants"); var identity_1 = tslib_1.__importDefault(require("./identity")); var userIdentity_1 = require("./userIdentity"); var JSONResponseHandler_1 = tslib_1.__importDefault(require("../serviceHelpers/JSONResponseHandler")); function signInWithOIDC(code, state) { return tslib_1.__awaiter(this, void 0, void 0, function () { var headers, getParams; return tslib_1.__generator(this, function (_a) { switch (_a.label) { case 0: headers = tslib_1.__assign({}, constants_1.headers); if (!(identity_1.default.userIdentity && identity_1.default.userIdentity.accessToken && identity_1.default.userIdentity.refreshToken)) return [3, 2]; return [4, identity_1.default.heartbeat()]; case 1: _a.sent(); headers['Authorization'] = "Bearer ".concat(identity_1.default.userIdentity.accessToken); _a.label = 2; case 2: getParams = function () { var params = { code: code }; if (state) { params = tslib_1.__assign(tslib_1.__assign({}, params), { state: state }); } return new URLSearchParams(params).toString(); }; return [2, fetch("".concat(identity_1.default.apiOrigin, "/identity/public/v2/oidc/signin?").concat(getParams()), { method: 'GET', headers: tslib_1.__assign({}, headers) }) .then(JSONResponseHandler_1.default) .then(function (json) { localStorage.removeItem(constants_1.PROFILE_STORAGE_KEY_EXPIRED_TIME); if ((0, userIdentity_1.isUserIdentity)(json)) { identity_1.default.userIdentity = json; window.postMessage({ type: 'ARC_LOGIN_SUCCESS', grantType: 'OIDC' }, '*'); return identity_1.default.userIdentity; } else { throw json; } })]; } }); }); } exports.default = signInWithOIDC; //# sourceMappingURL=signInWithOIDC.js.map