@axa-fr/react-oidc 6.0.0-alpha9 → 6.0.0-beta10
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 +20 -11
- package/dist/OidcProvider.d.ts +2 -3
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +5 -4
- package/dist/OidcProvider.js.map +1 -1
- package/dist/OidcServiceWorker.js +21 -4
- package/dist/OidcTrustedDomains.js +7 -2
- package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
- package/dist/core/default-component/SilentCallback.component.js +5 -19
- package/dist/core/default-component/SilentCallback.component.js.map +1 -1
- package/dist/core/default-component/SilentLogin.component.d.ts +4 -0
- package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -0
- package/dist/core/default-component/{SilentSignin.component.js → SilentLogin.component.js} +3 -3
- package/dist/core/default-component/SilentLogin.component.js.map +1 -0
- package/dist/core/routes/OidcRoutes.d.ts +1 -1
- package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
- package/dist/core/routes/OidcRoutes.js +5 -8
- package/dist/core/routes/OidcRoutes.js.map +1 -1
- package/dist/vanilla/checkSessionIFrame.d.ts +6 -6
- package/dist/vanilla/checkSessionIFrame.d.ts.map +1 -1
- package/dist/vanilla/checkSessionIFrame.js +1 -1
- package/dist/vanilla/checkSessionIFrame.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +12 -12
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +342 -236
- package/dist/vanilla/oidc.js.map +1 -1
- package/package.json +2 -2
- package/src/oidc/OidcProvider.tsx +9 -10
- package/src/oidc/core/default-component/SilentCallback.component.tsx +1 -6
- package/src/oidc/core/default-component/{SilentSignin.component.tsx → SilentLogin.component.tsx} +2 -2
- package/src/oidc/core/routes/OidcRoutes.tsx +6 -10
- package/src/oidc/vanilla/OidcServiceWorker.js +21 -4
- package/src/oidc/vanilla/OidcTrustedDomains.js +7 -2
- package/src/oidc/vanilla/checkSessionIFrame.ts +7 -7
- package/src/oidc/vanilla/oidc.ts +238 -195
- 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/dist/core/default-component/SilentSignin.component.d.ts +0 -4
- package/dist/core/default-component/SilentSignin.component.d.ts.map +0 -1
- package/dist/core/default-component/SilentSignin.component.js.map +0 -1
- package/src/App.css +0 -38
- package/src/App.specold.tsx +0 -46
- package/src/App.tsx +0 -96
- package/src/FetchUser.tsx +0 -53
- package/src/Home.tsx +0 -22
- package/src/MultiAuth.tsx +0 -116
- package/src/Profile.tsx +0 -77
- package/src/configurations.ts +0 -70
- package/src/index.css +0 -13
- package/src/index.tsx +0 -9
- package/src/logo.svg +0 -7
- package/src/oidc/core/default-component/ServiceWorkerInstall.component.tsx +0 -60
- package/src/override/AuthenticateError.component.tsx +0 -14
- package/src/override/Authenticating.component.tsx +0 -14
- package/src/override/Callback.component.tsx +0 -13
- package/src/override/Loading.component.tsx +0 -13
- package/src/override/ServiceWorkerNotSupported.component.tsx +0 -15
- package/src/override/SessionLost.component.tsx +0 -21
- package/src/override/style.ts +0 -10
- package/src/setupTests.js +0 -5
package/dist/vanilla/oidc.js
CHANGED
|
@@ -74,26 +74,76 @@ 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 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, currentTimeUnixSecond;
|
|
79
|
+
return __generator(this, function (_c) {
|
|
80
|
+
switch (_c.label) {
|
|
81
|
+
case 0:
|
|
82
|
+
for (_i = 0, _a = Object.entries(extras); _i < _a.length; _i++) {
|
|
83
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
84
|
+
if (details[key] === undefined) {
|
|
85
|
+
details[key] = value;
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
formBody = [];
|
|
89
|
+
for (property in details) {
|
|
90
|
+
encodedKey = encodeURIComponent(property);
|
|
91
|
+
encodedValue = encodeURIComponent(details[property]);
|
|
92
|
+
formBody.push("".concat(encodedKey, "=").concat(encodedValue));
|
|
93
|
+
}
|
|
94
|
+
formBodyString = formBody.join("&");
|
|
95
|
+
return [4 /*yield*/, internalFetch(url, {
|
|
96
|
+
method: 'POST',
|
|
97
|
+
headers: {
|
|
98
|
+
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
99
|
+
},
|
|
100
|
+
body: formBodyString,
|
|
101
|
+
})];
|
|
102
|
+
case 1:
|
|
103
|
+
response = _c.sent();
|
|
104
|
+
if (response.status !== 200) {
|
|
105
|
+
return [2 /*return*/, { success: false, status: response.status }];
|
|
106
|
+
}
|
|
107
|
+
return [4 /*yield*/, response.json()];
|
|
108
|
+
case 2:
|
|
109
|
+
tokens = _c.sent();
|
|
110
|
+
if (!tokens.issued_at) {
|
|
111
|
+
currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
112
|
+
tokens.issued_at = currentTimeUnixSecond;
|
|
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
|
+
}
|
|
124
|
+
}];
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
}); };
|
|
77
128
|
var internalFetch = function (url, headers, numberRetry) {
|
|
78
129
|
if (numberRetry === void 0) { numberRetry = 0; }
|
|
79
130
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
-
var response, e_1;
|
|
131
|
+
var response, controller_1, e_1;
|
|
81
132
|
return __generator(this, function (_a) {
|
|
82
133
|
switch (_a.label) {
|
|
83
134
|
case 0:
|
|
84
135
|
_a.trys.push([0, 2, , 8]);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
])];
|
|
136
|
+
controller_1 = new AbortController();
|
|
137
|
+
setTimeout(function () { return controller_1.abort(); }, 10000);
|
|
138
|
+
return [4 /*yield*/, fetch(url, __assign(__assign({}, headers), { signal: controller_1.signal }))];
|
|
89
139
|
case 1:
|
|
90
140
|
response = _a.sent();
|
|
91
141
|
return [3 /*break*/, 8];
|
|
92
142
|
case 2:
|
|
93
143
|
e_1 = _a.sent();
|
|
94
|
-
if (!(e_1.message === '
|
|
95
|
-
|| e_1.message === 'Network request failed'
|
|
96
|
-
if (!(numberRetry <=
|
|
144
|
+
if (!(e_1.message === 'AbortError'
|
|
145
|
+
|| e_1.message === 'Network request failed')) return [3 /*break*/, 6];
|
|
146
|
+
if (!(numberRetry <= 1)) return [3 /*break*/, 4];
|
|
97
147
|
return [4 /*yield*/, internalFetch(url, headers, numberRetry + 1)];
|
|
98
148
|
case 3: return [2 /*return*/, _a.sent()];
|
|
99
149
|
case 4: throw e_1;
|
|
@@ -173,7 +223,7 @@ var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
|
|
|
173
223
|
var _a;
|
|
174
224
|
var refreshTimeBeforeTokensExpirationInSecond = (_a = oidc.configuration.refresh_time_before_tokens_expiration_in_second) !== null && _a !== void 0 ? _a : 60;
|
|
175
225
|
return timer_1.default.setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
176
|
-
var currentTimeUnixSecond, timeInfo, tokens, _a;
|
|
226
|
+
var currentTimeUnixSecond, timeInfo, tokens, _a, tokens;
|
|
177
227
|
return __generator(this, function (_b) {
|
|
178
228
|
switch (_b.label) {
|
|
179
229
|
case 0:
|
|
@@ -208,9 +258,9 @@ var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
|
|
|
208
258
|
return [3 /*break*/, 7];
|
|
209
259
|
case 5: return [4 /*yield*/, oidc.syncTokensAsync()];
|
|
210
260
|
case 6:
|
|
211
|
-
_b.sent();
|
|
212
|
-
if (oidc.timeoutId) {
|
|
213
|
-
oidc.timeoutId = autoRenewTokens(oidc, refreshToken, expiresAt);
|
|
261
|
+
tokens = _b.sent();
|
|
262
|
+
if (tokens && oidc.timeoutId) {
|
|
263
|
+
oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, tokens.expiresAt);
|
|
214
264
|
}
|
|
215
265
|
_b.label = 7;
|
|
216
266
|
case 7: return [2 /*return*/];
|
|
@@ -253,7 +303,7 @@ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, f
|
|
|
253
303
|
case 0: return [4 /*yield*/, fetch(url, {
|
|
254
304
|
headers: {
|
|
255
305
|
authorization: "Bearer ".concat(accessToken),
|
|
256
|
-
credentials: '
|
|
306
|
+
credentials: 'include'
|
|
257
307
|
}
|
|
258
308
|
})];
|
|
259
309
|
case 1:
|
|
@@ -274,7 +324,7 @@ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, f
|
|
|
274
324
|
});
|
|
275
325
|
}); };
|
|
276
326
|
var setTokensAsync = function (serviceWorker, tokens) { return __awaiter(void 0, void 0, void 0, function () {
|
|
277
|
-
var accessTokenPayload, _idTokenPayload, expiresAt;
|
|
327
|
+
var accessTokenPayload, _idTokenPayload, idTokenExipreAt, accessTokenExpiresAt, expiresAt;
|
|
278
328
|
return __generator(this, function (_a) {
|
|
279
329
|
switch (_a.label) {
|
|
280
330
|
case 0:
|
|
@@ -296,7 +346,9 @@ var setTokensAsync = function (serviceWorker, tokens) { return __awaiter(void 0,
|
|
|
296
346
|
_a.label = 6;
|
|
297
347
|
case 6:
|
|
298
348
|
_idTokenPayload = idTokenPayload(tokens.idToken);
|
|
299
|
-
|
|
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;
|
|
300
352
|
return [2 /*return*/, __assign(__assign({}, tokens), { idTokenPayload: _idTokenPayload, accessTokenPayload: accessTokenPayload, expiresAt: expiresAt })];
|
|
301
353
|
}
|
|
302
354
|
});
|
|
@@ -320,10 +372,10 @@ var eventNames = {
|
|
|
320
372
|
tryKeepExistingSessionAsync_begin: "tryKeepExistingSessionAsync_begin",
|
|
321
373
|
tryKeepExistingSessionAsync_end: "tryKeepExistingSessionAsync_end",
|
|
322
374
|
tryKeepExistingSessionAsync_error: "tryKeepExistingSessionAsync_error",
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
375
|
+
silentLoginAsync_begin: "silentLoginAsync_begin",
|
|
376
|
+
silentLoginAsync: "silentLoginAsync",
|
|
377
|
+
silentLoginAsync_end: "silentLoginAsync_end",
|
|
378
|
+
silentLoginAsync_error: "silentLoginAsync_error",
|
|
327
379
|
syncTokensAsync_begin: "syncTokensAsync_begin",
|
|
328
380
|
syncTokensAsync_end: "syncTokensAsync_end",
|
|
329
381
|
syncTokensAsync_error: "syncTokensAsync_error"
|
|
@@ -331,23 +383,28 @@ var eventNames = {
|
|
|
331
383
|
var getRandomInt = function (max) {
|
|
332
384
|
return Math.floor(Math.random() * max);
|
|
333
385
|
};
|
|
334
|
-
var WELL_KNOWN_PATH = '.well-known';
|
|
335
|
-
var OPENID_CONFIGURATION = 'openid-configuration';
|
|
336
386
|
var oneHourSecond = 60 * 60;
|
|
337
|
-
var
|
|
387
|
+
var fetchFromIssuerCache = null;
|
|
388
|
+
var fetchFromIssuer = function (openIdIssuerUrl, timeCacheSecond, storage) {
|
|
338
389
|
if (timeCacheSecond === void 0) { timeCacheSecond = oneHourSecond; }
|
|
390
|
+
if (storage === void 0) { storage = window.sessionStorage; }
|
|
339
391
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
340
|
-
var fullUrl, localStorageKey, cacheJson, oneHourMinisecond, response, result;
|
|
392
|
+
var fullUrl, localStorageKey, cacheJson, oneHourMinisecond, response, result, timestamp;
|
|
341
393
|
return __generator(this, function (_a) {
|
|
342
394
|
switch (_a.label) {
|
|
343
395
|
case 0:
|
|
344
|
-
fullUrl = "".concat(openIdIssuerUrl, "/")
|
|
396
|
+
fullUrl = "".concat(openIdIssuerUrl, "/.well-known/openid-configuration");
|
|
345
397
|
localStorageKey = "oidc.server:".concat(openIdIssuerUrl);
|
|
346
|
-
|
|
398
|
+
if (!fetchFromIssuerCache && storage) {
|
|
399
|
+
cacheJson = storage.getItem(localStorageKey);
|
|
400
|
+
if (cacheJson) {
|
|
401
|
+
fetchFromIssuerCache = JSON.parse(cacheJson);
|
|
402
|
+
}
|
|
403
|
+
}
|
|
347
404
|
oneHourMinisecond = 1000 * timeCacheSecond;
|
|
348
405
|
// @ts-ignore
|
|
349
|
-
if (
|
|
350
|
-
return [2 /*return*/, new OidcAuthorizationServiceConfiguration(
|
|
406
|
+
if (fetchFromIssuerCache && (fetchFromIssuerCache.timestamp + oneHourMinisecond) > Date.now()) {
|
|
407
|
+
return [2 /*return*/, new OidcAuthorizationServiceConfiguration(fetchFromIssuerCache.result)];
|
|
351
408
|
}
|
|
352
409
|
return [4 /*yield*/, fetch(fullUrl)];
|
|
353
410
|
case 1:
|
|
@@ -358,7 +415,11 @@ var fetchFromIssuer = function (openIdIssuerUrl, timeCacheSecond) {
|
|
|
358
415
|
return [4 /*yield*/, response.json()];
|
|
359
416
|
case 2:
|
|
360
417
|
result = _a.sent();
|
|
361
|
-
|
|
418
|
+
timestamp = Date.now();
|
|
419
|
+
fetchFromIssuerCache = { result: result, timestamp: timestamp };
|
|
420
|
+
if (storage) {
|
|
421
|
+
storage.setItem(localStorageKey, JSON.stringify({ result: result, timestamp: timestamp }));
|
|
422
|
+
}
|
|
362
423
|
return [2 /*return*/, new OidcAuthorizationServiceConfiguration(result)];
|
|
363
424
|
}
|
|
364
425
|
});
|
|
@@ -382,13 +443,16 @@ var buildQueries = function (extras) {
|
|
|
382
443
|
var Oidc = /** @class */ (function () {
|
|
383
444
|
function Oidc(configuration, configurationName) {
|
|
384
445
|
if (configurationName === void 0) { configurationName = "default"; }
|
|
385
|
-
this.initAsyncPromise = null;
|
|
386
446
|
this.tryKeepExistingSessionPromise = null;
|
|
387
447
|
this.loginPromise = null;
|
|
388
448
|
this.loginCallbackPromise = null;
|
|
389
449
|
this.syncTokensAsyncPromise = null;
|
|
390
450
|
this.loginCallbackWithAutoTokensRenewPromise = null;
|
|
391
|
-
|
|
451
|
+
var silent_login_uri = configuration.silent_login_uri;
|
|
452
|
+
if (configuration.silent_redirect_uri && !configuration.silent_login_uri) {
|
|
453
|
+
silent_login_uri = "".concat(configuration.silent_redirect_uri.replace("-callback", "").replace("callback", ""), "-login");
|
|
454
|
+
}
|
|
455
|
+
this.configuration = __assign(__assign({}, configuration), { silent_login_uri: silent_login_uri });
|
|
392
456
|
this.configurationName = configurationName;
|
|
393
457
|
this.tokens = null;
|
|
394
458
|
this.userInfo = null;
|
|
@@ -405,6 +469,8 @@ var Oidc = /** @class */ (function () {
|
|
|
405
469
|
this.removeEventSubscription.bind(this);
|
|
406
470
|
this.publishEvent.bind(this);
|
|
407
471
|
this.destroyAsync.bind(this);
|
|
472
|
+
this.logoutAsync.bind(this);
|
|
473
|
+
this.initAsync(this.configuration.authority, this.configuration.authority_configuration);
|
|
408
474
|
}
|
|
409
475
|
Oidc.prototype.subscriveEvents = function (func) {
|
|
410
476
|
var id = getRandomInt(9999999999999).toString();
|
|
@@ -432,28 +498,50 @@ var Oidc = /** @class */ (function () {
|
|
|
432
498
|
}
|
|
433
499
|
return oidcDatabase[name];
|
|
434
500
|
};
|
|
435
|
-
Oidc.prototype.
|
|
436
|
-
if (this.configuration.silent_redirect_uri) {
|
|
501
|
+
Oidc.prototype._silentLoginCallbackFromIFrame = function () {
|
|
502
|
+
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
437
503
|
var queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
|
|
438
504
|
window.top.postMessage("".concat(this.configurationName, "_oidc_tokens:").concat(JSON.stringify({ tokens: this.tokens, sessionState: queryParams.session_state })), window.location.origin);
|
|
439
505
|
}
|
|
440
506
|
};
|
|
441
|
-
Oidc.prototype.
|
|
442
|
-
if (this.configuration.silent_redirect_uri) {
|
|
507
|
+
Oidc.prototype._silentLoginErrorCallbackFromIFrame = function () {
|
|
508
|
+
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
443
509
|
var queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
|
|
444
510
|
window.top.postMessage("".concat(this.configurationName, "_oidc_error:").concat(JSON.stringify({ error: queryParams.error })), window.location.origin);
|
|
445
511
|
}
|
|
446
512
|
};
|
|
447
|
-
Oidc.prototype.
|
|
513
|
+
Oidc.prototype.silentLoginCallBackAsync = function () {
|
|
514
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
515
|
+
var error_1;
|
|
516
|
+
return __generator(this, function (_a) {
|
|
517
|
+
switch (_a.label) {
|
|
518
|
+
case 0:
|
|
519
|
+
_a.trys.push([0, 2, , 3]);
|
|
520
|
+
return [4 /*yield*/, this.loginCallbackAsync(true)];
|
|
521
|
+
case 1:
|
|
522
|
+
_a.sent();
|
|
523
|
+
this._silentLoginCallbackFromIFrame();
|
|
524
|
+
return [3 /*break*/, 3];
|
|
525
|
+
case 2:
|
|
526
|
+
error_1 = _a.sent();
|
|
527
|
+
console.error(error_1);
|
|
528
|
+
this._silentLoginErrorCallbackFromIFrame();
|
|
529
|
+
return [3 /*break*/, 3];
|
|
530
|
+
case 3: return [2 /*return*/];
|
|
531
|
+
}
|
|
532
|
+
});
|
|
533
|
+
});
|
|
534
|
+
};
|
|
535
|
+
Oidc.prototype.silentLoginAsync = function (extras, state, scope) {
|
|
448
536
|
if (extras === void 0) { extras = null; }
|
|
449
537
|
if (state === void 0) { state = null; }
|
|
450
538
|
if (scope === void 0) { scope = null; }
|
|
451
539
|
return __awaiter(this, void 0, void 0, function () {
|
|
452
|
-
var configuration_1, queries, _i, _a, _b, key, value, link, idx, iFrameOrigin_1, iframe_1, self_1;
|
|
540
|
+
var numberTryOnline, configuration_1, queries, _i, _a, _b, key, value, link, idx, iFrameOrigin_1, iframe_1, self_1;
|
|
453
541
|
return __generator(this, function (_c) {
|
|
454
542
|
switch (_c.label) {
|
|
455
543
|
case 0:
|
|
456
|
-
if (!this.configuration.silent_redirect_uri || !this.configuration.
|
|
544
|
+
if (!this.configuration.silent_redirect_uri || !this.configuration.silent_login_uri) {
|
|
457
545
|
return [2 /*return*/, Promise.resolve(null)];
|
|
458
546
|
}
|
|
459
547
|
_c.label = 1;
|
|
@@ -462,11 +550,22 @@ var Oidc = /** @class */ (function () {
|
|
|
462
550
|
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
463
551
|
case 2:
|
|
464
552
|
_c.sent();
|
|
465
|
-
this.publishEvent(eventNames.
|
|
553
|
+
this.publishEvent(eventNames.silentLoginAsync, { message: "wait because document is hidden" });
|
|
466
554
|
return [3 /*break*/, 1];
|
|
467
555
|
case 3:
|
|
556
|
+
numberTryOnline = 6;
|
|
557
|
+
_c.label = 4;
|
|
558
|
+
case 4:
|
|
559
|
+
if (!(!navigator.onLine && numberTryOnline > 0)) return [3 /*break*/, 6];
|
|
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:
|
|
468
567
|
try {
|
|
469
|
-
this.publishEvent(eventNames.
|
|
568
|
+
this.publishEvent(eventNames.silentLoginAsync_begin, {});
|
|
470
569
|
configuration_1 = this.configuration;
|
|
471
570
|
queries = "";
|
|
472
571
|
if (state) {
|
|
@@ -492,7 +591,7 @@ var Oidc = /** @class */ (function () {
|
|
|
492
591
|
}
|
|
493
592
|
}
|
|
494
593
|
}
|
|
495
|
-
link = configuration_1.
|
|
594
|
+
link = configuration_1.silent_login_uri + queries;
|
|
496
595
|
idx = link.indexOf("/", link.indexOf("//") + 2);
|
|
497
596
|
iFrameOrigin_1 = link.substr(0, idx);
|
|
498
597
|
iframe_1 = document.createElement('iframe');
|
|
@@ -516,41 +615,41 @@ var Oidc = /** @class */ (function () {
|
|
|
516
615
|
if (!isResolved_1) {
|
|
517
616
|
if (data.startsWith(key)) {
|
|
518
617
|
var result = JSON.parse(e.data.replace(key, ''));
|
|
519
|
-
self_1.publishEvent(eventNames.
|
|
618
|
+
self_1.publishEvent(eventNames.silentLoginAsync_end, {});
|
|
520
619
|
iframe_1.remove();
|
|
521
620
|
isResolved_1 = true;
|
|
522
621
|
resolve(result);
|
|
523
622
|
}
|
|
524
623
|
else if (data.startsWith(key_error)) {
|
|
525
624
|
var result = JSON.parse(e.data.replace(key_error, ''));
|
|
526
|
-
self_1.publishEvent(eventNames.
|
|
625
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, result);
|
|
527
626
|
iframe_1.remove();
|
|
528
627
|
isResolved_1 = true;
|
|
529
|
-
reject(result);
|
|
628
|
+
reject(new Error("oidc_" + result.error));
|
|
530
629
|
}
|
|
531
630
|
}
|
|
532
631
|
}
|
|
533
632
|
}
|
|
534
633
|
};
|
|
535
|
-
var silentSigninTimeout = (_a = configuration_1.
|
|
634
|
+
var silentSigninTimeout = (_a = configuration_1.silent_login_timeout) !== null && _a !== void 0 ? _a : 12000;
|
|
536
635
|
setTimeout(function () {
|
|
537
636
|
if (!isResolved_1) {
|
|
538
|
-
self_1.publishEvent(eventNames.
|
|
637
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, { reason: "timeout" });
|
|
539
638
|
iframe_1.remove();
|
|
540
639
|
isResolved_1 = true;
|
|
541
|
-
reject("timeout");
|
|
640
|
+
reject(new Error("timeout"));
|
|
542
641
|
}
|
|
543
642
|
}, silentSigninTimeout);
|
|
544
643
|
}
|
|
545
644
|
catch (e) {
|
|
546
645
|
iframe_1.remove();
|
|
547
|
-
self_1.publishEvent(eventNames.
|
|
646
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
548
647
|
reject(e);
|
|
549
648
|
}
|
|
550
649
|
})];
|
|
551
650
|
}
|
|
552
651
|
catch (e) {
|
|
553
|
-
this.publishEvent(eventNames.
|
|
652
|
+
this.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
554
653
|
throw e;
|
|
555
654
|
}
|
|
556
655
|
return [2 /*return*/];
|
|
@@ -561,9 +660,9 @@ var Oidc = /** @class */ (function () {
|
|
|
561
660
|
Oidc.prototype.initAsync = function (authority, authorityConfiguration) {
|
|
562
661
|
var _a;
|
|
563
662
|
return __awaiter(this, void 0, void 0, function () {
|
|
564
|
-
var
|
|
565
|
-
return __generator(this, function (
|
|
566
|
-
switch (
|
|
663
|
+
var serviceWorker, storage, initAsyncPromise;
|
|
664
|
+
return __generator(this, function (_b) {
|
|
665
|
+
switch (_b.label) {
|
|
567
666
|
case 0:
|
|
568
667
|
if (authorityConfiguration != null) {
|
|
569
668
|
return [2 /*return*/, new OidcAuthorizationServiceConfiguration({
|
|
@@ -575,14 +674,14 @@ var Oidc = /** @class */ (function () {
|
|
|
575
674
|
check_session_iframe: authorityConfiguration.check_session_iframe,
|
|
576
675
|
})];
|
|
577
676
|
}
|
|
578
|
-
|
|
579
|
-
return [2 /*return*/, this.initAsyncPromise];
|
|
580
|
-
}
|
|
581
|
-
_b = this;
|
|
582
|
-
return [4 /*yield*/, fetchFromIssuer(authority, (_a = this.configuration.authority_time_cache_wellknowurl_in_second) !== null && _a !== void 0 ? _a : 60 * 60)];
|
|
677
|
+
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName)];
|
|
583
678
|
case 1:
|
|
584
|
-
|
|
585
|
-
|
|
679
|
+
serviceWorker = _b.sent();
|
|
680
|
+
storage = serviceWorker ? window.localStorage : null;
|
|
681
|
+
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];
|
|
586
685
|
}
|
|
587
686
|
});
|
|
588
687
|
});
|
|
@@ -627,7 +726,8 @@ var Oidc = /** @class */ (function () {
|
|
|
627
726
|
expiresIn: tokens.expires_in,
|
|
628
727
|
idToken: tokens.id_token,
|
|
629
728
|
scope: tokens.scope,
|
|
630
|
-
tokenType: tokens.token_type
|
|
729
|
+
tokenType: tokens.token_type,
|
|
730
|
+
issuedAt: tokens.issued_at
|
|
631
731
|
};
|
|
632
732
|
_a = this;
|
|
633
733
|
return [4 /*yield*/, setTokensAsync(serviceWorker, reformattedToken)];
|
|
@@ -639,8 +739,10 @@ var Oidc = /** @class */ (function () {
|
|
|
639
739
|
return [4 /*yield*/, serviceWorker.getSessionStateAsync()];
|
|
640
740
|
case 6:
|
|
641
741
|
sessionState = _d.sent();
|
|
742
|
+
// @ts-ignore
|
|
642
743
|
return [4 /*yield*/, this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState)];
|
|
643
744
|
case 7:
|
|
745
|
+
// @ts-ignore
|
|
644
746
|
_d.sent();
|
|
645
747
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
646
748
|
success: true,
|
|
@@ -675,8 +777,10 @@ var Oidc = /** @class */ (function () {
|
|
|
675
777
|
// @ts-ignore
|
|
676
778
|
this.timeoutId = autoRenewTokens(this, tokens.refreshToken, this.tokens.expiresAt);
|
|
677
779
|
sessionState = session.getSessionState();
|
|
780
|
+
// @ts-ignore
|
|
678
781
|
return [4 /*yield*/, this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState)];
|
|
679
782
|
case 12:
|
|
783
|
+
// @ts-ignore
|
|
680
784
|
_d.sent();
|
|
681
785
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
682
786
|
success: true,
|
|
@@ -800,7 +904,7 @@ var Oidc = /** @class */ (function () {
|
|
|
800
904
|
var _this = this;
|
|
801
905
|
return __generator(this, function (_a) {
|
|
802
906
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
803
|
-
if (_this.configuration.
|
|
907
|
+
if (_this.configuration.silent_login_uri && _this.configuration.silent_redirect_uri && _this.configuration.monitor_session && checkSessionIFrameUri && sessionState && !isSilentSignin) {
|
|
804
908
|
var checkSessionCallback = function () {
|
|
805
909
|
_this.checkSessionIFrame.stop();
|
|
806
910
|
if (_this.tokens === null) {
|
|
@@ -810,7 +914,7 @@ var Oidc = /** @class */ (function () {
|
|
|
810
914
|
var idToken = _this.tokens.idToken;
|
|
811
915
|
// @ts-ignore
|
|
812
916
|
var idTokenPayload = _this.tokens.idTokenPayload;
|
|
813
|
-
_this.
|
|
917
|
+
_this.silentLoginAsync({
|
|
814
918
|
prompt: "none",
|
|
815
919
|
id_token_hint: idToken,
|
|
816
920
|
scope: "openid"
|
|
@@ -999,6 +1103,7 @@ var Oidc = /** @class */ (function () {
|
|
|
999
1103
|
clearTimeout(timeoutId);
|
|
1000
1104
|
_this.timeoutId = null;
|
|
1001
1105
|
var loginParams_1 = getLoginParams(_this.configurationName, redirectUri_1);
|
|
1106
|
+
// @ts-ignore
|
|
1002
1107
|
_this.startCheckSessionAsync(oidcServerConfiguration_1.check_session_iframe, clientId_1, sessionState_2, isSilentSignin).then(function () {
|
|
1003
1108
|
_this.publishEvent(eventNames.loginCallbackAsync_end, {});
|
|
1004
1109
|
resolve({
|
|
@@ -1034,207 +1139,208 @@ var Oidc = /** @class */ (function () {
|
|
|
1034
1139
|
};
|
|
1035
1140
|
Oidc.prototype.refreshTokensAsync = function (refreshToken) {
|
|
1036
1141
|
return __awaiter(this, void 0, void 0, function () {
|
|
1037
|
-
var
|
|
1142
|
+
var localsilentLoginAsync, configuration, clientId, redirectUri, authority, extras, _i, _a, _b, key, value, oidcServerConfiguration, details, index, numberTryOnline, tokenResponse, exception_4;
|
|
1038
1143
|
var _this = this;
|
|
1039
1144
|
return __generator(this, function (_c) {
|
|
1040
1145
|
switch (_c.label) {
|
|
1041
1146
|
case 0:
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
return
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
}
|
|
1069
|
-
});
|
|
1147
|
+
localsilentLoginAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1148
|
+
var loginParams, silent_token_response, exceptionSilent_1;
|
|
1149
|
+
return __generator(this, function (_a) {
|
|
1150
|
+
switch (_a.label) {
|
|
1151
|
+
case 0:
|
|
1152
|
+
_a.trys.push([0, 2, , 3]);
|
|
1153
|
+
loginParams = getLoginParams(this.configurationName, configuration.redirect_uri);
|
|
1154
|
+
return [4 /*yield*/, this.silentLoginAsync(loginParams.extras, loginParams.state)];
|
|
1155
|
+
case 1:
|
|
1156
|
+
silent_token_response = _a.sent();
|
|
1157
|
+
if (silent_token_response) {
|
|
1158
|
+
return [2 /*return*/, silent_token_response.tokens];
|
|
1159
|
+
}
|
|
1160
|
+
return [3 /*break*/, 3];
|
|
1161
|
+
case 2:
|
|
1162
|
+
exceptionSilent_1 = _a.sent();
|
|
1163
|
+
console.error(exceptionSilent_1);
|
|
1164
|
+
return [3 /*break*/, 3];
|
|
1165
|
+
case 3:
|
|
1166
|
+
if (this.timeoutId) {
|
|
1167
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
1168
|
+
this.timeoutId = null;
|
|
1169
|
+
}
|
|
1170
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token and silent refresh failed" });
|
|
1171
|
+
return [2 /*return*/, null];
|
|
1172
|
+
}
|
|
1070
1173
|
});
|
|
1071
|
-
};
|
|
1072
|
-
_c.label = 1;
|
|
1073
|
-
case 1:
|
|
1074
|
-
_c.trys.push([1, 6, , 8]);
|
|
1075
|
-
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken });
|
|
1174
|
+
}); };
|
|
1076
1175
|
configuration = this.configuration;
|
|
1077
|
-
|
|
1078
|
-
|
|
1176
|
+
clientId = configuration.client_id;
|
|
1177
|
+
redirectUri = configuration.redirect_uri;
|
|
1079
1178
|
authority = configuration.authority;
|
|
1080
|
-
if (!!refreshToken) return [3 /*break*/,
|
|
1081
|
-
return [4 /*yield*/,
|
|
1082
|
-
case
|
|
1083
|
-
case
|
|
1084
|
-
|
|
1179
|
+
if (!!refreshToken) return [3 /*break*/, 2];
|
|
1180
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1181
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1182
|
+
case 2:
|
|
1183
|
+
extras = {};
|
|
1085
1184
|
if (configuration.token_request_extras) {
|
|
1086
1185
|
for (_i = 0, _a = Object.entries(configuration.token_request_extras); _i < _a.length; _i++) {
|
|
1087
1186
|
_b = _a[_i], key = _b[0], value = _b[1];
|
|
1088
|
-
|
|
1187
|
+
extras[key] = value;
|
|
1089
1188
|
}
|
|
1090
1189
|
}
|
|
1091
1190
|
return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
|
|
1092
|
-
case
|
|
1191
|
+
case 3:
|
|
1093
1192
|
oidcServerConfiguration = _c.sent();
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
|
|
1105
|
-
for (_i = 0, _a = Object.entries(extras_1); _i < _a.length; _i++) {
|
|
1106
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
1107
|
-
if (details[key] === undefined) {
|
|
1108
|
-
details[key] = value;
|
|
1109
|
-
}
|
|
1110
|
-
}
|
|
1111
|
-
formBody = [];
|
|
1112
|
-
for (property in details) {
|
|
1113
|
-
encodedKey = encodeURIComponent(property);
|
|
1114
|
-
encodedValue = encodeURIComponent(details[property]);
|
|
1115
|
-
formBody.push("".concat(encodedKey, "=").concat(encodedValue));
|
|
1116
|
-
}
|
|
1117
|
-
formBodyString = formBody.join("&");
|
|
1118
|
-
return [4 /*yield*/, internalFetch(url, {
|
|
1119
|
-
method: 'POST',
|
|
1120
|
-
headers: {
|
|
1121
|
-
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
1122
|
-
},
|
|
1123
|
-
body: formBodyString,
|
|
1124
|
-
})];
|
|
1125
|
-
case 1:
|
|
1126
|
-
response = _c.sent();
|
|
1127
|
-
if (response.status >= 299) {
|
|
1128
|
-
throw new Error("Error refreshing token");
|
|
1129
|
-
}
|
|
1130
|
-
return [4 /*yield*/, response.json()];
|
|
1131
|
-
case 2:
|
|
1132
|
-
result = _c.sent();
|
|
1133
|
-
return [2 /*return*/, {
|
|
1134
|
-
accessToken: result.access_token,
|
|
1135
|
-
expiresIn: result.expires_in,
|
|
1136
|
-
idToken: result.id_token,
|
|
1137
|
-
refreshToken: result.refresh_token,
|
|
1138
|
-
scope: result.scope,
|
|
1139
|
-
tokenType: result.token_type,
|
|
1140
|
-
}];
|
|
1141
|
-
}
|
|
1142
|
-
});
|
|
1143
|
-
}); };
|
|
1144
|
-
return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint)];
|
|
1193
|
+
details = {
|
|
1194
|
+
client_id: clientId,
|
|
1195
|
+
redirect_uri: redirectUri,
|
|
1196
|
+
grant_type: appauth_1.GRANT_TYPE_REFRESH_TOKEN,
|
|
1197
|
+
refresh_token: refreshToken,
|
|
1198
|
+
};
|
|
1199
|
+
index = 0;
|
|
1200
|
+
_c.label = 4;
|
|
1201
|
+
case 4:
|
|
1202
|
+
if (!(index <= 4)) return [3 /*break*/, 18];
|
|
1203
|
+
_c.label = 5;
|
|
1145
1204
|
case 5:
|
|
1146
|
-
|
|
1147
|
-
this.publishEvent(eventNames.
|
|
1148
|
-
return [
|
|
1205
|
+
_c.trys.push([5, 16, , 17]);
|
|
1206
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, tryNumber: index });
|
|
1207
|
+
if (!(index > 1)) return [3 /*break*/, 11];
|
|
1208
|
+
_c.label = 6;
|
|
1149
1209
|
case 6:
|
|
1210
|
+
if (!document.hidden) return [3 /*break*/, 8];
|
|
1211
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1212
|
+
case 7:
|
|
1213
|
+
_c.sent();
|
|
1214
|
+
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because document is hidden" });
|
|
1215
|
+
return [3 /*break*/, 6];
|
|
1216
|
+
case 8:
|
|
1217
|
+
numberTryOnline = 6;
|
|
1218
|
+
_c.label = 9;
|
|
1219
|
+
case 9:
|
|
1220
|
+
if (!(!navigator.onLine && numberTryOnline > 0)) return [3 /*break*/, 11];
|
|
1221
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1222
|
+
case 10:
|
|
1223
|
+
_c.sent();
|
|
1224
|
+
numberTryOnline--;
|
|
1225
|
+
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because navigator is offline try ".concat(numberTryOnline) });
|
|
1226
|
+
return [3 /*break*/, 9];
|
|
1227
|
+
case 11: return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, extras)];
|
|
1228
|
+
case 12:
|
|
1229
|
+
tokenResponse = _c.sent();
|
|
1230
|
+
if (!tokenResponse.success) return [3 /*break*/, 13];
|
|
1231
|
+
this.publishEvent(eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
|
|
1232
|
+
return [2 /*return*/, tokenResponse.data];
|
|
1233
|
+
case 13:
|
|
1234
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "bad request", tokenResponse: tokenResponse });
|
|
1235
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1236
|
+
case 14: return [2 /*return*/, _c.sent()];
|
|
1237
|
+
case 15: return [3 /*break*/, 17];
|
|
1238
|
+
case 16:
|
|
1150
1239
|
exception_4 = _c.sent();
|
|
1151
1240
|
console.error(exception_4);
|
|
1152
|
-
this.publishEvent(eventNames.refreshTokensAsync_silent_error, exception_4);
|
|
1153
|
-
return [
|
|
1154
|
-
case
|
|
1155
|
-
|
|
1241
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "exception", exception: exception_4.message });
|
|
1242
|
+
return [3 /*break*/, 17];
|
|
1243
|
+
case 17:
|
|
1244
|
+
index++;
|
|
1245
|
+
return [3 /*break*/, 4];
|
|
1246
|
+
case 18: return [2 /*return*/];
|
|
1156
1247
|
}
|
|
1157
1248
|
});
|
|
1158
1249
|
});
|
|
1159
1250
|
};
|
|
1160
1251
|
Oidc.prototype.syncTokensAsync = function () {
|
|
1161
|
-
var _a;
|
|
1162
1252
|
return __awaiter(this, void 0, void 0, function () {
|
|
1163
|
-
var
|
|
1164
|
-
|
|
1165
|
-
|
|
1166
|
-
|
|
1167
|
-
|
|
1168
|
-
|
|
1169
|
-
|
|
1170
|
-
|
|
1171
|
-
|
|
1172
|
-
|
|
1173
|
-
|
|
1174
|
-
|
|
1175
|
-
|
|
1176
|
-
|
|
1177
|
-
|
|
1178
|
-
|
|
1179
|
-
|
|
1180
|
-
|
|
1181
|
-
|
|
1182
|
-
|
|
1183
|
-
|
|
1184
|
-
|
|
1185
|
-
|
|
1186
|
-
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1197
|
-
|
|
1198
|
-
|
|
1199
|
-
|
|
1200
|
-
|
|
1201
|
-
|
|
1202
|
-
|
|
1203
|
-
|
|
1204
|
-
|
|
1205
|
-
|
|
1206
|
-
|
|
1207
|
-
|
|
1208
|
-
|
|
1209
|
-
|
|
1210
|
-
|
|
1211
|
-
|
|
1212
|
-
|
|
1213
|
-
|
|
1214
|
-
|
|
1215
|
-
|
|
1216
|
-
|
|
1217
|
-
|
|
1253
|
+
var localSyncTokensAsync;
|
|
1254
|
+
var _this = this;
|
|
1255
|
+
return __generator(this, function (_a) {
|
|
1256
|
+
localSyncTokensAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1257
|
+
var configuration, oidcServerConfiguration, serviceWorker, isLogin, loginParams, silent_token_response, _a, exceptionSilent_2, session, tokens;
|
|
1258
|
+
var _b;
|
|
1259
|
+
return __generator(this, function (_c) {
|
|
1260
|
+
switch (_c.label) {
|
|
1261
|
+
case 0:
|
|
1262
|
+
configuration = this.configuration;
|
|
1263
|
+
if (!this.tokens) {
|
|
1264
|
+
return [2 /*return*/, null];
|
|
1265
|
+
}
|
|
1266
|
+
return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
|
|
1267
|
+
case 1:
|
|
1268
|
+
oidcServerConfiguration = _c.sent();
|
|
1269
|
+
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
|
|
1270
|
+
case 2:
|
|
1271
|
+
serviceWorker = _c.sent();
|
|
1272
|
+
if (!serviceWorker) return [3 /*break*/, 13];
|
|
1273
|
+
return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "syncTokensAsync")];
|
|
1274
|
+
case 3:
|
|
1275
|
+
isLogin = (_c.sent()).isLogin;
|
|
1276
|
+
if (!(isLogin == false)) return [3 /*break*/, 5];
|
|
1277
|
+
this.publishEvent(eventNames.logout_from_another_tab, {});
|
|
1278
|
+
return [4 /*yield*/, this.destroyAsync()];
|
|
1279
|
+
case 4:
|
|
1280
|
+
_c.sent();
|
|
1281
|
+
return [2 /*return*/, null];
|
|
1282
|
+
case 5:
|
|
1283
|
+
if (!(isLogin == null)) return [3 /*break*/, 12];
|
|
1284
|
+
_c.label = 6;
|
|
1285
|
+
case 6:
|
|
1286
|
+
_c.trys.push([6, 11, , 12]);
|
|
1287
|
+
this.publishEvent(eventNames.syncTokensAsync_begin, {});
|
|
1288
|
+
loginParams = getLoginParams(this.configurationName, configuration.redirect_uri);
|
|
1289
|
+
return [4 /*yield*/, this.silentLoginAsync(__assign(__assign({}, loginParams.extras), { prompt: "none" }), loginParams.state)];
|
|
1290
|
+
case 7:
|
|
1291
|
+
silent_token_response = _c.sent();
|
|
1292
|
+
if (!(silent_token_response && silent_token_response.tokens)) return [3 /*break*/, 9];
|
|
1293
|
+
_a = this;
|
|
1294
|
+
return [4 /*yield*/, setTokensAsync(serviceWorker, silent_token_response.tokens)];
|
|
1295
|
+
case 8:
|
|
1296
|
+
_a.tokens = _c.sent();
|
|
1297
|
+
this.publishEvent(eventNames.syncTokensAsync_end, {});
|
|
1298
|
+
return [2 /*return*/, this.tokens];
|
|
1299
|
+
case 9:
|
|
1300
|
+
this.publishEvent(eventNames.syncTokensAsync_error, { message: "no token found in result" });
|
|
1301
|
+
if (this.timeoutId) {
|
|
1302
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
1303
|
+
this.timeoutId = null;
|
|
1304
|
+
}
|
|
1305
|
+
this.publishEvent(eventNames.syncTokensAsync_end, {});
|
|
1306
|
+
return [2 /*return*/, null];
|
|
1307
|
+
case 10: return [3 /*break*/, 12];
|
|
1308
|
+
case 11:
|
|
1309
|
+
exceptionSilent_2 = _c.sent();
|
|
1310
|
+
console.error(exceptionSilent_2);
|
|
1311
|
+
this.publishEvent(eventNames.syncTokensAsync_error, exceptionSilent_2);
|
|
1312
|
+
if (this.timeoutId) {
|
|
1313
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
1314
|
+
this.timeoutId = null;
|
|
1315
|
+
}
|
|
1316
|
+
this.publishEvent(eventNames.syncTokensAsync_end, {});
|
|
1317
|
+
return [2 /*return*/, null];
|
|
1318
|
+
case 12: return [3 /*break*/, 16];
|
|
1319
|
+
case 13:
|
|
1320
|
+
session = (0, initSession_1.initSession)(this.configurationName, configuration.redirect_uri, (_b = configuration.storage) !== null && _b !== void 0 ? _b : sessionStorage);
|
|
1321
|
+
return [4 /*yield*/, session.initAsync()];
|
|
1322
|
+
case 14:
|
|
1323
|
+
tokens = (_c.sent()).tokens;
|
|
1324
|
+
if (!!tokens) return [3 /*break*/, 16];
|
|
1325
|
+
this.publishEvent(eventNames.logout_from_another_tab, {});
|
|
1326
|
+
return [4 /*yield*/, this.destroyAsync()];
|
|
1327
|
+
case 15:
|
|
1328
|
+
_c.sent();
|
|
1329
|
+
return [2 /*return*/, null];
|
|
1330
|
+
case 16: return [2 /*return*/, this.tokens];
|
|
1218
1331
|
}
|
|
1219
|
-
|
|
1220
|
-
|
|
1221
|
-
|
|
1222
|
-
|
|
1223
|
-
_c.label = 13;
|
|
1224
|
-
case 13: return [3 /*break*/, 17];
|
|
1225
|
-
case 14:
|
|
1226
|
-
session = (0, initSession_1.initSession)(this.configurationName, configuration.redirect_uri, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
|
|
1227
|
-
return [4 /*yield*/, session.initAsync()];
|
|
1228
|
-
case 15:
|
|
1229
|
-
tokens = (_c.sent()).tokens;
|
|
1230
|
-
if (!!tokens) return [3 /*break*/, 17];
|
|
1231
|
-
this.publishEvent(eventNames.logout_from_another_tab, {});
|
|
1232
|
-
return [4 /*yield*/, this.destroyAsync()];
|
|
1233
|
-
case 16:
|
|
1234
|
-
_c.sent();
|
|
1235
|
-
_c.label = 17;
|
|
1236
|
-
case 17: return [2 /*return*/];
|
|
1332
|
+
});
|
|
1333
|
+
}); };
|
|
1334
|
+
if (this.syncTokensAsyncPromise) {
|
|
1335
|
+
return [2 /*return*/, this.syncTokensAsyncPromise];
|
|
1237
1336
|
}
|
|
1337
|
+
this.syncTokensAsyncPromise = localSyncTokensAsync().then(function (result) {
|
|
1338
|
+
if (_this.syncTokensAsyncPromise) {
|
|
1339
|
+
_this.syncTokensAsyncPromise = null;
|
|
1340
|
+
}
|
|
1341
|
+
return result;
|
|
1342
|
+
});
|
|
1343
|
+
return [2 /*return*/, this.syncTokensAsyncPromise];
|
|
1238
1344
|
});
|
|
1239
1345
|
});
|
|
1240
1346
|
};
|