@axa-fr/react-oidc 6.0.0-beta9 → 6.0.0
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/README.md +13 -4
- package/dist/FetchToken.d.ts.map +1 -1
- package/dist/FetchToken.js +10 -6
- package/dist/FetchToken.js.map +1 -1
- package/dist/OidcProvider.d.ts +1 -0
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +11 -4
- package/dist/OidcProvider.js.map +1 -1
- package/dist/OidcSecure.js +2 -2
- package/dist/OidcSecure.js.map +1 -1
- package/dist/OidcServiceWorker.js +62 -32
- package/dist/OidcTrustedDomains.js +7 -2
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/ReactOidc.js +4 -3
- package/dist/ReactOidc.js.map +1 -1
- package/dist/core/default-component/SilentLogin.component.js +1 -1
- package/dist/core/default-component/SilentLogin.component.js.map +1 -1
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.js +1 -4
- package/dist/core/routes/OidcRoutes.js.map +1 -1
- package/dist/vanilla/initSession.d.ts +2 -1
- package/dist/vanilla/initSession.d.ts.map +1 -1
- package/dist/vanilla/initSession.js +7 -7
- package/dist/vanilla/initSession.js.map +1 -1
- package/dist/vanilla/initWorker.d.ts +2 -3
- package/dist/vanilla/initWorker.d.ts.map +1 -1
- package/dist/vanilla/initWorker.js +6 -21
- package/dist/vanilla/initWorker.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +10 -5
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +463 -492
- package/dist/vanilla/oidc.js.map +1 -1
- package/package.json +1 -1
- package/src/oidc/FetchToken.tsx +7 -4
- package/src/oidc/OidcProvider.tsx +9 -0
- package/src/oidc/OidcSecure.tsx +2 -2
- package/src/oidc/ReactOidc.tsx +4 -3
- package/src/oidc/core/default-component/SilentLogin.component.tsx +1 -1
- package/src/oidc/core/routes/OidcRoutes.tsx +0 -4
- package/src/oidc/vanilla/OidcServiceWorker.js +62 -32
- package/src/oidc/vanilla/OidcTrustedDomains.js +7 -2
- package/src/oidc/vanilla/initSession.ts +6 -7
- package/src/oidc/vanilla/initWorker.ts +6 -15
- package/src/oidc/vanilla/oidc.ts +220 -277
- package/src/oidc/vanilla/parseTokens.js +107 -0
- package/dist/core/default-component/ServiceWorkerInstall.component.d.ts +0 -4
- package/dist/core/default-component/ServiceWorkerInstall.component.d.ts.map +0 -1
- package/dist/core/default-component/ServiceWorkerInstall.component.js +0 -131
- package/dist/core/default-component/ServiceWorkerInstall.component.js.map +0 -1
- package/src/oidc/core/default-component/ServiceWorkerInstall.component.tsx +0 -60
package/dist/vanilla/oidc.js
CHANGED
|
@@ -74,8 +74,9 @@ var initSession_1 = require("./initSession");
|
|
|
74
74
|
var timer_1 = __importDefault(require("./timer"));
|
|
75
75
|
var checkSessionIFrame_1 = require("./checkSessionIFrame");
|
|
76
76
|
var route_utils_1 = require("./route-utils");
|
|
77
|
+
var parseTokens_1 = require("./parseTokens");
|
|
77
78
|
var performTokenRequestAsync = function (url, details, extras) { return __awaiter(void 0, void 0, void 0, function () {
|
|
78
|
-
var _i, _a, _b, key, value, formBody, property, encodedKey, encodedValue, formBodyString, response, tokens
|
|
79
|
+
var _i, _a, _b, key, value, formBody, property, encodedKey, encodedValue, formBodyString, response, tokens;
|
|
79
80
|
return __generator(this, function (_c) {
|
|
80
81
|
switch (_c.label) {
|
|
81
82
|
case 0:
|
|
@@ -107,20 +108,9 @@ var performTokenRequestAsync = function (url, details, extras) { return __awaite
|
|
|
107
108
|
return [4 /*yield*/, response.json()];
|
|
108
109
|
case 2:
|
|
109
110
|
tokens = _c.sent();
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
}
|
|
114
|
-
return [2 /*return*/, { success: true,
|
|
115
|
-
data: {
|
|
116
|
-
accessToken: tokens.access_token,
|
|
117
|
-
expiresIn: tokens.expires_in,
|
|
118
|
-
idToken: tokens.id_token,
|
|
119
|
-
refreshToken: tokens.refresh_token,
|
|
120
|
-
scope: tokens.scope,
|
|
121
|
-
tokenType: tokens.token_type,
|
|
122
|
-
issuedAt: tokens.issued_at
|
|
123
|
-
}
|
|
111
|
+
return [2 /*return*/, {
|
|
112
|
+
success: true,
|
|
113
|
+
data: (0, parseTokens_1.parseOriginalTokens)(tokens)
|
|
124
114
|
}];
|
|
125
115
|
}
|
|
126
116
|
});
|
|
@@ -171,33 +161,6 @@ var OidcAuthorizationServiceConfiguration = /** @class */ (function (_super) {
|
|
|
171
161
|
return OidcAuthorizationServiceConfiguration;
|
|
172
162
|
}(appauth_1.AuthorizationServiceConfiguration));
|
|
173
163
|
exports.OidcAuthorizationServiceConfiguration = OidcAuthorizationServiceConfiguration;
|
|
174
|
-
var idTokenPayload = function (token) {
|
|
175
|
-
var base64Url = token.split('.')[1];
|
|
176
|
-
var base64 = base64Url.replace(/-/g, '+').replace(/_/g, '/');
|
|
177
|
-
var jsonPayload = decodeURIComponent(atob(base64).split('').map(function (c) {
|
|
178
|
-
return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2);
|
|
179
|
-
}).join(''));
|
|
180
|
-
return JSON.parse(jsonPayload);
|
|
181
|
-
};
|
|
182
|
-
var countLetter = function (str, find) {
|
|
183
|
-
return (str.split(find)).length - 1;
|
|
184
|
-
};
|
|
185
|
-
var extractAccessTokenPayload = function (tokens) {
|
|
186
|
-
if (tokens.accessTokenPayload) {
|
|
187
|
-
return tokens.accessTokenPayload;
|
|
188
|
-
}
|
|
189
|
-
var accessToken = tokens.accessToken;
|
|
190
|
-
try {
|
|
191
|
-
if (!accessToken || countLetter(accessToken, '.') != 2) {
|
|
192
|
-
return null;
|
|
193
|
-
}
|
|
194
|
-
return JSON.parse(atob(accessToken.split('.')[1]));
|
|
195
|
-
}
|
|
196
|
-
catch (e) {
|
|
197
|
-
console.warn(e);
|
|
198
|
-
}
|
|
199
|
-
return null;
|
|
200
|
-
};
|
|
201
164
|
var oidcDatabase = {};
|
|
202
165
|
var oidcFactory = function (configuration, name) {
|
|
203
166
|
if (name === void 0) { name = "default"; }
|
|
@@ -220,50 +183,35 @@ var loginCallbackWithAutoTokensRenewAsync = function (oidc) { return __awaiter(v
|
|
|
220
183
|
});
|
|
221
184
|
}); };
|
|
222
185
|
var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
|
|
223
|
-
var
|
|
224
|
-
var refreshTimeBeforeTokensExpirationInSecond = (_a = oidc.configuration.refresh_time_before_tokens_expiration_in_second) !== null && _a !== void 0 ? _a : 60;
|
|
186
|
+
var refreshTimeBeforeTokensExpirationInSecond = oidc.configuration.refresh_time_before_tokens_expiration_in_second;
|
|
225
187
|
return timer_1.default.setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
226
|
-
var
|
|
188
|
+
var timeLeft, timeInfo, _a, tokens, status;
|
|
227
189
|
return __generator(this, function (_b) {
|
|
228
190
|
switch (_b.label) {
|
|
229
191
|
case 0:
|
|
230
|
-
|
|
231
|
-
timeInfo = { timeLeft:
|
|
192
|
+
timeLeft = (0, parseTokens_1.computeTimeLeft)(refreshTimeBeforeTokensExpirationInSecond, expiresAt);
|
|
193
|
+
timeInfo = { timeLeft: timeLeft };
|
|
232
194
|
oidc.publishEvent(Oidc.eventNames.token_timer, timeInfo);
|
|
233
|
-
|
|
234
|
-
return [4 /*yield*/, oidc.refreshTokensAsync(refreshToken)];
|
|
195
|
+
return [4 /*yield*/, oidc.synchroniseTokensAsync(refreshToken)];
|
|
235
196
|
case 1:
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
return [
|
|
239
|
-
case 2:
|
|
240
|
-
_a.tokens = _b.sent();
|
|
241
|
-
if (!!oidc.serviceWorker) return [3 /*break*/, 4];
|
|
197
|
+
_a = _b.sent(), tokens = _a.tokens, status = _a.status;
|
|
198
|
+
oidc.tokens = tokens;
|
|
199
|
+
if (!!oidc.serviceWorker) return [3 /*break*/, 3];
|
|
242
200
|
return [4 /*yield*/, oidc.session.setTokens(oidc.tokens)];
|
|
243
|
-
case
|
|
201
|
+
case 2:
|
|
244
202
|
_b.sent();
|
|
245
|
-
_b.label =
|
|
203
|
+
_b.label = 3;
|
|
204
|
+
case 3:
|
|
205
|
+
if (!!oidc.tokens) return [3 /*break*/, 5];
|
|
206
|
+
return [4 /*yield*/, oidc.destroyAsync(status)];
|
|
246
207
|
case 4:
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
oidc.checkSessionIFrame = null;
|
|
251
|
-
}
|
|
252
|
-
return [2 /*return*/];
|
|
253
|
-
}
|
|
254
|
-
oidc.publishEvent(Oidc.eventNames.token_renewed, {});
|
|
208
|
+
_b.sent();
|
|
209
|
+
return [2 /*return*/];
|
|
210
|
+
case 5:
|
|
255
211
|
if (oidc.timeoutId) {
|
|
256
212
|
oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt);
|
|
257
213
|
}
|
|
258
|
-
return [
|
|
259
|
-
case 5: return [4 /*yield*/, oidc.syncTokensAsync()];
|
|
260
|
-
case 6:
|
|
261
|
-
tokens = _b.sent();
|
|
262
|
-
if (tokens && oidc.timeoutId) {
|
|
263
|
-
oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, expiresAt);
|
|
264
|
-
}
|
|
265
|
-
_b.label = 7;
|
|
266
|
-
case 7: return [2 /*return*/];
|
|
214
|
+
return [2 /*return*/];
|
|
267
215
|
}
|
|
268
216
|
});
|
|
269
217
|
}); }, 1000);
|
|
@@ -271,8 +219,18 @@ var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
|
|
|
271
219
|
var getLoginSessionKey = function (configurationName, redirectUri) {
|
|
272
220
|
return "oidc_login.".concat(configurationName, ":").concat(redirectUri);
|
|
273
221
|
};
|
|
222
|
+
var setLoginParams = function (configurationName, redirectUri, data) {
|
|
223
|
+
var sessionKey = getLoginSessionKey(configurationName, redirectUri);
|
|
224
|
+
getLoginParamsCache = data;
|
|
225
|
+
sessionStorage[sessionKey] = JSON.stringify(data);
|
|
226
|
+
};
|
|
227
|
+
var getLoginParamsCache = null;
|
|
274
228
|
var getLoginParams = function (configurationName, redirectUri) {
|
|
275
|
-
|
|
229
|
+
var dataString = sessionStorage[getLoginSessionKey(configurationName, redirectUri)];
|
|
230
|
+
if (!getLoginParamsCache) {
|
|
231
|
+
getLoginParamsCache = JSON.parse(dataString);
|
|
232
|
+
}
|
|
233
|
+
return getLoginParamsCache;
|
|
276
234
|
};
|
|
277
235
|
var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, function () {
|
|
278
236
|
var accessToken, oidcServerConfiguration, url, fetchUserInfo, userInfo;
|
|
@@ -285,15 +243,19 @@ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, f
|
|
|
285
243
|
if (!oidc.tokens) {
|
|
286
244
|
return [2 /*return*/, null];
|
|
287
245
|
}
|
|
288
|
-
|
|
289
|
-
|
|
246
|
+
accessToken = oidc.tokens.accessToken;
|
|
247
|
+
if (!accessToken) {
|
|
248
|
+
return [2 /*return*/, null];
|
|
249
|
+
}
|
|
250
|
+
_a.label = 1;
|
|
290
251
|
case 1:
|
|
291
|
-
|
|
292
|
-
|
|
252
|
+
if (!(oidc.tokens && !(0, parseTokens_1.isTokensValid)(oidc.tokens))) return [3 /*break*/, 3];
|
|
253
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(200)];
|
|
293
254
|
case 2:
|
|
294
|
-
|
|
295
|
-
return [
|
|
296
|
-
case 3:
|
|
255
|
+
_a.sent();
|
|
256
|
+
return [3 /*break*/, 1];
|
|
257
|
+
case 3: return [4 /*yield*/, oidc.initAsync(oidc.configuration.authority, oidc.configuration.authority_configuration)];
|
|
258
|
+
case 4:
|
|
297
259
|
oidcServerConfiguration = _a.sent();
|
|
298
260
|
url = oidcServerConfiguration.userInfoEndpoint;
|
|
299
261
|
fetchUserInfo = function (accessToken) { return __awaiter(void 0, void 0, void 0, function () {
|
|
@@ -316,47 +278,18 @@ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, f
|
|
|
316
278
|
});
|
|
317
279
|
}); };
|
|
318
280
|
return [4 /*yield*/, fetchUserInfo(accessToken)];
|
|
319
|
-
case
|
|
281
|
+
case 5:
|
|
320
282
|
userInfo = _a.sent();
|
|
321
283
|
oidc.userInfo = userInfo;
|
|
322
284
|
return [2 /*return*/, userInfo];
|
|
323
285
|
}
|
|
324
286
|
});
|
|
325
287
|
}); };
|
|
326
|
-
var setTokensAsync = function (serviceWorker, tokens) { return __awaiter(void 0, void 0, void 0, function () {
|
|
327
|
-
var accessTokenPayload, _idTokenPayload, idTokenExipreAt, accessTokenExpiresAt, expiresAt;
|
|
328
|
-
return __generator(this, function (_a) {
|
|
329
|
-
switch (_a.label) {
|
|
330
|
-
case 0:
|
|
331
|
-
if (!(tokens == null)) return [3 /*break*/, 3];
|
|
332
|
-
if (!serviceWorker) return [3 /*break*/, 2];
|
|
333
|
-
return [4 /*yield*/, serviceWorker.clearAsync()];
|
|
334
|
-
case 1:
|
|
335
|
-
_a.sent();
|
|
336
|
-
_a.label = 2;
|
|
337
|
-
case 2: return [2 /*return*/, null];
|
|
338
|
-
case 3:
|
|
339
|
-
if (!serviceWorker) return [3 /*break*/, 5];
|
|
340
|
-
return [4 /*yield*/, serviceWorker.getAccessTokenPayloadAsync()];
|
|
341
|
-
case 4:
|
|
342
|
-
accessTokenPayload = _a.sent();
|
|
343
|
-
return [3 /*break*/, 6];
|
|
344
|
-
case 5:
|
|
345
|
-
accessTokenPayload = extractAccessTokenPayload(tokens);
|
|
346
|
-
_a.label = 6;
|
|
347
|
-
case 6:
|
|
348
|
-
_idTokenPayload = idTokenPayload(tokens.idToken);
|
|
349
|
-
idTokenExipreAt = (_idTokenPayload && _idTokenPayload.exp) ? _idTokenPayload.exp : Number.MAX_VALUE;
|
|
350
|
-
accessTokenExpiresAt = (accessTokenPayload && accessTokenPayload.exp) ? accessTokenPayload.exp : tokens.issuedAt + tokens.expiresIn;
|
|
351
|
-
expiresAt = idTokenExipreAt < accessTokenExpiresAt ? idTokenExipreAt : accessTokenExpiresAt;
|
|
352
|
-
return [2 /*return*/, __assign(__assign({}, tokens), { idTokenPayload: _idTokenPayload, accessTokenPayload: accessTokenPayload, expiresAt: expiresAt })];
|
|
353
|
-
}
|
|
354
|
-
});
|
|
355
|
-
}); };
|
|
356
288
|
var eventNames = {
|
|
357
289
|
service_worker_not_supported_by_browser: "service_worker_not_supported_by_browser",
|
|
358
290
|
token_aquired: "token_aquired",
|
|
359
291
|
logout_from_another_tab: "logout_from_another_tab",
|
|
292
|
+
logout_from_same_tab: "logout_from_same_tab",
|
|
360
293
|
token_renewed: "token_renewed",
|
|
361
294
|
token_timer: "token_timer",
|
|
362
295
|
loginAsync_begin: "loginAsync_begin",
|
|
@@ -443,16 +376,16 @@ var buildQueries = function (extras) {
|
|
|
443
376
|
var Oidc = /** @class */ (function () {
|
|
444
377
|
function Oidc(configuration, configurationName) {
|
|
445
378
|
if (configurationName === void 0) { configurationName = "default"; }
|
|
379
|
+
var _a, _b, _c;
|
|
446
380
|
this.tryKeepExistingSessionPromise = null;
|
|
447
381
|
this.loginPromise = null;
|
|
448
382
|
this.loginCallbackPromise = null;
|
|
449
|
-
this.syncTokensAsyncPromise = null;
|
|
450
383
|
this.loginCallbackWithAutoTokensRenewPromise = null;
|
|
451
384
|
var silent_login_uri = configuration.silent_login_uri;
|
|
452
385
|
if (configuration.silent_redirect_uri && !configuration.silent_login_uri) {
|
|
453
386
|
silent_login_uri = "".concat(configuration.silent_redirect_uri.replace("-callback", "").replace("callback", ""), "-login");
|
|
454
387
|
}
|
|
455
|
-
this.configuration = __assign(__assign({}, configuration), { silent_login_uri: silent_login_uri });
|
|
388
|
+
this.configuration = __assign(__assign({}, configuration), { silent_login_uri: silent_login_uri, monitor_session: (_a = configuration.monitor_session) !== null && _a !== void 0 ? _a : true, refresh_time_before_tokens_expiration_in_second: (_b = configuration.refresh_time_before_tokens_expiration_in_second) !== null && _b !== void 0 ? _b : 60, silent_login_timeout: (_c = configuration.silent_login_timeout) !== null && _c !== void 0 ? _c : 12000 });
|
|
456
389
|
this.configurationName = configurationName;
|
|
457
390
|
this.tokens = null;
|
|
458
391
|
this.userInfo = null;
|
|
@@ -460,7 +393,7 @@ var Oidc = /** @class */ (function () {
|
|
|
460
393
|
this.timeoutId = null;
|
|
461
394
|
this.serviceWorker = null;
|
|
462
395
|
this.session = null;
|
|
463
|
-
this.
|
|
396
|
+
this.synchroniseTokensAsync.bind(this);
|
|
464
397
|
this.loginCallbackWithAutoTokensRenewAsync.bind(this);
|
|
465
398
|
this.initAsync.bind(this);
|
|
466
399
|
this.loginCallbackAsync.bind(this);
|
|
@@ -537,130 +470,106 @@ var Oidc = /** @class */ (function () {
|
|
|
537
470
|
if (state === void 0) { state = null; }
|
|
538
471
|
if (scope === void 0) { scope = null; }
|
|
539
472
|
return __awaiter(this, void 0, void 0, function () {
|
|
540
|
-
var
|
|
473
|
+
var configuration_1, queries, _i, _a, _b, key, value, link, idx, iFrameOrigin_1, iframe_1, self_1;
|
|
541
474
|
return __generator(this, function (_c) {
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
475
|
+
if (!this.configuration.silent_redirect_uri || !this.configuration.silent_login_uri) {
|
|
476
|
+
return [2 /*return*/, Promise.resolve(null)];
|
|
477
|
+
}
|
|
478
|
+
try {
|
|
479
|
+
this.publishEvent(eventNames.silentLoginAsync_begin, {});
|
|
480
|
+
configuration_1 = this.configuration;
|
|
481
|
+
queries = "";
|
|
482
|
+
if (state) {
|
|
483
|
+
if (extras == null) {
|
|
484
|
+
extras = {};
|
|
546
485
|
}
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
550
|
-
|
|
551
|
-
|
|
552
|
-
|
|
553
|
-
|
|
554
|
-
|
|
555
|
-
|
|
556
|
-
|
|
557
|
-
|
|
558
|
-
|
|
559
|
-
|
|
560
|
-
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
561
|
-
case 5:
|
|
562
|
-
_c.sent();
|
|
563
|
-
numberTryOnline--;
|
|
564
|
-
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because navigator is offline try ".concat(numberTryOnline) });
|
|
565
|
-
return [3 /*break*/, 4];
|
|
566
|
-
case 6:
|
|
567
|
-
try {
|
|
568
|
-
this.publishEvent(eventNames.silentLoginAsync_begin, {});
|
|
569
|
-
configuration_1 = this.configuration;
|
|
570
|
-
queries = "";
|
|
571
|
-
if (state) {
|
|
572
|
-
if (extras == null) {
|
|
573
|
-
extras = {};
|
|
574
|
-
}
|
|
575
|
-
extras.state = state;
|
|
576
|
-
}
|
|
577
|
-
if (scope) {
|
|
578
|
-
if (extras == null) {
|
|
579
|
-
extras = {};
|
|
580
|
-
}
|
|
581
|
-
extras.scope = scope;
|
|
486
|
+
extras.state = state;
|
|
487
|
+
}
|
|
488
|
+
if (scope) {
|
|
489
|
+
if (extras == null) {
|
|
490
|
+
extras = {};
|
|
491
|
+
}
|
|
492
|
+
extras.scope = scope;
|
|
493
|
+
}
|
|
494
|
+
if (extras != null) {
|
|
495
|
+
for (_i = 0, _a = Object.entries(extras); _i < _a.length; _i++) {
|
|
496
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
497
|
+
if (queries === "") {
|
|
498
|
+
queries = "?".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
|
|
582
499
|
}
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
586
|
-
if (queries === "") {
|
|
587
|
-
queries = "?".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
|
|
588
|
-
}
|
|
589
|
-
else {
|
|
590
|
-
queries += "&".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
|
|
591
|
-
}
|
|
592
|
-
}
|
|
500
|
+
else {
|
|
501
|
+
queries += "&".concat(encodeURIComponent(key), "=").concat(encodeURIComponent(value));
|
|
593
502
|
}
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
if (data.startsWith(key)) {
|
|
617
|
-
var result = JSON.parse(e.data.replace(key, ''));
|
|
618
|
-
self_1.publishEvent(eventNames.silentLoginAsync_end, {});
|
|
619
|
-
iframe_1.remove();
|
|
620
|
-
isResolved_1 = true;
|
|
621
|
-
resolve(result);
|
|
622
|
-
}
|
|
623
|
-
else if (data.startsWith(key_error)) {
|
|
624
|
-
var result = JSON.parse(e.data.replace(key_error, ''));
|
|
625
|
-
self_1.publishEvent(eventNames.silentLoginAsync_error, result);
|
|
626
|
-
iframe_1.remove();
|
|
627
|
-
isResolved_1 = true;
|
|
628
|
-
reject(new Error("oidc_" + result.error));
|
|
629
|
-
}
|
|
630
|
-
}
|
|
631
|
-
}
|
|
632
|
-
}
|
|
633
|
-
};
|
|
634
|
-
var silentSigninTimeout = (_a = configuration_1.silent_login_timeout) !== null && _a !== void 0 ? _a : 12000;
|
|
635
|
-
setTimeout(function () {
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
link = configuration_1.silent_login_uri + queries;
|
|
506
|
+
idx = link.indexOf("/", link.indexOf("//") + 2);
|
|
507
|
+
iFrameOrigin_1 = link.substr(0, idx);
|
|
508
|
+
iframe_1 = document.createElement('iframe');
|
|
509
|
+
iframe_1.width = "0px";
|
|
510
|
+
iframe_1.height = "0px";
|
|
511
|
+
iframe_1.id = "".concat(this.configurationName, "_oidc_iframe");
|
|
512
|
+
iframe_1.setAttribute("src", link);
|
|
513
|
+
document.body.appendChild(iframe_1);
|
|
514
|
+
self_1 = this;
|
|
515
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
516
|
+
try {
|
|
517
|
+
var isResolved_1 = false;
|
|
518
|
+
window.onmessage = function (e) {
|
|
519
|
+
if (e.origin === iFrameOrigin_1 &&
|
|
520
|
+
e.source === iframe_1.contentWindow) {
|
|
521
|
+
var key = "".concat(self_1.configurationName, "_oidc_tokens:");
|
|
522
|
+
var key_error = "".concat(self_1.configurationName, "_oidc_error:");
|
|
523
|
+
var data = e.data;
|
|
524
|
+
if (data && typeof (data) === "string") {
|
|
636
525
|
if (!isResolved_1) {
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
|
|
526
|
+
if (data.startsWith(key)) {
|
|
527
|
+
var result = JSON.parse(e.data.replace(key, ''));
|
|
528
|
+
self_1.publishEvent(eventNames.silentLoginAsync_end, {});
|
|
529
|
+
iframe_1.remove();
|
|
530
|
+
isResolved_1 = true;
|
|
531
|
+
resolve(result);
|
|
532
|
+
}
|
|
533
|
+
else if (data.startsWith(key_error)) {
|
|
534
|
+
var result = JSON.parse(e.data.replace(key_error, ''));
|
|
535
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, result);
|
|
536
|
+
iframe_1.remove();
|
|
537
|
+
isResolved_1 = true;
|
|
538
|
+
reject(new Error("oidc_" + result.error));
|
|
539
|
+
}
|
|
641
540
|
}
|
|
642
|
-
}
|
|
541
|
+
}
|
|
643
542
|
}
|
|
644
|
-
|
|
543
|
+
};
|
|
544
|
+
var silentSigninTimeout = configuration_1.silent_login_timeout;
|
|
545
|
+
setTimeout(function () {
|
|
546
|
+
if (!isResolved_1) {
|
|
547
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, { reason: "timeout" });
|
|
645
548
|
iframe_1.remove();
|
|
646
|
-
|
|
647
|
-
reject(
|
|
549
|
+
isResolved_1 = true;
|
|
550
|
+
reject(new Error("timeout"));
|
|
648
551
|
}
|
|
649
|
-
})
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
|
|
655
|
-
|
|
552
|
+
}, silentSigninTimeout);
|
|
553
|
+
}
|
|
554
|
+
catch (e) {
|
|
555
|
+
iframe_1.remove();
|
|
556
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
557
|
+
reject(e);
|
|
558
|
+
}
|
|
559
|
+
})];
|
|
560
|
+
}
|
|
561
|
+
catch (e) {
|
|
562
|
+
this.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
563
|
+
throw e;
|
|
656
564
|
}
|
|
565
|
+
return [2 /*return*/];
|
|
657
566
|
});
|
|
658
567
|
});
|
|
659
568
|
};
|
|
660
569
|
Oidc.prototype.initAsync = function (authority, authorityConfiguration) {
|
|
661
570
|
var _a;
|
|
662
571
|
return __awaiter(this, void 0, void 0, function () {
|
|
663
|
-
var serviceWorker, storage
|
|
572
|
+
var serviceWorker, storage;
|
|
664
573
|
return __generator(this, function (_b) {
|
|
665
574
|
switch (_b.label) {
|
|
666
575
|
case 0:
|
|
@@ -679,9 +588,7 @@ var Oidc = /** @class */ (function () {
|
|
|
679
588
|
serviceWorker = _b.sent();
|
|
680
589
|
storage = serviceWorker ? window.localStorage : null;
|
|
681
590
|
return [4 /*yield*/, fetchFromIssuer(authority, (_a = this.configuration.authority_time_cache_wellknowurl_in_second) !== null && _a !== void 0 ? _a : 60 * 60, storage)];
|
|
682
|
-
case 2:
|
|
683
|
-
initAsyncPromise = _b.sent();
|
|
684
|
-
return [2 /*return*/, initAsyncPromise];
|
|
591
|
+
case 2: return [2 /*return*/, _b.sent()];
|
|
685
592
|
}
|
|
686
593
|
});
|
|
687
594
|
});
|
|
@@ -695,83 +602,68 @@ var Oidc = /** @class */ (function () {
|
|
|
695
602
|
return [2 /*return*/, this.tryKeepExistingSessionPromise];
|
|
696
603
|
}
|
|
697
604
|
funcAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
698
|
-
var serviceWorker, configuration, oidcServerConfiguration, tokens,
|
|
699
|
-
var
|
|
700
|
-
return __generator(this, function (
|
|
701
|
-
switch (
|
|
605
|
+
var serviceWorker, configuration, oidcServerConfiguration, tokens, sessionState, session, tokens, sessionState, exception_1;
|
|
606
|
+
var _a;
|
|
607
|
+
return __generator(this, function (_b) {
|
|
608
|
+
switch (_b.label) {
|
|
702
609
|
case 0:
|
|
703
610
|
if (this.tokens != null) {
|
|
704
611
|
return [2 /*return*/, false];
|
|
705
612
|
}
|
|
706
613
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_begin, {});
|
|
707
|
-
|
|
614
|
+
_b.label = 1;
|
|
708
615
|
case 1:
|
|
709
|
-
|
|
616
|
+
_b.trys.push([1, 12, , 15]);
|
|
710
617
|
configuration = this.configuration;
|
|
711
618
|
return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
|
|
712
619
|
case 2:
|
|
713
|
-
oidcServerConfiguration =
|
|
620
|
+
oidcServerConfiguration = _b.sent();
|
|
714
621
|
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
|
|
715
622
|
case 3:
|
|
716
|
-
serviceWorker =
|
|
717
|
-
if (!serviceWorker) return [3 /*break*/,
|
|
623
|
+
serviceWorker = _b.sent();
|
|
624
|
+
if (!serviceWorker) return [3 /*break*/, 8];
|
|
718
625
|
return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "tryKeepExistingSessionAsync")];
|
|
719
626
|
case 4:
|
|
720
|
-
tokens = (
|
|
721
|
-
if (!tokens) return [3 /*break*/,
|
|
627
|
+
tokens = (_b.sent()).tokens;
|
|
628
|
+
if (!tokens) return [3 /*break*/, 7];
|
|
722
629
|
serviceWorker.startKeepAliveServiceWorker();
|
|
723
|
-
|
|
724
|
-
|
|
725
|
-
refreshToken: tokens.refresh_token,
|
|
726
|
-
expiresIn: tokens.expires_in,
|
|
727
|
-
idToken: tokens.id_token,
|
|
728
|
-
scope: tokens.scope,
|
|
729
|
-
tokenType: tokens.token_type,
|
|
730
|
-
issuedAt: tokens.issued_at
|
|
731
|
-
};
|
|
732
|
-
_a = this;
|
|
733
|
-
return [4 /*yield*/, setTokensAsync(serviceWorker, reformattedToken)];
|
|
734
|
-
case 5:
|
|
735
|
-
_a.tokens = _d.sent();
|
|
630
|
+
// @ts-ignore
|
|
631
|
+
this.tokens = tokens;
|
|
736
632
|
this.serviceWorker = serviceWorker;
|
|
737
633
|
// @ts-ignore
|
|
738
634
|
this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt);
|
|
739
635
|
return [4 /*yield*/, serviceWorker.getSessionStateAsync()];
|
|
740
|
-
case
|
|
741
|
-
sessionState =
|
|
636
|
+
case 5:
|
|
637
|
+
sessionState = _b.sent();
|
|
742
638
|
// @ts-ignore
|
|
743
639
|
return [4 /*yield*/, this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState)];
|
|
744
|
-
case
|
|
640
|
+
case 6:
|
|
745
641
|
// @ts-ignore
|
|
746
|
-
|
|
642
|
+
_b.sent();
|
|
747
643
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
748
644
|
success: true,
|
|
749
645
|
message: "tokens inside ServiceWorker are valid"
|
|
750
646
|
});
|
|
751
647
|
return [2 /*return*/, true];
|
|
752
|
-
case
|
|
648
|
+
case 7:
|
|
753
649
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
754
650
|
success: false,
|
|
755
651
|
message: "no exiting session found"
|
|
756
652
|
});
|
|
757
|
-
return [3 /*break*/,
|
|
758
|
-
case
|
|
653
|
+
return [3 /*break*/, 11];
|
|
654
|
+
case 8:
|
|
759
655
|
if (configuration.service_worker_relative_url) {
|
|
760
656
|
this.publishEvent(eventNames.service_worker_not_supported_by_browser, {
|
|
761
657
|
message: "service worker is not supported by this browser"
|
|
762
658
|
});
|
|
763
659
|
}
|
|
764
|
-
session = (0, initSession_1.initSession)(this.configurationName, configuration.redirect_uri, (
|
|
660
|
+
session = (0, initSession_1.initSession)(this.configurationName, configuration.redirect_uri, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
|
|
765
661
|
return [4 /*yield*/, session.initAsync()];
|
|
766
|
-
case
|
|
767
|
-
tokens = (
|
|
768
|
-
if (!tokens) return [3 /*break*/,
|
|
769
|
-
// @ts-ignore
|
|
770
|
-
_b = this;
|
|
771
|
-
return [4 /*yield*/, setTokensAsync(serviceWorker, tokens)];
|
|
772
|
-
case 11:
|
|
662
|
+
case 9:
|
|
663
|
+
tokens = (_b.sent()).tokens;
|
|
664
|
+
if (!tokens) return [3 /*break*/, 11];
|
|
773
665
|
// @ts-ignore
|
|
774
|
-
|
|
666
|
+
this.tokens = (0, parseTokens_1.setTokens)(tokens);
|
|
775
667
|
//session.setTokens(this.tokens);
|
|
776
668
|
this.session = session;
|
|
777
669
|
// @ts-ignore
|
|
@@ -779,32 +671,32 @@ var Oidc = /** @class */ (function () {
|
|
|
779
671
|
sessionState = session.getSessionState();
|
|
780
672
|
// @ts-ignore
|
|
781
673
|
return [4 /*yield*/, this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState)];
|
|
782
|
-
case
|
|
674
|
+
case 10:
|
|
783
675
|
// @ts-ignore
|
|
784
|
-
|
|
676
|
+
_b.sent();
|
|
785
677
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
786
678
|
success: true,
|
|
787
679
|
message: "tokens inside storage are valid"
|
|
788
680
|
});
|
|
789
681
|
return [2 /*return*/, true];
|
|
790
|
-
case
|
|
682
|
+
case 11:
|
|
791
683
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
792
684
|
success: false,
|
|
793
685
|
message: serviceWorker ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
|
|
794
686
|
});
|
|
795
687
|
return [2 /*return*/, false];
|
|
796
|
-
case
|
|
797
|
-
exception_1 =
|
|
688
|
+
case 12:
|
|
689
|
+
exception_1 = _b.sent();
|
|
798
690
|
console.error(exception_1);
|
|
799
|
-
if (!serviceWorker) return [3 /*break*/,
|
|
691
|
+
if (!serviceWorker) return [3 /*break*/, 14];
|
|
800
692
|
return [4 /*yield*/, serviceWorker.clearAsync()];
|
|
801
|
-
case
|
|
802
|
-
|
|
803
|
-
|
|
804
|
-
case
|
|
693
|
+
case 13:
|
|
694
|
+
_b.sent();
|
|
695
|
+
_b.label = 14;
|
|
696
|
+
case 14:
|
|
805
697
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid");
|
|
806
698
|
return [2 /*return*/, false];
|
|
807
|
-
case
|
|
699
|
+
case 15: return [2 /*return*/];
|
|
808
700
|
}
|
|
809
701
|
});
|
|
810
702
|
}); };
|
|
@@ -816,10 +708,9 @@ var Oidc = /** @class */ (function () {
|
|
|
816
708
|
});
|
|
817
709
|
});
|
|
818
710
|
};
|
|
819
|
-
Oidc.prototype.loginAsync = function (callbackPath, extras,
|
|
711
|
+
Oidc.prototype.loginAsync = function (callbackPath, extras, state, isSilentSignin, scope) {
|
|
820
712
|
if (callbackPath === void 0) { callbackPath = undefined; }
|
|
821
713
|
if (extras === void 0) { extras = null; }
|
|
822
|
-
if (installServiceWorker === void 0) { installServiceWorker = true; }
|
|
823
714
|
if (state === void 0) { state = undefined; }
|
|
824
715
|
if (isSilentSignin === void 0) { isSilentSignin = false; }
|
|
825
716
|
if (scope === void 0) { scope = undefined; }
|
|
@@ -831,7 +722,7 @@ var Oidc = /** @class */ (function () {
|
|
|
831
722
|
return [2 /*return*/, this.loginPromise];
|
|
832
723
|
}
|
|
833
724
|
loginLocalAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
834
|
-
var location_1, url, configuration, redirectUri,
|
|
725
|
+
var location_1, url, configuration, redirectUri, serviceWorker, oidcServerConfiguration, storage, session, extraFinal, queryStringUtil, authorizationHandler, authRequest, exception_2;
|
|
835
726
|
var _a;
|
|
836
727
|
return __generator(this, function (_b) {
|
|
837
728
|
switch (_b.label) {
|
|
@@ -845,8 +736,7 @@ var Oidc = /** @class */ (function () {
|
|
|
845
736
|
if (!scope) {
|
|
846
737
|
scope = configuration.scope;
|
|
847
738
|
}
|
|
848
|
-
|
|
849
|
-
sessionStorage[sessionKey] = JSON.stringify({ callbackPath: url, extras: extras, state: state });
|
|
739
|
+
setLoginParams(this.configurationName, redirectUri, { callbackPath: url, extras: extras, state: state });
|
|
850
740
|
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
|
|
851
741
|
case 1:
|
|
852
742
|
serviceWorker = _b.sent();
|
|
@@ -933,10 +823,31 @@ var Oidc = /** @class */ (function () {
|
|
|
933
823
|
else {
|
|
934
824
|
console.debug("SessionMonitor._callback: Different subject signed into OP:", iFrameIdTokenPayload.sub);
|
|
935
825
|
}
|
|
936
|
-
}).catch(function (e) {
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
826
|
+
}).catch(function (e) { return __awaiter(_this, void 0, void 0, function () {
|
|
827
|
+
var _i, _a, _b, key, oidc;
|
|
828
|
+
return __generator(this, function (_c) {
|
|
829
|
+
switch (_c.label) {
|
|
830
|
+
case 0:
|
|
831
|
+
_i = 0, _a = Object.entries(oidcDatabase);
|
|
832
|
+
_c.label = 1;
|
|
833
|
+
case 1:
|
|
834
|
+
if (!(_i < _a.length)) return [3 /*break*/, 4];
|
|
835
|
+
_b = _a[_i], key = _b[0], oidc = _b[1];
|
|
836
|
+
//if(oidc !== this) {
|
|
837
|
+
// @ts-ignore
|
|
838
|
+
return [4 /*yield*/, oidc.logoutOtherTabAsync(this.configuration.client_id, idTokenPayload.sub)];
|
|
839
|
+
case 2:
|
|
840
|
+
//if(oidc !== this) {
|
|
841
|
+
// @ts-ignore
|
|
842
|
+
_c.sent();
|
|
843
|
+
_c.label = 3;
|
|
844
|
+
case 3:
|
|
845
|
+
_i++;
|
|
846
|
+
return [3 /*break*/, 1];
|
|
847
|
+
case 4: return [2 /*return*/];
|
|
848
|
+
}
|
|
849
|
+
});
|
|
850
|
+
}); });
|
|
940
851
|
};
|
|
941
852
|
_this.checkSessionIFrame = new checkSessionIFrame_1.CheckSessionIFrame(checkSessionCallback, clientId, checkSessionIFrameUri);
|
|
942
853
|
_this.checkSessionIFrame.load().then(function () {
|
|
@@ -970,16 +881,14 @@ var Oidc = /** @class */ (function () {
|
|
|
970
881
|
case 1:
|
|
971
882
|
response = _a.sent();
|
|
972
883
|
tokens = response.tokens;
|
|
973
|
-
|
|
974
|
-
case 2:
|
|
975
|
-
parsedTokens = _a.sent();
|
|
884
|
+
parsedTokens = (0, parseTokens_1.setTokens)(tokens);
|
|
976
885
|
this.tokens = parsedTokens;
|
|
977
|
-
if (!!this.serviceWorker) return [3 /*break*/,
|
|
886
|
+
if (!!this.serviceWorker) return [3 /*break*/, 3];
|
|
978
887
|
return [4 /*yield*/, this.session.setTokens(parsedTokens)];
|
|
979
|
-
case
|
|
888
|
+
case 2:
|
|
980
889
|
_a.sent();
|
|
981
|
-
_a.label =
|
|
982
|
-
case
|
|
890
|
+
_a.label = 3;
|
|
891
|
+
case 3:
|
|
983
892
|
this.publishEvent(Oidc.eventNames.token_aquired, parsedTokens);
|
|
984
893
|
// @ts-ignore
|
|
985
894
|
return [2 /*return*/, { parsedTokens: parsedTokens, state: response.state, callbackPath: response.callbackPath }];
|
|
@@ -998,7 +907,7 @@ var Oidc = /** @class */ (function () {
|
|
|
998
907
|
var _a;
|
|
999
908
|
if (isSilentSignin === void 0) { isSilentSignin = false; }
|
|
1000
909
|
return __awaiter(this, void 0, void 0, function () {
|
|
1001
|
-
var configuration_2, clientId_1, redirectUri_1, authority, tokenRequestTimeout_1, oidcServerConfiguration_1, queryParams, sessionState_2,
|
|
910
|
+
var configuration_2, clientId_1, redirectUri_1, authority, tokenRequestTimeout_1, oidcServerConfiguration_1, queryParams, sessionState_2, serviceWorker_1, storage_1, items, dummy, session, items, exception_3;
|
|
1002
911
|
var _this = this;
|
|
1003
912
|
return __generator(this, function (_b) {
|
|
1004
913
|
switch (_b.label) {
|
|
@@ -1017,18 +926,18 @@ var Oidc = /** @class */ (function () {
|
|
|
1017
926
|
sessionState_2 = queryParams.session_state;
|
|
1018
927
|
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration_2.service_worker_relative_url, this.configurationName)];
|
|
1019
928
|
case 2:
|
|
1020
|
-
|
|
929
|
+
serviceWorker_1 = _b.sent();
|
|
1021
930
|
storage_1 = null;
|
|
1022
|
-
if (!
|
|
1023
|
-
|
|
1024
|
-
this.serviceWorker =
|
|
1025
|
-
return [4 /*yield*/,
|
|
931
|
+
if (!serviceWorker_1) return [3 /*break*/, 8];
|
|
932
|
+
serviceWorker_1.startKeepAliveServiceWorker();
|
|
933
|
+
this.serviceWorker = serviceWorker_1;
|
|
934
|
+
return [4 /*yield*/, serviceWorker_1.initAsync(oidcServerConfiguration_1, "loginCallbackAsync")];
|
|
1026
935
|
case 3:
|
|
1027
936
|
_b.sent();
|
|
1028
|
-
return [4 /*yield*/,
|
|
937
|
+
return [4 /*yield*/, serviceWorker_1.loadItemsAsync()];
|
|
1029
938
|
case 4:
|
|
1030
939
|
items = _b.sent();
|
|
1031
|
-
storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(
|
|
940
|
+
storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker_1.saveItemsAsync, items);
|
|
1032
941
|
return [4 /*yield*/, storage_1.getItem("dummy")];
|
|
1033
942
|
case 5:
|
|
1034
943
|
dummy = _b.sent();
|
|
@@ -1038,7 +947,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1038
947
|
return [4 /*yield*/, storage_1.removeItem("dummy")];
|
|
1039
948
|
case 6:
|
|
1040
949
|
_b.sent();
|
|
1041
|
-
return [4 /*yield*/,
|
|
950
|
+
return [4 /*yield*/, serviceWorker_1.setSessionStateAsync(sessionState_2)];
|
|
1042
951
|
case 7:
|
|
1043
952
|
_b.sent();
|
|
1044
953
|
return [3 /*break*/, 10];
|
|
@@ -1098,22 +1007,37 @@ var Oidc = /** @class */ (function () {
|
|
|
1098
1007
|
}, tokenRequestTimeout_1 !== null && tokenRequestTimeout_1 !== void 0 ? tokenRequestTimeout_1 : 12000);
|
|
1099
1008
|
try {
|
|
1100
1009
|
var tokenHandler = new appauth_1.BaseTokenRequestHandler(new appauth_1.FetchRequestor());
|
|
1101
|
-
tokenHandler.performTokenRequest(oidcServerConfiguration_1, tokenRequest).then(function (tokenResponse) {
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
|
|
1106
|
-
|
|
1107
|
-
|
|
1108
|
-
|
|
1109
|
-
|
|
1110
|
-
|
|
1111
|
-
|
|
1112
|
-
|
|
1113
|
-
|
|
1114
|
-
|
|
1115
|
-
|
|
1116
|
-
|
|
1010
|
+
tokenHandler.performTokenRequest(oidcServerConfiguration_1, tokenRequest).then(function (tokenResponse) { return __awaiter(_this, void 0, void 0, function () {
|
|
1011
|
+
var loginParams_1, tokens;
|
|
1012
|
+
var _this = this;
|
|
1013
|
+
return __generator(this, function (_a) {
|
|
1014
|
+
switch (_a.label) {
|
|
1015
|
+
case 0:
|
|
1016
|
+
if (!timeoutId) return [3 /*break*/, 3];
|
|
1017
|
+
clearTimeout(timeoutId);
|
|
1018
|
+
this.timeoutId = null;
|
|
1019
|
+
loginParams_1 = getLoginParams(this.configurationName, redirectUri_1);
|
|
1020
|
+
if (!serviceWorker_1) return [3 /*break*/, 2];
|
|
1021
|
+
return [4 /*yield*/, serviceWorker_1.initAsync(oidcServerConfiguration_1, "syncTokensAsync")];
|
|
1022
|
+
case 1:
|
|
1023
|
+
tokens = (_a.sent()).tokens;
|
|
1024
|
+
tokenResponse = tokens;
|
|
1025
|
+
_a.label = 2;
|
|
1026
|
+
case 2:
|
|
1027
|
+
// @ts-ignore
|
|
1028
|
+
this.startCheckSessionAsync(oidcServerConfiguration_1.check_session_iframe, clientId_1, sessionState_2, isSilentSignin).then(function () {
|
|
1029
|
+
_this.publishEvent(eventNames.loginCallbackAsync_end, {});
|
|
1030
|
+
resolve({
|
|
1031
|
+
tokens: tokenResponse,
|
|
1032
|
+
state: request.state,
|
|
1033
|
+
callbackPath: loginParams_1.callbackPath,
|
|
1034
|
+
});
|
|
1035
|
+
});
|
|
1036
|
+
_a.label = 3;
|
|
1037
|
+
case 3: return [2 /*return*/];
|
|
1038
|
+
}
|
|
1039
|
+
});
|
|
1040
|
+
}); });
|
|
1117
1041
|
}
|
|
1118
1042
|
catch (exception) {
|
|
1119
1043
|
if (timeoutId) {
|
|
@@ -1137,208 +1061,207 @@ var Oidc = /** @class */ (function () {
|
|
|
1137
1061
|
});
|
|
1138
1062
|
});
|
|
1139
1063
|
};
|
|
1140
|
-
Oidc.prototype.
|
|
1064
|
+
Oidc.prototype.synchroniseTokensAsync = function (refreshToken, index) {
|
|
1065
|
+
if (index === void 0) { index = 0; }
|
|
1141
1066
|
return __awaiter(this, void 0, void 0, function () {
|
|
1142
|
-
var
|
|
1067
|
+
var numberTryOnline, configuration, localsilentLoginAsync, _a, status_1, tokens, _b, clientId, redirectUri, authority, extras, _i, _c, _d, key, value, details, oidcServerConfiguration, tokenResponse, exception_4;
|
|
1143
1068
|
var _this = this;
|
|
1144
|
-
return __generator(this, function (
|
|
1145
|
-
switch (
|
|
1069
|
+
return __generator(this, function (_e) {
|
|
1070
|
+
switch (_e.label) {
|
|
1146
1071
|
case 0:
|
|
1072
|
+
if (!document.hidden) return [3 /*break*/, 3];
|
|
1073
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1074
|
+
case 1:
|
|
1075
|
+
_e.sent();
|
|
1076
|
+
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because document is hidden" });
|
|
1077
|
+
return [4 /*yield*/, this.synchroniseTokensAsync(refreshToken, index)];
|
|
1078
|
+
case 2: return [2 /*return*/, _e.sent()];
|
|
1079
|
+
case 3:
|
|
1080
|
+
numberTryOnline = 6;
|
|
1081
|
+
_e.label = 4;
|
|
1082
|
+
case 4:
|
|
1083
|
+
if (!(!navigator.onLine && numberTryOnline > 0)) return [3 /*break*/, 6];
|
|
1084
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1085
|
+
case 5:
|
|
1086
|
+
_e.sent();
|
|
1087
|
+
numberTryOnline--;
|
|
1088
|
+
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because navigator is offline try ".concat(numberTryOnline) });
|
|
1089
|
+
return [3 /*break*/, 4];
|
|
1090
|
+
case 6:
|
|
1091
|
+
configuration = this.configuration;
|
|
1147
1092
|
localsilentLoginAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1148
|
-
var silent_token_response, exceptionSilent_1;
|
|
1093
|
+
var loginParams, silent_token_response, exceptionSilent_1;
|
|
1149
1094
|
return __generator(this, function (_a) {
|
|
1150
1095
|
switch (_a.label) {
|
|
1151
1096
|
case 0:
|
|
1152
|
-
_a.trys.push([0, 2, ,
|
|
1153
|
-
|
|
1097
|
+
_a.trys.push([0, 2, , 4]);
|
|
1098
|
+
loginParams = getLoginParams(this.configurationName, configuration.redirect_uri);
|
|
1099
|
+
return [4 /*yield*/, this.silentLoginAsync(__assign(__assign({}, loginParams.extras), { prompt: "none" }), loginParams.state)];
|
|
1154
1100
|
case 1:
|
|
1155
1101
|
silent_token_response = _a.sent();
|
|
1156
1102
|
if (silent_token_response) {
|
|
1157
|
-
|
|
1103
|
+
this.publishEvent(Oidc.eventNames.token_renewed, {});
|
|
1104
|
+
return [2 /*return*/, { tokens: silent_token_response.tokens, status: "LOGGED" }];
|
|
1158
1105
|
}
|
|
1159
|
-
return [3 /*break*/,
|
|
1106
|
+
return [3 /*break*/, 4];
|
|
1160
1107
|
case 2:
|
|
1161
1108
|
exceptionSilent_1 = _a.sent();
|
|
1162
1109
|
console.error(exceptionSilent_1);
|
|
1163
|
-
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
this.timeoutId = null;
|
|
1110
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "exceptionSilent", exception: exceptionSilent_1.message });
|
|
1111
|
+
if (exceptionSilent_1 && exceptionSilent_1.message && exceptionSilent_1.message.startsWith("oidc")) {
|
|
1112
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token silent" });
|
|
1113
|
+
return [2 /*return*/, { tokens: null, status: "SESSION_LOST" }];
|
|
1168
1114
|
}
|
|
1169
|
-
|
|
1170
|
-
|
|
1115
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1116
|
+
case 3:
|
|
1117
|
+
_a.sent();
|
|
1118
|
+
throw exceptionSilent_1;
|
|
1119
|
+
case 4:
|
|
1120
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token silent return" });
|
|
1121
|
+
return [2 /*return*/, { tokens: null, status: "SESSION_LOST" }];
|
|
1171
1122
|
}
|
|
1172
1123
|
});
|
|
1173
1124
|
}); };
|
|
1174
|
-
|
|
1125
|
+
if (!(index <= 4)) return [3 /*break*/, 24];
|
|
1126
|
+
_e.label = 7;
|
|
1127
|
+
case 7:
|
|
1128
|
+
_e.trys.push([7, 23, , 24]);
|
|
1129
|
+
if (!!refreshToken) return [3 /*break*/, 9];
|
|
1130
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, tryNumber: index });
|
|
1131
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1132
|
+
case 8: return [2 /*return*/, _e.sent()];
|
|
1133
|
+
case 9: return [4 /*yield*/, this.syncTokensInfoAsync(configuration, this.configurationName, this.tokens)];
|
|
1134
|
+
case 10:
|
|
1135
|
+
_a = _e.sent(), status_1 = _a.status, tokens = _a.tokens;
|
|
1136
|
+
_b = status_1;
|
|
1137
|
+
switch (_b) {
|
|
1138
|
+
case "SESSION_LOST": return [3 /*break*/, 11];
|
|
1139
|
+
case "NOT_CONNECTED": return [3 /*break*/, 12];
|
|
1140
|
+
case "TOKENS_VALID": return [3 /*break*/, 13];
|
|
1141
|
+
case "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID": return [3 /*break*/, 13];
|
|
1142
|
+
case "LOGOUT_FROM_ANOTHER_TAB": return [3 /*break*/, 14];
|
|
1143
|
+
case "REQUIRE_SYNC_TOKENS": return [3 /*break*/, 15];
|
|
1144
|
+
}
|
|
1145
|
+
return [3 /*break*/, 17];
|
|
1146
|
+
case 11:
|
|
1147
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token session lost" });
|
|
1148
|
+
return [2 /*return*/, { tokens: null, status: "SESSION_LOST" }];
|
|
1149
|
+
case 12: return [2 /*return*/, { tokens: null, status: null }];
|
|
1150
|
+
case 13: return [2 /*return*/, { tokens: tokens, status: "LOGGED_IN" }];
|
|
1151
|
+
case 14:
|
|
1152
|
+
this.publishEvent(eventNames.logout_from_another_tab, { "status": "session syncTokensAsync" });
|
|
1153
|
+
return [2 /*return*/, { tokens: null, status: "LOGGED_OUT" }];
|
|
1154
|
+
case 15:
|
|
1155
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, status: status_1, tryNumber: index });
|
|
1156
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1157
|
+
case 16: return [2 /*return*/, _e.sent()];
|
|
1158
|
+
case 17:
|
|
1159
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, status: status_1, tryNumber: index });
|
|
1175
1160
|
clientId = configuration.client_id;
|
|
1176
1161
|
redirectUri = configuration.redirect_uri;
|
|
1177
1162
|
authority = configuration.authority;
|
|
1178
|
-
if (!!refreshToken) return [3 /*break*/, 2];
|
|
1179
|
-
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1180
|
-
case 1: return [2 /*return*/, _c.sent()];
|
|
1181
|
-
case 2:
|
|
1182
1163
|
extras = {};
|
|
1183
1164
|
if (configuration.token_request_extras) {
|
|
1184
|
-
for (_i = 0,
|
|
1185
|
-
|
|
1165
|
+
for (_i = 0, _c = Object.entries(configuration.token_request_extras); _i < _c.length; _i++) {
|
|
1166
|
+
_d = _c[_i], key = _d[0], value = _d[1];
|
|
1186
1167
|
extras[key] = value;
|
|
1187
1168
|
}
|
|
1188
1169
|
}
|
|
1189
|
-
return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
|
|
1190
|
-
case 3:
|
|
1191
|
-
oidcServerConfiguration = _c.sent();
|
|
1192
1170
|
details = {
|
|
1193
1171
|
client_id: clientId,
|
|
1194
1172
|
redirect_uri: redirectUri,
|
|
1195
1173
|
grant_type: appauth_1.GRANT_TYPE_REFRESH_TOKEN,
|
|
1196
|
-
refresh_token: refreshToken,
|
|
1174
|
+
refresh_token: tokens.refreshToken,
|
|
1197
1175
|
};
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, tryNumber: index });
|
|
1206
|
-
if (!(index > 1)) return [3 /*break*/, 11];
|
|
1207
|
-
_c.label = 6;
|
|
1208
|
-
case 6:
|
|
1209
|
-
if (!document.hidden) return [3 /*break*/, 8];
|
|
1210
|
-
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1211
|
-
case 7:
|
|
1212
|
-
_c.sent();
|
|
1213
|
-
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because document is hidden" });
|
|
1214
|
-
return [3 /*break*/, 6];
|
|
1215
|
-
case 8:
|
|
1216
|
-
numberTryOnline = 6;
|
|
1217
|
-
_c.label = 9;
|
|
1218
|
-
case 9:
|
|
1219
|
-
if (!(!navigator.onLine && numberTryOnline > 0)) return [3 /*break*/, 11];
|
|
1220
|
-
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1221
|
-
case 10:
|
|
1222
|
-
_c.sent();
|
|
1223
|
-
numberTryOnline--;
|
|
1224
|
-
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because navigator is offline try ".concat(numberTryOnline) });
|
|
1225
|
-
return [3 /*break*/, 9];
|
|
1226
|
-
case 11: return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, extras)];
|
|
1227
|
-
case 12:
|
|
1228
|
-
tokenResponse = _c.sent();
|
|
1229
|
-
if (!tokenResponse.success) return [3 /*break*/, 13];
|
|
1176
|
+
return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
|
|
1177
|
+
case 18:
|
|
1178
|
+
oidcServerConfiguration = _e.sent();
|
|
1179
|
+
return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, extras)];
|
|
1180
|
+
case 19:
|
|
1181
|
+
tokenResponse = _e.sent();
|
|
1182
|
+
if (!tokenResponse.success) return [3 /*break*/, 20];
|
|
1230
1183
|
this.publishEvent(eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
|
|
1231
|
-
|
|
1232
|
-
|
|
1233
|
-
|
|
1234
|
-
|
|
1235
|
-
|
|
1236
|
-
|
|
1237
|
-
|
|
1238
|
-
|
|
1184
|
+
this.publishEvent(Oidc.eventNames.token_renewed, {});
|
|
1185
|
+
return [2 /*return*/, { tokens: tokenResponse.data, status: "LOGGED_IN" }];
|
|
1186
|
+
case 20:
|
|
1187
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, {
|
|
1188
|
+
message: "bad request",
|
|
1189
|
+
tokenResponse: tokenResponse
|
|
1190
|
+
});
|
|
1191
|
+
return [4 /*yield*/, this.synchroniseTokensAsync(null, index + 1)];
|
|
1192
|
+
case 21: return [2 /*return*/, _e.sent()];
|
|
1193
|
+
case 22: return [3 /*break*/, 24];
|
|
1194
|
+
case 23:
|
|
1195
|
+
exception_4 = _e.sent();
|
|
1239
1196
|
console.error(exception_4);
|
|
1240
1197
|
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "exception", exception: exception_4.message });
|
|
1241
|
-
return [
|
|
1242
|
-
case
|
|
1243
|
-
|
|
1244
|
-
return [
|
|
1245
|
-
case 18: return [2 /*return*/];
|
|
1198
|
+
return [2 /*return*/, this.synchroniseTokensAsync(refreshToken, index + 1)];
|
|
1199
|
+
case 24:
|
|
1200
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token" });
|
|
1201
|
+
return [2 /*return*/, { tokens: null, status: "SESSION_LOST" }];
|
|
1246
1202
|
}
|
|
1247
1203
|
});
|
|
1248
1204
|
});
|
|
1249
1205
|
};
|
|
1250
|
-
Oidc.prototype.
|
|
1206
|
+
Oidc.prototype.syncTokensInfoAsync = function (configuration, configurationName, currentTokens) {
|
|
1207
|
+
var _a;
|
|
1251
1208
|
return __awaiter(this, void 0, void 0, function () {
|
|
1252
|
-
var
|
|
1253
|
-
|
|
1254
|
-
|
|
1255
|
-
|
|
1256
|
-
|
|
1257
|
-
|
|
1258
|
-
|
|
1259
|
-
|
|
1260
|
-
case 0:
|
|
1261
|
-
configuration = this.configuration;
|
|
1262
|
-
if (!this.tokens) {
|
|
1263
|
-
return [2 /*return*/, null];
|
|
1264
|
-
}
|
|
1265
|
-
return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
|
|
1266
|
-
case 1:
|
|
1267
|
-
oidcServerConfiguration = _c.sent();
|
|
1268
|
-
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
|
|
1269
|
-
case 2:
|
|
1270
|
-
serviceWorker = _c.sent();
|
|
1271
|
-
if (!serviceWorker) return [3 /*break*/, 13];
|
|
1272
|
-
return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "syncTokensAsync")];
|
|
1273
|
-
case 3:
|
|
1274
|
-
isLogin = (_c.sent()).isLogin;
|
|
1275
|
-
if (!(isLogin == false)) return [3 /*break*/, 5];
|
|
1276
|
-
this.publishEvent(eventNames.logout_from_another_tab, {});
|
|
1277
|
-
return [4 /*yield*/, this.destroyAsync()];
|
|
1278
|
-
case 4:
|
|
1279
|
-
_c.sent();
|
|
1280
|
-
return [2 /*return*/, null];
|
|
1281
|
-
case 5:
|
|
1282
|
-
if (!(isLogin == null)) return [3 /*break*/, 12];
|
|
1283
|
-
_c.label = 6;
|
|
1284
|
-
case 6:
|
|
1285
|
-
_c.trys.push([6, 11, , 12]);
|
|
1286
|
-
this.publishEvent(eventNames.syncTokensAsync_begin, {});
|
|
1287
|
-
return [4 /*yield*/, this.silentLoginAsync({ prompt: "none" })];
|
|
1288
|
-
case 7:
|
|
1289
|
-
silent_token_response = _c.sent();
|
|
1290
|
-
if (!(silent_token_response && silent_token_response.tokens)) return [3 /*break*/, 9];
|
|
1291
|
-
_a = this;
|
|
1292
|
-
return [4 /*yield*/, setTokensAsync(serviceWorker, silent_token_response.tokens)];
|
|
1293
|
-
case 8:
|
|
1294
|
-
_a.tokens = _c.sent();
|
|
1295
|
-
this.publishEvent(eventNames.syncTokensAsync_end, {});
|
|
1296
|
-
return [2 /*return*/, this.tokens];
|
|
1297
|
-
case 9:
|
|
1298
|
-
this.publishEvent(eventNames.syncTokensAsync_error, { message: "no token found in result" });
|
|
1299
|
-
if (this.timeoutId) {
|
|
1300
|
-
timer_1.default.clearTimeout(this.timeoutId);
|
|
1301
|
-
this.timeoutId = null;
|
|
1302
|
-
}
|
|
1303
|
-
this.publishEvent(eventNames.syncTokensAsync_end, {});
|
|
1304
|
-
return [2 /*return*/, null];
|
|
1305
|
-
case 10: return [3 /*break*/, 12];
|
|
1306
|
-
case 11:
|
|
1307
|
-
exceptionSilent_2 = _c.sent();
|
|
1308
|
-
console.error(exceptionSilent_2);
|
|
1309
|
-
this.publishEvent(eventNames.syncTokensAsync_error, exceptionSilent_2);
|
|
1310
|
-
if (this.timeoutId) {
|
|
1311
|
-
timer_1.default.clearTimeout(this.timeoutId);
|
|
1312
|
-
this.timeoutId = null;
|
|
1313
|
-
}
|
|
1314
|
-
this.publishEvent(eventNames.syncTokensAsync_end, {});
|
|
1315
|
-
return [2 /*return*/, null];
|
|
1316
|
-
case 12: return [3 /*break*/, 16];
|
|
1317
|
-
case 13:
|
|
1318
|
-
session = (0, initSession_1.initSession)(this.configurationName, configuration.redirect_uri, (_b = configuration.storage) !== null && _b !== void 0 ? _b : sessionStorage);
|
|
1319
|
-
return [4 /*yield*/, session.initAsync()];
|
|
1320
|
-
case 14:
|
|
1321
|
-
tokens = (_c.sent()).tokens;
|
|
1322
|
-
if (!!tokens) return [3 /*break*/, 16];
|
|
1323
|
-
this.publishEvent(eventNames.logout_from_another_tab, {});
|
|
1324
|
-
return [4 /*yield*/, this.destroyAsync()];
|
|
1325
|
-
case 15:
|
|
1326
|
-
_c.sent();
|
|
1327
|
-
return [2 /*return*/, null];
|
|
1328
|
-
case 16: return [2 /*return*/, this.tokens];
|
|
1209
|
+
var oidcServerConfiguration, serviceWorker, _b, status_2, tokens, timeLeft_1, status_3, session, _c, tokens, status_4, timeLeft_2, status_5, timeLeft, status;
|
|
1210
|
+
return __generator(this, function (_d) {
|
|
1211
|
+
switch (_d.label) {
|
|
1212
|
+
case 0:
|
|
1213
|
+
// 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)
|
|
1214
|
+
//const configuration = this.configuration;
|
|
1215
|
+
if (!currentTokens) {
|
|
1216
|
+
return [2 /*return*/, { tokens: null, status: "NOT_CONNECTED" }];
|
|
1329
1217
|
}
|
|
1330
|
-
|
|
1331
|
-
|
|
1332
|
-
|
|
1333
|
-
|
|
1218
|
+
return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
|
|
1219
|
+
case 1:
|
|
1220
|
+
oidcServerConfiguration = _d.sent();
|
|
1221
|
+
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, configurationName)];
|
|
1222
|
+
case 2:
|
|
1223
|
+
serviceWorker = _d.sent();
|
|
1224
|
+
if (!serviceWorker) return [3 /*break*/, 4];
|
|
1225
|
+
return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "syncTokensAsync")];
|
|
1226
|
+
case 3:
|
|
1227
|
+
_b = _d.sent(), status_2 = _b.status, tokens = _b.tokens;
|
|
1228
|
+
if (status_2 == "LOGGED_OUT") {
|
|
1229
|
+
return [2 /*return*/, { tokens: null, status: "LOGOUT_FROM_ANOTHER_TAB" }];
|
|
1230
|
+
}
|
|
1231
|
+
else if (status_2 == "SESSIONS_LOST") {
|
|
1232
|
+
return [2 /*return*/, { tokens: null, status: "SESSIONS_LOST" }];
|
|
1233
|
+
}
|
|
1234
|
+
else if (!status_2 || !tokens) {
|
|
1235
|
+
return [2 /*return*/, { tokens: null, status: "REQUIRE_SYNC_TOKENS" }];
|
|
1236
|
+
}
|
|
1237
|
+
else if (tokens.issuedAt !== currentTokens.issuedAt) {
|
|
1238
|
+
timeLeft_1 = (0, parseTokens_1.computeTimeLeft)(configuration.refresh_time_before_tokens_expiration_in_second, tokens.expiresAt);
|
|
1239
|
+
status_3 = (timeLeft_1 > 0) ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID";
|
|
1240
|
+
return [2 /*return*/, { tokens: tokens, status: status_3 }];
|
|
1241
|
+
}
|
|
1242
|
+
return [3 /*break*/, 6];
|
|
1243
|
+
case 4:
|
|
1244
|
+
session = (0, initSession_1.initSession)(configurationName, configuration.redirect_uri, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
|
|
1245
|
+
return [4 /*yield*/, session.initAsync()];
|
|
1246
|
+
case 5:
|
|
1247
|
+
_c = _d.sent(), tokens = _c.tokens, status_4 = _c.status;
|
|
1248
|
+
if (!tokens) {
|
|
1249
|
+
return [2 /*return*/, { tokens: null, status: "LOGOUT_FROM_ANOTHER_TAB" }];
|
|
1250
|
+
}
|
|
1251
|
+
else if (status_4 == "SESSIONS_LOST") {
|
|
1252
|
+
return [2 /*return*/, { tokens: null, status: "SESSIONS_LOST" }];
|
|
1253
|
+
}
|
|
1254
|
+
else if (tokens.issuedAt !== currentTokens.issuedAt) {
|
|
1255
|
+
timeLeft_2 = (0, parseTokens_1.computeTimeLeft)(configuration.refresh_time_before_tokens_expiration_in_second, tokens.expiresAt);
|
|
1256
|
+
status_5 = (timeLeft_2 > 0) ? "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID" : "TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_INVALID";
|
|
1257
|
+
return [2 /*return*/, { tokens: tokens, status: status_5 }];
|
|
1258
|
+
}
|
|
1259
|
+
_d.label = 6;
|
|
1260
|
+
case 6:
|
|
1261
|
+
timeLeft = (0, parseTokens_1.computeTimeLeft)(configuration.refresh_time_before_tokens_expiration_in_second, currentTokens.expiresAt);
|
|
1262
|
+
status = (timeLeft > 0) ? "TOKENS_VALID" : "TOKENS_INVALID";
|
|
1263
|
+
return [2 /*return*/, { tokens: currentTokens, status: status }];
|
|
1334
1264
|
}
|
|
1335
|
-
this.syncTokensAsyncPromise = localSyncTokensAsync().then(function (result) {
|
|
1336
|
-
if (_this.syncTokensAsyncPromise) {
|
|
1337
|
-
_this.syncTokensAsyncPromise = null;
|
|
1338
|
-
}
|
|
1339
|
-
return result;
|
|
1340
|
-
});
|
|
1341
|
-
return [2 /*return*/, this.syncTokensAsyncPromise];
|
|
1342
1265
|
});
|
|
1343
1266
|
});
|
|
1344
1267
|
};
|
|
@@ -1356,7 +1279,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1356
1279
|
Oidc.prototype.userInfoAsync = function () {
|
|
1357
1280
|
return userInfoAsync(this);
|
|
1358
1281
|
};
|
|
1359
|
-
Oidc.prototype.destroyAsync = function () {
|
|
1282
|
+
Oidc.prototype.destroyAsync = function (status) {
|
|
1360
1283
|
return __awaiter(this, void 0, void 0, function () {
|
|
1361
1284
|
return __generator(this, function (_a) {
|
|
1362
1285
|
switch (_a.label) {
|
|
@@ -1367,37 +1290,68 @@ var Oidc = /** @class */ (function () {
|
|
|
1367
1290
|
this.checkSessionIFrame.stop();
|
|
1368
1291
|
}
|
|
1369
1292
|
if (!this.serviceWorker) return [3 /*break*/, 2];
|
|
1370
|
-
return [4 /*yield*/, this.serviceWorker.clearAsync()];
|
|
1293
|
+
return [4 /*yield*/, this.serviceWorker.clearAsync(status)];
|
|
1371
1294
|
case 1:
|
|
1372
1295
|
_a.sent();
|
|
1373
1296
|
_a.label = 2;
|
|
1374
1297
|
case 2:
|
|
1375
1298
|
if (!this.session) return [3 /*break*/, 4];
|
|
1376
|
-
return [4 /*yield*/, this.session.clearAsync()];
|
|
1299
|
+
return [4 /*yield*/, this.session.clearAsync(status)];
|
|
1377
1300
|
case 3:
|
|
1378
1301
|
_a.sent();
|
|
1379
1302
|
_a.label = 4;
|
|
1380
1303
|
case 4:
|
|
1381
1304
|
this.tokens = null;
|
|
1382
1305
|
this.userInfo = null;
|
|
1383
|
-
this.events = [];
|
|
1384
1306
|
return [2 /*return*/];
|
|
1385
1307
|
}
|
|
1386
1308
|
});
|
|
1387
1309
|
});
|
|
1388
1310
|
};
|
|
1311
|
+
Oidc.prototype.logoutSameTabAsync = function (clientId, sub) {
|
|
1312
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1313
|
+
return __generator(this, function (_a) {
|
|
1314
|
+
switch (_a.label) {
|
|
1315
|
+
case 0:
|
|
1316
|
+
if (!(this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub)) return [3 /*break*/, 2];
|
|
1317
|
+
this.publishEvent(eventNames.logout_from_same_tab, { "message": sub });
|
|
1318
|
+
return [4 /*yield*/, this.destroyAsync("LOGGED_OUT")];
|
|
1319
|
+
case 1:
|
|
1320
|
+
_a.sent();
|
|
1321
|
+
_a.label = 2;
|
|
1322
|
+
case 2: return [2 /*return*/];
|
|
1323
|
+
}
|
|
1324
|
+
});
|
|
1325
|
+
});
|
|
1326
|
+
};
|
|
1327
|
+
Oidc.prototype.logoutOtherTabAsync = function (clientId, sub) {
|
|
1328
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
1329
|
+
return __generator(this, function (_a) {
|
|
1330
|
+
switch (_a.label) {
|
|
1331
|
+
case 0:
|
|
1332
|
+
if (!(this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub)) return [3 /*break*/, 2];
|
|
1333
|
+
return [4 /*yield*/, this.destroyAsync("LOGGED_OUT")];
|
|
1334
|
+
case 1:
|
|
1335
|
+
_a.sent();
|
|
1336
|
+
this.publishEvent(eventNames.logout_from_another_tab, { message: "SessionMonitor", "sub": sub });
|
|
1337
|
+
_a.label = 2;
|
|
1338
|
+
case 2: return [2 /*return*/];
|
|
1339
|
+
}
|
|
1340
|
+
});
|
|
1341
|
+
});
|
|
1342
|
+
};
|
|
1389
1343
|
Oidc.prototype.logoutAsync = function (callbackPathOrUrl, extras) {
|
|
1390
1344
|
if (callbackPathOrUrl === void 0) { callbackPathOrUrl = undefined; }
|
|
1391
1345
|
if (extras === void 0) { extras = null; }
|
|
1392
1346
|
return __awaiter(this, void 0, void 0, function () {
|
|
1393
|
-
var configuration, oidcServerConfiguration, path, isUri, url, idToken,
|
|
1394
|
-
return __generator(this, function (
|
|
1395
|
-
switch (
|
|
1347
|
+
var configuration, oidcServerConfiguration, path, isUri, url, idToken, sub, _i, _a, _b, key, oidc, extraQueryString, _c, _d, _e, key, value;
|
|
1348
|
+
return __generator(this, function (_f) {
|
|
1349
|
+
switch (_f.label) {
|
|
1396
1350
|
case 0:
|
|
1397
1351
|
configuration = this.configuration;
|
|
1398
1352
|
return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
|
|
1399
1353
|
case 1:
|
|
1400
|
-
oidcServerConfiguration =
|
|
1354
|
+
oidcServerConfiguration = _f.sent();
|
|
1401
1355
|
if (callbackPathOrUrl && (typeof callbackPathOrUrl !== 'string')) {
|
|
1402
1356
|
callbackPathOrUrl = undefined;
|
|
1403
1357
|
console.warn('callbackPathOrUrl path is not a string');
|
|
@@ -1409,14 +1363,31 @@ var Oidc = /** @class */ (function () {
|
|
|
1409
1363
|
}
|
|
1410
1364
|
url = isUri ? callbackPathOrUrl : window.location.origin + path;
|
|
1411
1365
|
idToken = this.tokens ? this.tokens.idToken : "";
|
|
1412
|
-
|
|
1366
|
+
sub = this.tokens && this.tokens.idTokenPayload ? this.tokens.idTokenPayload.sub : null;
|
|
1367
|
+
return [4 /*yield*/, this.destroyAsync("LOGGED_OUT")];
|
|
1413
1368
|
case 2:
|
|
1414
|
-
|
|
1369
|
+
_f.sent();
|
|
1370
|
+
_i = 0, _a = Object.entries(oidcDatabase);
|
|
1371
|
+
_f.label = 3;
|
|
1372
|
+
case 3:
|
|
1373
|
+
if (!(_i < _a.length)) return [3 /*break*/, 6];
|
|
1374
|
+
_b = _a[_i], key = _b[0], oidc = _b[1];
|
|
1375
|
+
if (!(oidc !== this)) return [3 /*break*/, 5];
|
|
1376
|
+
// @ts-ignore
|
|
1377
|
+
return [4 /*yield*/, oidc.logoutSameTabAsync(this.configuration.client_id, sub)];
|
|
1378
|
+
case 4:
|
|
1379
|
+
// @ts-ignore
|
|
1380
|
+
_f.sent();
|
|
1381
|
+
_f.label = 5;
|
|
1382
|
+
case 5:
|
|
1383
|
+
_i++;
|
|
1384
|
+
return [3 /*break*/, 3];
|
|
1385
|
+
case 6:
|
|
1415
1386
|
if (oidcServerConfiguration.endSessionEndpoint) {
|
|
1416
1387
|
extraQueryString = "";
|
|
1417
1388
|
if (extras) {
|
|
1418
|
-
for (
|
|
1419
|
-
|
|
1389
|
+
for (_c = 0, _d = Object.entries(extras); _c < _d.length; _c++) {
|
|
1390
|
+
_e = _d[_c], key = _e[0], value = _e[1];
|
|
1420
1391
|
extraQueryString += "&".concat(key, "=").concat(encodeURIComponent(value));
|
|
1421
1392
|
}
|
|
1422
1393
|
}
|