@axa-fr/react-oidc 6.24.27-alpha928 → 6.25.0-alpha939
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/post-install.js +35 -0
- package/dist/FetchToken.d.ts +2 -3
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/OidcProvider.d.ts +4 -5
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcSecure.d.ts +3 -3
- package/dist/OidcSecure.d.ts.map +1 -1
- package/dist/OidcServiceWorker.js +559 -0
- package/{service_worker → dist}/OidcTrustedDomains.js +4 -5
- package/dist/ReactOidc.d.ts +4 -4
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/User.d.ts +2 -2
- package/dist/User.d.ts.map +1 -1
- package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
- package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
- package/dist/core/default-component/Callback.component.d.ts.map +1 -1
- package/dist/core/default-component/Loading.component.d.ts.map +1 -1
- package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
- package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
- package/dist/core/default-component/index.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.d.ts +1 -1
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- package/dist/core/routes/index.d.ts +3 -0
- package/dist/core/routes/index.d.ts.map +1 -0
- package/dist/core/routes/withRouter.d.ts +4 -4
- package/dist/core/routes/withRouter.d.ts.map +1 -1
- package/dist/index.d.ts +2 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +964 -21
- package/dist/index.umd.cjs +27 -0
- package/package.json +37 -43
- package/src/{oidc/FetchToken.tsx → FetchToken.tsx} +14 -16
- package/src/{oidc/OidcProvider.tsx → OidcProvider.tsx} +40 -42
- package/src/{oidc/OidcSecure.tsx → OidcSecure.tsx} +1 -3
- package/src/{oidc/ReactOidc.tsx → ReactOidc.tsx} +1 -3
- package/src/{oidc/User.ts → User.ts} +1 -2
- package/src/{oidc/core → core}/default-component/AuthenticateError.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/Authenticating.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/Callback.component.tsx +2 -2
- package/src/{oidc/core → core}/default-component/Loading.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/ServiceWorkerNotSupported.component.tsx +0 -1
- package/src/{oidc/core → core}/default-component/SessionLost.component.tsx +1 -1
- package/src/{oidc/core → core}/default-component/SilentCallback.component.tsx +1 -2
- package/src/{oidc/core → core}/default-component/SilentLogin.component.tsx +1 -3
- package/src/{oidc/core → core}/routes/OidcRoutes.spec.tsx +3 -2
- package/src/{oidc/core → core}/routes/OidcRoutes.tsx +6 -6
- package/src/{oidc/core → core}/routes/withRouter.spec.tsx +3 -5
- package/src/{oidc/index.ts → index.ts} +7 -2
- package/bin/copy.cjs +0 -43
- package/dist/FetchToken.js +0 -59
- package/dist/FetchToken.js.map +0 -1
- package/dist/OidcProvider.js +0 -134
- package/dist/OidcProvider.js.map +0 -1
- package/dist/OidcSecure.js +0 -25
- package/dist/OidcSecure.js.map +0 -1
- package/dist/ReactOidc.js +0 -156
- package/dist/ReactOidc.js.map +0 -1
- package/dist/User.js +0 -42
- package/dist/User.js.map +0 -1
- package/dist/core/default-component/AuthenticateError.component.js +0 -6
- package/dist/core/default-component/AuthenticateError.component.js.map +0 -1
- package/dist/core/default-component/Authenticating.component.js +0 -6
- package/dist/core/default-component/Authenticating.component.js.map +0 -1
- package/dist/core/default-component/Callback.component.js +0 -54
- package/dist/core/default-component/Callback.component.js.map +0 -1
- package/dist/core/default-component/Loading.component.js +0 -6
- package/dist/core/default-component/Loading.component.js.map +0 -1
- package/dist/core/default-component/ServiceWorkerNotSupported.component.js +0 -6
- package/dist/core/default-component/ServiceWorkerNotSupported.component.js.map +0 -1
- package/dist/core/default-component/SessionLost.component.js +0 -8
- package/dist/core/default-component/SessionLost.component.js.map +0 -1
- package/dist/core/default-component/SilentCallback.component.js +0 -27
- package/dist/core/default-component/SilentCallback.component.js.map +0 -1
- package/dist/core/default-component/SilentLogin.component.js +0 -29
- package/dist/core/default-component/SilentLogin.component.js.map +0 -1
- package/dist/core/default-component/index.js +0 -20
- package/dist/core/default-component/index.js.map +0 -1
- package/dist/core/routes/OidcRoutes.js +0 -64
- package/dist/core/routes/OidcRoutes.js.map +0 -1
- package/dist/core/routes/withRouter.js +0 -31
- package/dist/core/routes/withRouter.js.map +0 -1
- package/dist/index.js.map +0 -1
- package/dist/service_worker/OidcServiceWorker.d.ts +0 -2
- package/dist/service_worker/OidcServiceWorker.d.ts.map +0 -1
- package/dist/service_worker/OidcServiceWorker.js +0 -2
- package/dist/service_worker/OidcServiceWorker.js.map +0 -1
- package/dist/service_worker/constants.d.ts +0 -18
- package/dist/service_worker/constants.d.ts.map +0 -1
- package/dist/service_worker/types.d.ts +0 -87
- package/dist/service_worker/types.d.ts.map +0 -1
- package/dist/service_worker/utils/codeVerifier.d.ts +0 -2
- package/dist/service_worker/utils/codeVerifier.d.ts.map +0 -1
- package/dist/service_worker/utils/domains.d.ts +0 -7
- package/dist/service_worker/utils/domains.d.ts.map +0 -1
- package/dist/service_worker/utils/index.d.ts +0 -6
- package/dist/service_worker/utils/index.d.ts.map +0 -1
- package/dist/service_worker/utils/serializeHeaders.d.ts +0 -3
- package/dist/service_worker/utils/serializeHeaders.d.ts.map +0 -1
- package/dist/service_worker/utils/sleep.d.ts +0 -3
- package/dist/service_worker/utils/sleep.d.ts.map +0 -1
- package/dist/service_worker/utils/strings.d.ts +0 -8
- package/dist/service_worker/utils/strings.d.ts.map +0 -1
- package/dist/service_worker/utils/tokens.d.ts +0 -22
- package/dist/service_worker/utils/tokens.d.ts.map +0 -1
- package/dist/tsconfig.tsbuildinfo +0 -1
- package/dist/vanilla/cache.d.ts +0 -3
- package/dist/vanilla/cache.d.ts.map +0 -1
- package/dist/vanilla/cache.js +0 -30
- package/dist/vanilla/cache.js.map +0 -1
- package/dist/vanilla/checkSession.d.ts +0 -4
- package/dist/vanilla/checkSession.d.ts.map +0 -1
- package/dist/vanilla/checkSession.js +0 -73
- package/dist/vanilla/checkSession.js.map +0 -1
- package/dist/vanilla/checkSessionIFrame.d.ts +0 -17
- package/dist/vanilla/checkSessionIFrame.d.ts.map +0 -1
- package/dist/vanilla/checkSessionIFrame.js +0 -73
- package/dist/vanilla/checkSessionIFrame.js.map +0 -1
- package/dist/vanilla/crypto.d.ts +0 -4
- package/dist/vanilla/crypto.d.ts.map +0 -1
- package/dist/vanilla/crypto.js +0 -85
- package/dist/vanilla/crypto.js.map +0 -1
- package/dist/vanilla/events.d.ts +0 -29
- package/dist/vanilla/events.d.ts.map +0 -1
- package/dist/vanilla/events.js +0 -32
- package/dist/vanilla/events.js.map +0 -1
- package/dist/vanilla/index.d.ts +0 -3
- package/dist/vanilla/index.d.ts.map +0 -1
- package/dist/vanilla/index.js +0 -6
- package/dist/vanilla/index.js.map +0 -1
- package/dist/vanilla/initSession.d.ts +0 -22
- package/dist/vanilla/initSession.d.ts.map +0 -1
- package/dist/vanilla/initSession.js +0 -90
- package/dist/vanilla/initSession.js.map +0 -1
- package/dist/vanilla/initWorker.d.ts +0 -30
- package/dist/vanilla/initWorker.d.ts.map +0 -1
- package/dist/vanilla/initWorker.js +0 -317
- package/dist/vanilla/initWorker.js.map +0 -1
- package/dist/vanilla/login.d.ts +0 -8
- package/dist/vanilla/login.d.ts.map +0 -1
- package/dist/vanilla/login.js +0 -175
- package/dist/vanilla/login.js.map +0 -1
- package/dist/vanilla/logout.d.ts +0 -8
- package/dist/vanilla/logout.d.ts.map +0 -1
- package/dist/vanilla/logout.js +0 -118
- package/dist/vanilla/logout.js.map +0 -1
- package/dist/vanilla/oidc.d.ts +0 -101
- package/dist/vanilla/oidc.d.ts.map +0 -1
- package/dist/vanilla/oidc.js +0 -612
- package/dist/vanilla/oidc.js.map +0 -1
- package/dist/vanilla/parseTokens.d.ts +0 -37
- package/dist/vanilla/parseTokens.d.ts.map +0 -1
- package/dist/vanilla/parseTokens.js +0 -167
- package/dist/vanilla/parseTokens.js.map +0 -1
- package/dist/vanilla/renewTokens.d.ts +0 -4
- package/dist/vanilla/renewTokens.d.ts.map +0 -1
- package/dist/vanilla/renewTokens.js +0 -51
- package/dist/vanilla/renewTokens.js.map +0 -1
- package/dist/vanilla/requests.d.ts +0 -33
- package/dist/vanilla/requests.d.ts.map +0 -1
- package/dist/vanilla/requests.js +0 -174
- package/dist/vanilla/requests.js.map +0 -1
- package/dist/vanilla/route-utils.d.ts +0 -13
- package/dist/vanilla/route-utils.d.ts.map +0 -1
- package/dist/vanilla/route-utils.js +0 -71
- package/dist/vanilla/route-utils.js.map +0 -1
- package/dist/vanilla/silentLogin.d.ts +0 -10
- package/dist/vanilla/silentLogin.d.ts.map +0 -1
- package/dist/vanilla/silentLogin.js +0 -144
- package/dist/vanilla/silentLogin.js.map +0 -1
- package/dist/vanilla/timer.d.ts +0 -8
- package/dist/vanilla/timer.d.ts.map +0 -1
- package/dist/vanilla/timer.js +0 -143
- package/dist/vanilla/timer.js.map +0 -1
- package/dist/vanilla/types.d.ts +0 -38
- package/dist/vanilla/types.d.ts.map +0 -1
- package/dist/vanilla/types.js +0 -3
- package/dist/vanilla/types.js.map +0 -1
- package/dist/vanilla/user.d.ts +0 -2
- package/dist/vanilla/user.d.ts.map +0 -1
- package/dist/vanilla/user.js +0 -48
- package/dist/vanilla/user.js.map +0 -1
- package/dist/vanilla/vanillaOidc.d.ts +0 -85
- package/dist/vanilla/vanillaOidc.d.ts.map +0 -1
- package/dist/vanilla/vanillaOidc.js +0 -71
- package/dist/vanilla/vanillaOidc.js.map +0 -1
- package/service_worker/.eslintrc.cjs +0 -18
- package/service_worker/OidcServiceWorker.ts +0 -424
- package/service_worker/constants.ts +0 -32
- package/service_worker/dist/OidcServiceWorker.d.ts +0 -2
- package/service_worker/dist/OidcServiceWorker.d.ts.map +0 -1
- package/service_worker/dist/OidcServiceWorker.js +0 -2
- package/service_worker/dist/OidcServiceWorker.js.map +0 -1
- package/service_worker/dist/constants.d.ts +0 -18
- package/service_worker/dist/constants.d.ts.map +0 -1
- package/service_worker/dist/types.d.ts +0 -87
- package/service_worker/dist/types.d.ts.map +0 -1
- package/service_worker/dist/utils/codeVerifier.d.ts +0 -2
- package/service_worker/dist/utils/codeVerifier.d.ts.map +0 -1
- package/service_worker/dist/utils/domains.d.ts +0 -7
- package/service_worker/dist/utils/domains.d.ts.map +0 -1
- package/service_worker/dist/utils/index.d.ts +0 -6
- package/service_worker/dist/utils/index.d.ts.map +0 -1
- package/service_worker/dist/utils/serializeHeaders.d.ts +0 -3
- package/service_worker/dist/utils/serializeHeaders.d.ts.map +0 -1
- package/service_worker/dist/utils/sleep.d.ts +0 -3
- package/service_worker/dist/utils/sleep.d.ts.map +0 -1
- package/service_worker/dist/utils/strings.d.ts +0 -8
- package/service_worker/dist/utils/strings.d.ts.map +0 -1
- package/service_worker/dist/utils/tokens.d.ts +0 -22
- package/service_worker/dist/utils/tokens.d.ts.map +0 -1
- package/service_worker/tsconfig.json +0 -26
- package/service_worker/types.ts +0 -103
- package/service_worker/utils/__tests__/codeVerifier.spec.ts +0 -14
- package/service_worker/utils/__tests__/domains.spec.ts +0 -90
- package/service_worker/utils/__tests__/serializeHeaders.spec.ts +0 -11
- package/service_worker/utils/__tests__/strings.spec.ts +0 -9
- package/service_worker/utils/__tests__/testHelper.ts +0 -352
- package/service_worker/utils/__tests__/tokens.spec.ts +0 -92
- package/service_worker/utils/codeVerifier.ts +0 -6
- package/service_worker/utils/domains.ts +0 -105
- package/service_worker/utils/index.ts +0 -5
- package/service_worker/utils/serializeHeaders.ts +0 -12
- package/service_worker/utils/sleep.ts +0 -2
- package/service_worker/utils/strings.ts +0 -9
- package/service_worker/utils/tokens.ts +0 -206
- package/src/oidc/vanilla/cache.ts +0 -27
- package/src/oidc/vanilla/checkSession.ts +0 -60
- package/src/oidc/vanilla/checkSessionIFrame.ts +0 -83
- package/src/oidc/vanilla/crypto.ts +0 -61
- package/src/oidc/vanilla/events.ts +0 -29
- package/src/oidc/vanilla/index.ts +0 -2
- package/src/oidc/vanilla/iniWorker.spec.ts +0 -21
- package/src/oidc/vanilla/initSession.ts +0 -90
- package/src/oidc/vanilla/initWorker.ts +0 -321
- package/src/oidc/vanilla/login.ts +0 -174
- package/src/oidc/vanilla/logout.spec.ts +0 -66
- package/src/oidc/vanilla/logout.spec.tsx +0 -64
- package/src/oidc/vanilla/logout.ts +0 -101
- package/src/oidc/vanilla/oidc.ts +0 -614
- package/src/oidc/vanilla/parseTokens.spec.ts +0 -49
- package/src/oidc/vanilla/parseTokens.ts +0 -194
- package/src/oidc/vanilla/renewTokens.ts +0 -37
- package/src/oidc/vanilla/requests.spec.ts +0 -9
- package/src/oidc/vanilla/requests.ts +0 -169
- package/src/oidc/vanilla/route-utils.spec.ts +0 -23
- package/src/oidc/vanilla/route-utils.ts +0 -79
- package/src/oidc/vanilla/silentLogin.ts +0 -144
- package/src/oidc/vanilla/timer.ts +0 -163
- package/src/oidc/vanilla/types.ts +0 -42
- package/src/oidc/vanilla/user.ts +0 -40
- package/src/oidc/vanilla/vanillaOidc.ts +0 -109
- package/src/override/AuthenticateError.component.tsx +0 -15
- package/src/override/Authenticating.component.tsx +0 -15
- package/src/override/Callback.component.tsx +0 -14
- package/src/override/Loading.component.tsx +0 -11
- package/src/override/ServiceWorkerNotSupported.component.tsx +0 -15
- package/src/override/SessionLost.component.tsx +0 -22
- package/src/override/style.ts +0 -12
- /package/src/{oidc/core → core}/default-component/index.ts +0 -0
- /package/src/{oidc/core → core}/routes/__snapshots__/OidcRoutes.spec.tsx.snap +0 -0
- /package/src/{oidc/core → core}/routes/index.ts +0 -0
- /package/src/{oidc/core → core}/routes/withRouter.tsx +0 -0
package/dist/vanilla/oidc.js
DELETED
|
@@ -1,612 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
-
if (k2 === undefined) k2 = k;
|
|
4
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
-
}
|
|
8
|
-
Object.defineProperty(o, k2, desc);
|
|
9
|
-
}) : (function(o, m, k, k2) {
|
|
10
|
-
if (k2 === undefined) k2 = k;
|
|
11
|
-
o[k2] = m[k];
|
|
12
|
-
}));
|
|
13
|
-
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
-
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
-
}) : function(o, v) {
|
|
16
|
-
o["default"] = v;
|
|
17
|
-
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
-
if (mod && mod.__esModule) return mod;
|
|
20
|
-
var result = {};
|
|
21
|
-
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
-
__setModuleDefault(result, mod);
|
|
23
|
-
return result;
|
|
24
|
-
};
|
|
25
|
-
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
-
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
-
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
-
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
-
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
-
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
-
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
-
});
|
|
33
|
-
};
|
|
34
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
35
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
36
|
-
};
|
|
37
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
38
|
-
exports.Oidc = exports.OidcAuthorizationServiceConfiguration = exports.getFetchDefault = void 0;
|
|
39
|
-
const checkSession_js_1 = require("./checkSession.js");
|
|
40
|
-
const events_js_1 = require("./events.js");
|
|
41
|
-
const initSession_js_1 = require("./initSession.js");
|
|
42
|
-
const initWorker_js_1 = require("./initWorker.js");
|
|
43
|
-
const login_js_1 = require("./login.js");
|
|
44
|
-
const logout_js_1 = require("./logout.js");
|
|
45
|
-
const parseTokens_js_1 = require("./parseTokens.js");
|
|
46
|
-
const renewTokens_js_1 = require("./renewTokens.js");
|
|
47
|
-
const requests_js_1 = require("./requests.js");
|
|
48
|
-
const route_utils_js_1 = require("./route-utils.js");
|
|
49
|
-
const silentLogin_js_1 = __importStar(require("./silentLogin.js"));
|
|
50
|
-
const timer_js_1 = __importDefault(require("./timer.js"));
|
|
51
|
-
const user_js_1 = require("./user.js");
|
|
52
|
-
const getFetchDefault = () => {
|
|
53
|
-
return fetch;
|
|
54
|
-
};
|
|
55
|
-
exports.getFetchDefault = getFetchDefault;
|
|
56
|
-
class OidcAuthorizationServiceConfiguration {
|
|
57
|
-
constructor(request) {
|
|
58
|
-
this.authorizationEndpoint = request.authorization_endpoint;
|
|
59
|
-
this.tokenEndpoint = request.token_endpoint;
|
|
60
|
-
this.revocationEndpoint = request.revocation_endpoint;
|
|
61
|
-
this.userInfoEndpoint = request.userinfo_endpoint;
|
|
62
|
-
this.checkSessionIframe = request.check_session_iframe;
|
|
63
|
-
this.issuer = request.issuer;
|
|
64
|
-
this.endSessionEndpoint = request.end_session_endpoint;
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
exports.OidcAuthorizationServiceConfiguration = OidcAuthorizationServiceConfiguration;
|
|
68
|
-
const oidcDatabase = {};
|
|
69
|
-
const oidcFactory = (getFetch) => (configuration, name = 'default') => {
|
|
70
|
-
if (oidcDatabase[name]) {
|
|
71
|
-
return oidcDatabase[name];
|
|
72
|
-
}
|
|
73
|
-
oidcDatabase[name] = new Oidc(configuration, name, getFetch);
|
|
74
|
-
return oidcDatabase[name];
|
|
75
|
-
};
|
|
76
|
-
const loginCallbackWithAutoTokensRenewAsync = (oidc) => __awaiter(void 0, void 0, void 0, function* () {
|
|
77
|
-
const { parsedTokens, callbackPath } = yield oidc.loginCallbackAsync();
|
|
78
|
-
oidc.timeoutId = (0, renewTokens_js_1.autoRenewTokens)(oidc, parsedTokens.refreshToken, parsedTokens.expiresAt);
|
|
79
|
-
return { callbackPath };
|
|
80
|
-
});
|
|
81
|
-
const getRandomInt = (max) => {
|
|
82
|
-
return Math.floor(Math.random() * max);
|
|
83
|
-
};
|
|
84
|
-
class Oidc {
|
|
85
|
-
constructor(configuration, configurationName = 'default', getFetch) {
|
|
86
|
-
var _a, _b, _c, _d;
|
|
87
|
-
this.initPromise = null;
|
|
88
|
-
this.tryKeepExistingSessionPromise = null;
|
|
89
|
-
this.loginPromise = null;
|
|
90
|
-
this.loginCallbackPromise = null;
|
|
91
|
-
this.loginCallbackWithAutoTokensRenewPromise = null;
|
|
92
|
-
this.userInfoPromise = null;
|
|
93
|
-
this.renewTokensPromise = null;
|
|
94
|
-
this.logoutPromise = null;
|
|
95
|
-
let silent_login_uri = configuration.silent_login_uri;
|
|
96
|
-
if (configuration.silent_redirect_uri && !configuration.silent_login_uri) {
|
|
97
|
-
silent_login_uri = `${configuration.silent_redirect_uri.replace('-callback', '').replace('callback', '')}-login`;
|
|
98
|
-
}
|
|
99
|
-
let refresh_time_before_tokens_expiration_in_second = (_a = configuration.refresh_time_before_tokens_expiration_in_second) !== null && _a !== void 0 ? _a : 120;
|
|
100
|
-
if (refresh_time_before_tokens_expiration_in_second > 60) {
|
|
101
|
-
refresh_time_before_tokens_expiration_in_second = refresh_time_before_tokens_expiration_in_second - Math.floor(Math.random() * 40);
|
|
102
|
-
}
|
|
103
|
-
if (!configuration.logout_tokens_to_invalidate) {
|
|
104
|
-
configuration.logout_tokens_to_invalidate = ['access_token', 'refresh_token'];
|
|
105
|
-
}
|
|
106
|
-
if (!configuration.authority_timeout_wellknowurl_in_millisecond) {
|
|
107
|
-
configuration.authority_timeout_wellknowurl_in_millisecond = 10000;
|
|
108
|
-
}
|
|
109
|
-
this.configuration = Object.assign(Object.assign({}, configuration), { silent_login_uri, monitor_session: (_b = configuration.monitor_session) !== null && _b !== void 0 ? _b : false, refresh_time_before_tokens_expiration_in_second, silent_login_timeout: (_c = configuration.silent_login_timeout) !== null && _c !== void 0 ? _c : 12000, token_renew_mode: (_d = configuration.token_renew_mode) !== null && _d !== void 0 ? _d : parseTokens_js_1.TokenRenewMode.access_token_or_id_token_invalid });
|
|
110
|
-
this.getFetch = getFetch !== null && getFetch !== void 0 ? getFetch : exports.getFetchDefault;
|
|
111
|
-
this.configurationName = configurationName;
|
|
112
|
-
this.tokens = null;
|
|
113
|
-
this.userInfo = null;
|
|
114
|
-
this.events = [];
|
|
115
|
-
this.timeoutId = null;
|
|
116
|
-
this.synchroniseTokensAsync.bind(this);
|
|
117
|
-
this.loginCallbackWithAutoTokensRenewAsync.bind(this);
|
|
118
|
-
this.initAsync.bind(this);
|
|
119
|
-
this.loginCallbackAsync.bind(this);
|
|
120
|
-
this.subscribeEvents.bind(this);
|
|
121
|
-
this.removeEventSubscription.bind(this);
|
|
122
|
-
this.publishEvent.bind(this);
|
|
123
|
-
this.destroyAsync.bind(this);
|
|
124
|
-
this.logoutAsync.bind(this);
|
|
125
|
-
this.renewTokensAsync.bind(this);
|
|
126
|
-
this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
|
|
127
|
-
}
|
|
128
|
-
subscribeEvents(func) {
|
|
129
|
-
const id = getRandomInt(9999999999999).toString();
|
|
130
|
-
this.events.push({ id, func });
|
|
131
|
-
return id;
|
|
132
|
-
}
|
|
133
|
-
removeEventSubscription(id) {
|
|
134
|
-
const newEvents = this.events.filter(e => e.id !== id);
|
|
135
|
-
this.events = newEvents;
|
|
136
|
-
}
|
|
137
|
-
publishEvent(eventName, data) {
|
|
138
|
-
this.events.forEach(event => {
|
|
139
|
-
event.func(eventName, data);
|
|
140
|
-
});
|
|
141
|
-
}
|
|
142
|
-
static get(name = 'default') {
|
|
143
|
-
const isInsideBrowser = (typeof process === 'undefined');
|
|
144
|
-
if (!Object.prototype.hasOwnProperty.call(oidcDatabase, name) && isInsideBrowser) {
|
|
145
|
-
throw Error(`OIDC library does seem initialized.
|
|
146
|
-
Please checkout that you are using OIDC hook inside a <OidcProvider configurationName="${name}"></OidcProvider> compoment.`);
|
|
147
|
-
}
|
|
148
|
-
return oidcDatabase[name];
|
|
149
|
-
}
|
|
150
|
-
_silentLoginCallbackFromIFrame() {
|
|
151
|
-
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
152
|
-
const queryParams = (0, route_utils_js_1.getParseQueryStringFromLocation)(window.location.href);
|
|
153
|
-
window.top.postMessage(`${this.configurationName}_oidc_tokens:${JSON.stringify({ tokens: this.tokens, sessionState: queryParams.session_state })}`, window.location.origin);
|
|
154
|
-
}
|
|
155
|
-
}
|
|
156
|
-
_silentLoginErrorCallbackFromIFrame() {
|
|
157
|
-
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
158
|
-
const queryParams = (0, route_utils_js_1.getParseQueryStringFromLocation)(window.location.href);
|
|
159
|
-
window.top.postMessage(`${this.configurationName}_oidc_error:${JSON.stringify({ error: queryParams.error })}`, window.location.origin);
|
|
160
|
-
}
|
|
161
|
-
}
|
|
162
|
-
silentLoginCallbackAsync() {
|
|
163
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
164
|
-
try {
|
|
165
|
-
yield this.loginCallbackAsync(true);
|
|
166
|
-
this._silentLoginCallbackFromIFrame();
|
|
167
|
-
}
|
|
168
|
-
catch (error) {
|
|
169
|
-
console.error(error);
|
|
170
|
-
this._silentLoginErrorCallbackFromIFrame();
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}
|
|
174
|
-
initAsync(authority, authorityConfiguration) {
|
|
175
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
176
|
-
if (this.initPromise !== null) {
|
|
177
|
-
return this.initPromise;
|
|
178
|
-
}
|
|
179
|
-
const localFuncAsync = () => __awaiter(this, void 0, void 0, function* () {
|
|
180
|
-
var _a;
|
|
181
|
-
if (authorityConfiguration != null) {
|
|
182
|
-
return new OidcAuthorizationServiceConfiguration({
|
|
183
|
-
authorization_endpoint: authorityConfiguration.authorization_endpoint,
|
|
184
|
-
end_session_endpoint: authorityConfiguration.end_session_endpoint,
|
|
185
|
-
revocation_endpoint: authorityConfiguration.revocation_endpoint,
|
|
186
|
-
token_endpoint: authorityConfiguration.token_endpoint,
|
|
187
|
-
userinfo_endpoint: authorityConfiguration.userinfo_endpoint,
|
|
188
|
-
check_session_iframe: authorityConfiguration.check_session_iframe,
|
|
189
|
-
issuer: authorityConfiguration.issuer,
|
|
190
|
-
});
|
|
191
|
-
}
|
|
192
|
-
const serviceWorker = yield (0, initWorker_js_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName);
|
|
193
|
-
const storage = serviceWorker ? window.localStorage : null;
|
|
194
|
-
return yield (0, requests_js_1.fetchFromIssuer)(this.getFetch())(authority, (_a = this.configuration.authority_time_cache_wellknowurl_in_second) !== null && _a !== void 0 ? _a : 60 * 60, storage, this.configuration.authority_timeout_wellknowurl_in_millisecond);
|
|
195
|
-
});
|
|
196
|
-
this.initPromise = localFuncAsync();
|
|
197
|
-
return this.initPromise.then((result) => {
|
|
198
|
-
this.initPromise = null;
|
|
199
|
-
return result;
|
|
200
|
-
});
|
|
201
|
-
});
|
|
202
|
-
}
|
|
203
|
-
tryKeepExistingSessionAsync() {
|
|
204
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
205
|
-
if (this.tryKeepExistingSessionPromise !== null) {
|
|
206
|
-
return this.tryKeepExistingSessionPromise;
|
|
207
|
-
}
|
|
208
|
-
const funcAsync = () => __awaiter(this, void 0, void 0, function* () {
|
|
209
|
-
var _a;
|
|
210
|
-
let serviceWorker;
|
|
211
|
-
if (this.tokens != null) {
|
|
212
|
-
return false;
|
|
213
|
-
}
|
|
214
|
-
this.publishEvent(events_js_1.eventNames.tryKeepExistingSessionAsync_begin, {});
|
|
215
|
-
try {
|
|
216
|
-
const configuration = this.configuration;
|
|
217
|
-
const oidcServerConfiguration = yield this.initAsync(configuration.authority, configuration.authority_configuration);
|
|
218
|
-
serviceWorker = yield (0, initWorker_js_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName);
|
|
219
|
-
if (serviceWorker) {
|
|
220
|
-
const { tokens } = yield serviceWorker.initAsync(oidcServerConfiguration, 'tryKeepExistingSessionAsync', configuration);
|
|
221
|
-
if (tokens) {
|
|
222
|
-
serviceWorker.startKeepAliveServiceWorker();
|
|
223
|
-
// @ts-ignore
|
|
224
|
-
this.tokens = tokens;
|
|
225
|
-
const getLoginParams = serviceWorker.getLoginParams(this.configurationName);
|
|
226
|
-
// @ts-ignore
|
|
227
|
-
this.timeoutId = (0, renewTokens_js_1.autoRenewTokens)(this, this.tokens.refreshToken, this.tokens.expiresAt, getLoginParams.extras);
|
|
228
|
-
const sessionState = yield serviceWorker.getSessionStateAsync();
|
|
229
|
-
// @ts-ignore
|
|
230
|
-
yield this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
|
|
231
|
-
this.publishEvent(events_js_1.eventNames.tryKeepExistingSessionAsync_end, {
|
|
232
|
-
success: true,
|
|
233
|
-
message: 'tokens inside ServiceWorker are valid',
|
|
234
|
-
});
|
|
235
|
-
return true;
|
|
236
|
-
}
|
|
237
|
-
this.publishEvent(events_js_1.eventNames.tryKeepExistingSessionAsync_end, {
|
|
238
|
-
success: false,
|
|
239
|
-
message: 'no exiting session found',
|
|
240
|
-
});
|
|
241
|
-
}
|
|
242
|
-
else {
|
|
243
|
-
if (configuration.service_worker_relative_url) {
|
|
244
|
-
this.publishEvent(events_js_1.eventNames.service_worker_not_supported_by_browser, {
|
|
245
|
-
message: 'service worker is not supported by this browser',
|
|
246
|
-
});
|
|
247
|
-
}
|
|
248
|
-
const session = (0, initSession_js_1.initSession)(this.configurationName, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
|
|
249
|
-
const { tokens } = yield session.initAsync();
|
|
250
|
-
if (tokens) {
|
|
251
|
-
// @ts-ignore
|
|
252
|
-
this.tokens = (0, parseTokens_js_1.setTokens)(tokens, null, configuration.token_renew_mode);
|
|
253
|
-
const getLoginParams = session.getLoginParams(this.configurationName);
|
|
254
|
-
// @ts-ignore
|
|
255
|
-
this.timeoutId = (0, renewTokens_js_1.autoRenewTokens)(this, tokens.refreshToken, this.tokens.expiresAt, getLoginParams.extras);
|
|
256
|
-
const sessionState = yield session.getSessionStateAsync();
|
|
257
|
-
// @ts-ignore
|
|
258
|
-
yield this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
|
|
259
|
-
this.publishEvent(events_js_1.eventNames.tryKeepExistingSessionAsync_end, {
|
|
260
|
-
success: true,
|
|
261
|
-
message: 'tokens inside storage are valid',
|
|
262
|
-
});
|
|
263
|
-
return true;
|
|
264
|
-
}
|
|
265
|
-
}
|
|
266
|
-
this.publishEvent(events_js_1.eventNames.tryKeepExistingSessionAsync_end, {
|
|
267
|
-
success: false,
|
|
268
|
-
message: serviceWorker ? 'service worker sessions not retrieved' : 'session storage sessions not retrieved',
|
|
269
|
-
});
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
catch (exception) {
|
|
273
|
-
console.error(exception);
|
|
274
|
-
if (serviceWorker) {
|
|
275
|
-
yield serviceWorker.clearAsync();
|
|
276
|
-
}
|
|
277
|
-
this.publishEvent(events_js_1.eventNames.tryKeepExistingSessionAsync_error, 'tokens inside ServiceWorker are invalid');
|
|
278
|
-
return false;
|
|
279
|
-
}
|
|
280
|
-
});
|
|
281
|
-
this.tryKeepExistingSessionPromise = funcAsync();
|
|
282
|
-
return this.tryKeepExistingSessionPromise.then((result) => {
|
|
283
|
-
this.tryKeepExistingSessionPromise = null;
|
|
284
|
-
return result;
|
|
285
|
-
});
|
|
286
|
-
});
|
|
287
|
-
}
|
|
288
|
-
startCheckSessionAsync(checkSessionIFrameUri, clientId, sessionState, isSilentSignin = false) {
|
|
289
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
290
|
-
yield (0, checkSession_js_1.startCheckSessionAsync)(this, oidcDatabase, this.configuration)(checkSessionIFrameUri, clientId, sessionState, isSilentSignin);
|
|
291
|
-
});
|
|
292
|
-
}
|
|
293
|
-
loginAsync(callbackPath = undefined, extras = null, isSilentSignin = false, scope = undefined, silentLoginOnly = false) {
|
|
294
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
295
|
-
if (this.loginPromise !== null) {
|
|
296
|
-
return this.loginPromise;
|
|
297
|
-
}
|
|
298
|
-
if (silentLoginOnly) {
|
|
299
|
-
return (0, silentLogin_js_1.default)(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(extras, scope);
|
|
300
|
-
}
|
|
301
|
-
this.loginPromise = (0, login_js_1.defaultLoginAsync)(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this))(callbackPath, extras, isSilentSignin, scope);
|
|
302
|
-
return this.loginPromise.then(result => {
|
|
303
|
-
this.loginPromise = null;
|
|
304
|
-
return result;
|
|
305
|
-
});
|
|
306
|
-
});
|
|
307
|
-
}
|
|
308
|
-
loginCallbackAsync(isSilenSignin = false) {
|
|
309
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
310
|
-
if (this.loginCallbackPromise !== null) {
|
|
311
|
-
return this.loginCallbackPromise;
|
|
312
|
-
}
|
|
313
|
-
const loginCallbackLocalAsync = () => __awaiter(this, void 0, void 0, function* () {
|
|
314
|
-
const response = yield (0, login_js_1.loginCallbackAsync)(this)(isSilenSignin);
|
|
315
|
-
// @ts-ignore
|
|
316
|
-
const parsedTokens = response.tokens;
|
|
317
|
-
// @ts-ignore
|
|
318
|
-
this.tokens = parsedTokens;
|
|
319
|
-
const serviceWorker = yield (0, initWorker_js_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName);
|
|
320
|
-
if (!serviceWorker) {
|
|
321
|
-
const session = (0, initSession_js_1.initSession)(this.configurationName, this.configuration.storage);
|
|
322
|
-
session.setTokens(parsedTokens);
|
|
323
|
-
}
|
|
324
|
-
this.publishEvent(Oidc.eventNames.token_aquired, parsedTokens);
|
|
325
|
-
// @ts-ignore
|
|
326
|
-
return { parsedTokens, state: response.state, callbackPath: response.callbackPath };
|
|
327
|
-
});
|
|
328
|
-
this.loginCallbackPromise = loginCallbackLocalAsync();
|
|
329
|
-
return this.loginCallbackPromise.then(result => {
|
|
330
|
-
this.loginCallbackPromise = null;
|
|
331
|
-
return result;
|
|
332
|
-
});
|
|
333
|
-
});
|
|
334
|
-
}
|
|
335
|
-
synchroniseTokensAsync(refreshToken, index = 0, forceRefresh = false, extras = null, updateTokens) {
|
|
336
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
337
|
-
while (!navigator.onLine && document.hidden) {
|
|
338
|
-
yield (0, initWorker_js_1.sleepAsync)(1000);
|
|
339
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync, { message: 'wait because navigator is offline and hidden' });
|
|
340
|
-
}
|
|
341
|
-
let numberTryOnline = 6;
|
|
342
|
-
while (!navigator.onLine && numberTryOnline > 0) {
|
|
343
|
-
yield (0, initWorker_js_1.sleepAsync)(1000);
|
|
344
|
-
numberTryOnline--;
|
|
345
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync, { message: `wait because navigator is offline try ${numberTryOnline}` });
|
|
346
|
-
}
|
|
347
|
-
let numberTryHidden = Math.floor(Math.random() * 15) + 10;
|
|
348
|
-
while (document.hidden && numberTryHidden > 0) {
|
|
349
|
-
yield (0, initWorker_js_1.sleepAsync)(1000);
|
|
350
|
-
numberTryHidden--;
|
|
351
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync, { message: `wait because navigator is hidden try ${numberTryHidden}` });
|
|
352
|
-
}
|
|
353
|
-
const isDocumentHidden = document.hidden;
|
|
354
|
-
const nextIndex = isDocumentHidden ? index : index + 1;
|
|
355
|
-
if (!extras) {
|
|
356
|
-
extras = {};
|
|
357
|
-
}
|
|
358
|
-
const configuration = this.configuration;
|
|
359
|
-
const silentLoginAsync = (extras, state, scope = null) => {
|
|
360
|
-
return (0, silentLogin_js_1._silentLoginAsync)(this.configurationName, this.configuration, this.publishEvent.bind(this))(extras, state, scope);
|
|
361
|
-
};
|
|
362
|
-
const localsilentLoginAsync = () => __awaiter(this, void 0, void 0, function* () {
|
|
363
|
-
try {
|
|
364
|
-
let loginParams;
|
|
365
|
-
const serviceWorker = yield (0, initWorker_js_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName);
|
|
366
|
-
if (serviceWorker) {
|
|
367
|
-
loginParams = serviceWorker.getLoginParams(this.configurationName);
|
|
368
|
-
}
|
|
369
|
-
else {
|
|
370
|
-
const session = (0, initSession_js_1.initSession)(this.configurationName, configuration.storage);
|
|
371
|
-
loginParams = session.getLoginParams(this.configurationName);
|
|
372
|
-
}
|
|
373
|
-
const silent_token_response = yield silentLoginAsync(Object.assign(Object.assign(Object.assign({}, loginParams.extras), extras), { prompt: 'none' }), loginParams.state);
|
|
374
|
-
if (silent_token_response) {
|
|
375
|
-
updateTokens(silent_token_response.tokens);
|
|
376
|
-
this.publishEvent(Oidc.eventNames.token_renewed, {});
|
|
377
|
-
return { tokens: silent_token_response.tokens, status: 'LOGGED' };
|
|
378
|
-
}
|
|
379
|
-
}
|
|
380
|
-
catch (exceptionSilent) {
|
|
381
|
-
console.error(exceptionSilent);
|
|
382
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_silent_error, { message: 'exceptionSilent', exception: exceptionSilent.message });
|
|
383
|
-
if (exceptionSilent && exceptionSilent.message && exceptionSilent.message.startsWith('oidc')) {
|
|
384
|
-
updateTokens(null);
|
|
385
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_error, { message: 'refresh token silent' });
|
|
386
|
-
return { tokens: null, status: 'SESSION_LOST' };
|
|
387
|
-
}
|
|
388
|
-
}
|
|
389
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_error, { message: 'refresh token silent return' });
|
|
390
|
-
return yield this.synchroniseTokensAsync(null, nextIndex, forceRefresh, extras, updateTokens);
|
|
391
|
-
});
|
|
392
|
-
if (index > 4) {
|
|
393
|
-
updateTokens(null);
|
|
394
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_error, { message: 'refresh token' });
|
|
395
|
-
return { tokens: null, status: 'SESSION_LOST' };
|
|
396
|
-
}
|
|
397
|
-
try {
|
|
398
|
-
const { status, tokens, nonce } = yield this.syncTokensInfoAsync(configuration, this.configurationName, this.tokens, forceRefresh);
|
|
399
|
-
switch (status) {
|
|
400
|
-
case 'SESSION_LOST':
|
|
401
|
-
updateTokens(null);
|
|
402
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_error, { message: 'refresh token session lost' });
|
|
403
|
-
return { tokens: null, status: 'SESSION_LOST' };
|
|
404
|
-
case 'NOT_CONNECTED':
|
|
405
|
-
updateTokens(null);
|
|
406
|
-
return { tokens: null, status: null };
|
|
407
|
-
case 'TOKENS_VALID':
|
|
408
|
-
updateTokens(tokens);
|
|
409
|
-
return { tokens, status: 'LOGGED_IN' };
|
|
410
|
-
case 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID':
|
|
411
|
-
updateTokens(tokens);
|
|
412
|
-
this.publishEvent(Oidc.eventNames.token_renewed, { reason: 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID' });
|
|
413
|
-
return { tokens, status: 'LOGGED_IN' };
|
|
414
|
-
case 'LOGOUT_FROM_ANOTHER_TAB':
|
|
415
|
-
updateTokens(null);
|
|
416
|
-
this.publishEvent(events_js_1.eventNames.logout_from_another_tab, { status: 'session syncTokensAsync' });
|
|
417
|
-
return { tokens: null, status: 'LOGGED_OUT' };
|
|
418
|
-
case 'REQUIRE_SYNC_TOKENS':
|
|
419
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
|
|
420
|
-
return yield localsilentLoginAsync();
|
|
421
|
-
default: {
|
|
422
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
|
|
423
|
-
if (!refreshToken) {
|
|
424
|
-
return yield localsilentLoginAsync();
|
|
425
|
-
}
|
|
426
|
-
const clientId = configuration.client_id;
|
|
427
|
-
const redirectUri = configuration.redirect_uri;
|
|
428
|
-
const authority = configuration.authority;
|
|
429
|
-
const tokenExtras = configuration.token_request_extras ? configuration.token_request_extras : {};
|
|
430
|
-
const finalExtras = Object.assign({}, tokenExtras);
|
|
431
|
-
for (const [key, value] of Object.entries(extras)) {
|
|
432
|
-
if (key.endsWith(':token_request')) {
|
|
433
|
-
finalExtras[key.replace(':token_request', '')] = value;
|
|
434
|
-
}
|
|
435
|
-
}
|
|
436
|
-
const localFunctionAsync = () => __awaiter(this, void 0, void 0, function* () {
|
|
437
|
-
const details = {
|
|
438
|
-
client_id: clientId,
|
|
439
|
-
redirect_uri: redirectUri,
|
|
440
|
-
grant_type: 'refresh_token',
|
|
441
|
-
refresh_token: tokens.refreshToken,
|
|
442
|
-
};
|
|
443
|
-
const oidcServerConfiguration = yield this.initAsync(authority, configuration.authority_configuration);
|
|
444
|
-
const timeoutMs = document.hidden ? 10000 : 30000 * 10;
|
|
445
|
-
const tokenResponse = yield (0, requests_js_1.performTokenRequestAsync)(this.getFetch())(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens, configuration.token_renew_mode, timeoutMs);
|
|
446
|
-
if (tokenResponse.success) {
|
|
447
|
-
const { isValid, reason } = (0, parseTokens_js_1.isTokensOidcValid)(tokenResponse.data, nonce.nonce, oidcServerConfiguration);
|
|
448
|
-
if (!isValid) {
|
|
449
|
-
updateTokens(null);
|
|
450
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_error, { message: `refresh token return not valid tokens, reason: ${reason}` });
|
|
451
|
-
return { tokens: null, status: 'SESSION_LOST' };
|
|
452
|
-
}
|
|
453
|
-
updateTokens(tokenResponse.data);
|
|
454
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
|
|
455
|
-
this.publishEvent(Oidc.eventNames.token_renewed, { reason: 'REFRESH_TOKEN' });
|
|
456
|
-
return { tokens: tokenResponse.data, status: 'LOGGED_IN' };
|
|
457
|
-
}
|
|
458
|
-
else {
|
|
459
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_silent_error, {
|
|
460
|
-
message: 'bad request',
|
|
461
|
-
tokenResponse,
|
|
462
|
-
});
|
|
463
|
-
return yield this.synchroniseTokensAsync(refreshToken, nextIndex, forceRefresh, extras, updateTokens);
|
|
464
|
-
}
|
|
465
|
-
});
|
|
466
|
-
return yield localFunctionAsync();
|
|
467
|
-
}
|
|
468
|
-
}
|
|
469
|
-
}
|
|
470
|
-
catch (exception) {
|
|
471
|
-
console.error(exception);
|
|
472
|
-
this.publishEvent(events_js_1.eventNames.refreshTokensAsync_silent_error, { message: 'exception', exception: exception.message });
|
|
473
|
-
return this.synchroniseTokensAsync(refreshToken, nextIndex, forceRefresh, extras, updateTokens);
|
|
474
|
-
}
|
|
475
|
-
});
|
|
476
|
-
}
|
|
477
|
-
syncTokensInfoAsync(configuration, configurationName, currentTokens, forceRefresh = false) {
|
|
478
|
-
var _a;
|
|
479
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
480
|
-
// Service Worker can be killed by the browser (when it wants,for example after 10 seconds of inactivity, so we retreieve the session if it happen)
|
|
481
|
-
// const configuration = this.configuration;
|
|
482
|
-
const nullNonce = { nonce: null };
|
|
483
|
-
if (!currentTokens) {
|
|
484
|
-
return { tokens: null, status: 'NOT_CONNECTED', nonce: nullNonce };
|
|
485
|
-
}
|
|
486
|
-
let nonce = nullNonce;
|
|
487
|
-
const oidcServerConfiguration = yield this.initAsync(configuration.authority, configuration.authority_configuration);
|
|
488
|
-
const serviceWorker = yield (0, initWorker_js_1.initWorkerAsync)(configuration.service_worker_relative_url, configurationName);
|
|
489
|
-
if (serviceWorker) {
|
|
490
|
-
const { status, tokens } = yield serviceWorker.initAsync(oidcServerConfiguration, 'syncTokensAsync', configuration);
|
|
491
|
-
if (status === 'LOGGED_OUT') {
|
|
492
|
-
return { tokens: null, status: 'LOGOUT_FROM_ANOTHER_TAB', nonce: nullNonce };
|
|
493
|
-
}
|
|
494
|
-
else if (status === 'SESSIONS_LOST') {
|
|
495
|
-
return { tokens: null, status: 'SESSIONS_LOST', nonce: nullNonce };
|
|
496
|
-
}
|
|
497
|
-
else if (!status || !tokens) {
|
|
498
|
-
return { tokens: null, status: 'REQUIRE_SYNC_TOKENS', nonce: nullNonce };
|
|
499
|
-
}
|
|
500
|
-
else if (tokens.issuedAt !== currentTokens.issuedAt) {
|
|
501
|
-
const timeLeft = (0, parseTokens_js_1.computeTimeLeft)(configuration.refresh_time_before_tokens_expiration_in_second, tokens.expiresAt);
|
|
502
|
-
const status = (timeLeft > 0) ? 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID' : 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID';
|
|
503
|
-
const nonce = yield serviceWorker.getNonceAsync();
|
|
504
|
-
return { tokens, status, nonce };
|
|
505
|
-
}
|
|
506
|
-
nonce = yield serviceWorker.getNonceAsync();
|
|
507
|
-
}
|
|
508
|
-
else {
|
|
509
|
-
const session = (0, initSession_js_1.initSession)(configurationName, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
|
|
510
|
-
const { tokens, status } = yield session.initAsync();
|
|
511
|
-
if (!tokens) {
|
|
512
|
-
return { tokens: null, status: 'LOGOUT_FROM_ANOTHER_TAB', nonce: nullNonce };
|
|
513
|
-
}
|
|
514
|
-
else if (status === 'SESSIONS_LOST') {
|
|
515
|
-
return { tokens: null, status: 'SESSIONS_LOST', nonce: nullNonce };
|
|
516
|
-
}
|
|
517
|
-
else if (tokens.issuedAt !== currentTokens.issuedAt) {
|
|
518
|
-
const timeLeft = (0, parseTokens_js_1.computeTimeLeft)(configuration.refresh_time_before_tokens_expiration_in_second, tokens.expiresAt);
|
|
519
|
-
const status = (timeLeft > 0) ? 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID' : 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID';
|
|
520
|
-
const nonce = yield session.getNonceAsync();
|
|
521
|
-
return { tokens, status, nonce };
|
|
522
|
-
}
|
|
523
|
-
nonce = yield session.getNonceAsync();
|
|
524
|
-
}
|
|
525
|
-
const timeLeft = (0, parseTokens_js_1.computeTimeLeft)(configuration.refresh_time_before_tokens_expiration_in_second, currentTokens.expiresAt);
|
|
526
|
-
const status = (timeLeft > 0) ? 'TOKENS_VALID' : 'TOKENS_INVALID';
|
|
527
|
-
if (forceRefresh) {
|
|
528
|
-
return { tokens: currentTokens, status: 'FORCE_REFRESH', nonce };
|
|
529
|
-
}
|
|
530
|
-
return { tokens: currentTokens, status, nonce };
|
|
531
|
-
});
|
|
532
|
-
}
|
|
533
|
-
loginCallbackWithAutoTokensRenewAsync() {
|
|
534
|
-
if (this.loginCallbackWithAutoTokensRenewPromise !== null) {
|
|
535
|
-
return this.loginCallbackWithAutoTokensRenewPromise;
|
|
536
|
-
}
|
|
537
|
-
this.loginCallbackWithAutoTokensRenewPromise = loginCallbackWithAutoTokensRenewAsync(this);
|
|
538
|
-
return this.loginCallbackWithAutoTokensRenewPromise.then(result => {
|
|
539
|
-
this.loginCallbackWithAutoTokensRenewPromise = null;
|
|
540
|
-
return result;
|
|
541
|
-
});
|
|
542
|
-
}
|
|
543
|
-
userInfoAsync(noCache = false) {
|
|
544
|
-
if (this.userInfoPromise !== null) {
|
|
545
|
-
return this.userInfoPromise;
|
|
546
|
-
}
|
|
547
|
-
this.userInfoPromise = (0, user_js_1.userInfoAsync)(this)(noCache);
|
|
548
|
-
return this.userInfoPromise.then(result => {
|
|
549
|
-
this.userInfoPromise = null;
|
|
550
|
-
return result;
|
|
551
|
-
});
|
|
552
|
-
}
|
|
553
|
-
renewTokensAsync(extras = null) {
|
|
554
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
555
|
-
if (this.renewTokensPromise !== null) {
|
|
556
|
-
return this.renewTokensPromise;
|
|
557
|
-
}
|
|
558
|
-
if (!this.timeoutId) {
|
|
559
|
-
return;
|
|
560
|
-
}
|
|
561
|
-
timer_js_1.default.clearTimeout(this.timeoutId);
|
|
562
|
-
// @ts-ignore
|
|
563
|
-
this.renewTokensPromise = (0, renewTokens_js_1.renewTokensAndStartTimerAsync)(this, this.tokens.refreshToken, true, extras);
|
|
564
|
-
return this.renewTokensPromise.then(result => {
|
|
565
|
-
this.renewTokensPromise = null;
|
|
566
|
-
return result;
|
|
567
|
-
});
|
|
568
|
-
});
|
|
569
|
-
}
|
|
570
|
-
destroyAsync(status) {
|
|
571
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
572
|
-
return yield (0, logout_js_1.destroyAsync)(this)(status);
|
|
573
|
-
});
|
|
574
|
-
}
|
|
575
|
-
logoutSameTabAsync(clientId, sub) {
|
|
576
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
577
|
-
// @ts-ignore
|
|
578
|
-
if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
|
|
579
|
-
this.publishEvent(events_js_1.eventNames.logout_from_same_tab, { message: sub });
|
|
580
|
-
yield this.destroyAsync('LOGGED_OUT');
|
|
581
|
-
}
|
|
582
|
-
});
|
|
583
|
-
}
|
|
584
|
-
logoutOtherTabAsync(clientId, sub) {
|
|
585
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
586
|
-
// @ts-ignore
|
|
587
|
-
if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
|
|
588
|
-
yield this.destroyAsync('LOGGED_OUT');
|
|
589
|
-
this.publishEvent(events_js_1.eventNames.logout_from_another_tab, { message: 'SessionMonitor', sub });
|
|
590
|
-
}
|
|
591
|
-
});
|
|
592
|
-
}
|
|
593
|
-
logoutAsync(callbackPathOrUrl = undefined, extras = null) {
|
|
594
|
-
return __awaiter(this, void 0, void 0, function* () {
|
|
595
|
-
if (this.logoutPromise) {
|
|
596
|
-
return this.logoutPromise;
|
|
597
|
-
}
|
|
598
|
-
this.logoutPromise = (0, logout_js_1.logoutAsync)(this, oidcDatabase, this.getFetch(), window, console)(callbackPathOrUrl, extras);
|
|
599
|
-
return this.logoutPromise.then(result => {
|
|
600
|
-
this.logoutPromise = null;
|
|
601
|
-
return result;
|
|
602
|
-
});
|
|
603
|
-
});
|
|
604
|
-
}
|
|
605
|
-
}
|
|
606
|
-
exports.Oidc = Oidc;
|
|
607
|
-
Oidc.getOrCreate = (getFetch) => (configuration, name = 'default') => {
|
|
608
|
-
return oidcFactory(getFetch)(configuration, name);
|
|
609
|
-
};
|
|
610
|
-
Oidc.eventNames = events_js_1.eventNames;
|
|
611
|
-
exports.default = Oidc;
|
|
612
|
-
//# sourceMappingURL=oidc.js.map
|