@axa-fr/react-oidc 5.12.0 → 5.13.1
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/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +12 -2
- package/dist/OidcProvider.js.map +1 -1
- package/dist/OidcServiceWorker.js +9 -3
- package/dist/core/default-component/Callback.component.js +8 -6
- package/dist/core/default-component/Callback.component.js.map +1 -1
- package/dist/vanilla/initWorker.d.ts.map +1 -1
- package/dist/vanilla/initWorker.js +2 -11
- package/dist/vanilla/initWorker.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +4 -0
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +171 -156
- package/dist/vanilla/oidc.js.map +1 -1
- package/package.json +1 -1
- package/src/App.tsx +29 -4
- package/src/configurations.ts +1 -1
- package/src/oidc/OidcProvider.tsx +13 -2
- package/src/oidc/core/default-component/Callback.component.tsx +4 -4
- package/src/oidc/vanilla/OidcServiceWorker.js +9 -3
- package/src/oidc/vanilla/initWorker.ts +2 -10
- package/src/oidc/vanilla/oidc.ts +84 -48
package/dist/vanilla/oidc.js
CHANGED
|
@@ -103,82 +103,74 @@ var oidcFactory = function (configuration, name) {
|
|
|
103
103
|
return oidcDatabase[name];
|
|
104
104
|
};
|
|
105
105
|
var loginCallbackWithAutoTokensRenewAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, function () {
|
|
106
|
-
var response, tokens, _a
|
|
107
|
-
return __generator(this, function (
|
|
108
|
-
switch (
|
|
106
|
+
var response, tokens, _a;
|
|
107
|
+
return __generator(this, function (_b) {
|
|
108
|
+
switch (_b.label) {
|
|
109
109
|
case 0: return [4 /*yield*/, oidc.loginCallbackAsync()];
|
|
110
110
|
case 1:
|
|
111
|
-
response =
|
|
111
|
+
response = _b.sent();
|
|
112
112
|
tokens = response.tokens;
|
|
113
113
|
_a = oidc;
|
|
114
114
|
return [4 /*yield*/, setTokensAsync(oidc.serviceWorker, tokens)];
|
|
115
115
|
case 2:
|
|
116
|
-
_a.tokens =
|
|
116
|
+
_a.tokens = _b.sent();
|
|
117
117
|
if (!!oidc.serviceWorker) return [3 /*break*/, 4];
|
|
118
118
|
return [4 /*yield*/, oidc.session.setTokens(oidc.tokens)];
|
|
119
119
|
case 3:
|
|
120
|
-
|
|
121
|
-
|
|
120
|
+
_b.sent();
|
|
121
|
+
_b.label = 4;
|
|
122
122
|
case 4:
|
|
123
123
|
oidc.publishEvent(Oidc.eventNames.token_aquired, oidc.tokens);
|
|
124
|
-
|
|
125
|
-
return [4 /*yield*/, autoRenewTokensAsync(oidc, tokens.refreshToken, oidc.tokens.expiresAt)];
|
|
126
|
-
case 5:
|
|
127
|
-
_b.timeoutId = _c.sent();
|
|
124
|
+
oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt);
|
|
128
125
|
return [2 /*return*/, { state: response.state, callbackPath: response.callbackPath }];
|
|
129
126
|
}
|
|
130
127
|
});
|
|
131
128
|
}); };
|
|
132
|
-
var
|
|
133
|
-
var refreshTimeBeforeTokensExpirationInSecond;
|
|
129
|
+
var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
|
|
134
130
|
var _a;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
return [2 /*return*/];
|
|
161
|
-
}
|
|
162
|
-
oidc.publishEvent(Oidc.eventNames.token_renewed, oidc.tokens);
|
|
163
|
-
_b = oidc;
|
|
164
|
-
return [4 /*yield*/, autoRenewTokensAsync(oidc, tokens.refreshToken, oidc.tokens.expiresAt)];
|
|
165
|
-
case 5:
|
|
166
|
-
_b.timeoutId = _d.sent();
|
|
167
|
-
return [3 /*break*/, 9];
|
|
168
|
-
case 6: return [4 /*yield*/, oidc.syncTokensAsync()];
|
|
169
|
-
case 7:
|
|
170
|
-
_d.sent();
|
|
171
|
-
_c = oidc;
|
|
172
|
-
return [4 /*yield*/, autoRenewTokensAsync(oidc, refreshToken, expiresAt)];
|
|
173
|
-
case 8:
|
|
174
|
-
_c.timeoutId = _d.sent();
|
|
175
|
-
_d.label = 9;
|
|
176
|
-
case 9: return [2 /*return*/];
|
|
131
|
+
var refreshTimeBeforeTokensExpirationInSecond = (_a = oidc.configuration.refresh_time_before_tokens_expiration_in_second) !== null && _a !== void 0 ? _a : 60;
|
|
132
|
+
return timer_1.default.setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
133
|
+
var currentTimeUnixSecond, timeInfo, tokens, _a;
|
|
134
|
+
return __generator(this, function (_b) {
|
|
135
|
+
switch (_b.label) {
|
|
136
|
+
case 0:
|
|
137
|
+
currentTimeUnixSecond = new Date().getTime() / 1000;
|
|
138
|
+
timeInfo = { timeLeft: Math.round(((expiresAt - refreshTimeBeforeTokensExpirationInSecond) - currentTimeUnixSecond)) };
|
|
139
|
+
oidc.publishEvent(Oidc.eventNames.token_timer, timeInfo);
|
|
140
|
+
if (!(currentTimeUnixSecond > (expiresAt - refreshTimeBeforeTokensExpirationInSecond))) return [3 /*break*/, 5];
|
|
141
|
+
return [4 /*yield*/, oidc.refreshTokensAsync(refreshToken)];
|
|
142
|
+
case 1:
|
|
143
|
+
tokens = _b.sent();
|
|
144
|
+
_a = oidc;
|
|
145
|
+
return [4 /*yield*/, setTokensAsync(oidc.serviceWorker, tokens)];
|
|
146
|
+
case 2:
|
|
147
|
+
_a.tokens = _b.sent();
|
|
148
|
+
if (!!oidc.serviceWorker) return [3 /*break*/, 4];
|
|
149
|
+
return [4 /*yield*/, oidc.session.setTokens(oidc.tokens)];
|
|
150
|
+
case 3:
|
|
151
|
+
_b.sent();
|
|
152
|
+
_b.label = 4;
|
|
153
|
+
case 4:
|
|
154
|
+
if (!oidc.tokens) {
|
|
155
|
+
return [2 /*return*/];
|
|
177
156
|
}
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
}
|
|
157
|
+
oidc.publishEvent(Oidc.eventNames.token_renewed, oidc.tokens);
|
|
158
|
+
if (oidc.timeoutId) {
|
|
159
|
+
oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt);
|
|
160
|
+
}
|
|
161
|
+
return [3 /*break*/, 7];
|
|
162
|
+
case 5: return [4 /*yield*/, oidc.syncTokensAsync()];
|
|
163
|
+
case 6:
|
|
164
|
+
_b.sent();
|
|
165
|
+
if (oidc.timeoutId) {
|
|
166
|
+
oidc.timeoutId = autoRenewTokens(oidc, refreshToken, expiresAt);
|
|
167
|
+
}
|
|
168
|
+
_b.label = 7;
|
|
169
|
+
case 7: return [2 /*return*/];
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}); }, 1000);
|
|
173
|
+
};
|
|
182
174
|
var getLoginParams = function (configurationName) {
|
|
183
175
|
return JSON.parse(sessionStorage["oidc_login.".concat(configurationName)]);
|
|
184
176
|
};
|
|
@@ -280,6 +272,9 @@ var eventNames = {
|
|
|
280
272
|
silentSigninAsync_begin: "silentSigninAsync_begin",
|
|
281
273
|
silentSigninAsync_end: "silentSigninAsync_end",
|
|
282
274
|
silentSigninAsync_error: "silentSigninAsync_error",
|
|
275
|
+
syncTokensAsync_begin: "syncTokensAsync_begin",
|
|
276
|
+
syncTokensAsync_end: "syncTokensAsync_end",
|
|
277
|
+
syncTokensAsync_error: "syncTokensAsync_error"
|
|
283
278
|
};
|
|
284
279
|
var getRandomInt = function (max) {
|
|
285
280
|
return Math.floor(Math.random() * max);
|
|
@@ -287,6 +282,7 @@ var getRandomInt = function (max) {
|
|
|
287
282
|
var Oidc = /** @class */ (function () {
|
|
288
283
|
function Oidc(configuration, configurationName) {
|
|
289
284
|
if (configurationName === void 0) { configurationName = "default"; }
|
|
285
|
+
this.iFrameSession = {};
|
|
290
286
|
this.initAsyncPromise = null;
|
|
291
287
|
this.tryKeepExistingSessionPromise = null;
|
|
292
288
|
this.syncTokensAsyncPromise = null;
|
|
@@ -341,51 +337,59 @@ var Oidc = /** @class */ (function () {
|
|
|
341
337
|
};
|
|
342
338
|
Oidc.prototype.silentSigninAsync = function () {
|
|
343
339
|
return __awaiter(this, void 0, void 0, function () {
|
|
344
|
-
var
|
|
340
|
+
var configuration_1, link, iframe_1, self_1;
|
|
345
341
|
return __generator(this, function (_a) {
|
|
346
342
|
if (!this.configuration.silent_redirect_uri) {
|
|
347
343
|
return [2 /*return*/, Promise.resolve(null)];
|
|
348
344
|
}
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
345
|
+
try {
|
|
346
|
+
this.publishEvent(eventNames.silentSigninAsync_begin, {});
|
|
347
|
+
configuration_1 = this.configuration;
|
|
348
|
+
link = configuration_1.silent_redirect_uri;
|
|
349
|
+
iframe_1 = document.createElement('iframe');
|
|
350
|
+
iframe_1.width = "0px";
|
|
351
|
+
iframe_1.height = "0px";
|
|
352
|
+
iframe_1.id = "".concat(this.configurationName, "_oidc_iframe");
|
|
353
|
+
iframe_1.setAttribute("src", link);
|
|
354
|
+
document.body.appendChild(iframe_1);
|
|
355
|
+
self_1 = this;
|
|
356
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
357
|
+
try {
|
|
358
|
+
var isResolved_1 = false;
|
|
359
|
+
window.onmessage = function (e) {
|
|
360
|
+
var key = "".concat(self_1.configurationName, "_oidc_tokens:");
|
|
361
|
+
if (e.data && typeof (e.data) === "string" && e.data.startsWith(key)) {
|
|
362
|
+
if (!isResolved_1) {
|
|
363
|
+
var result = JSON.parse(e.data.replace(key, ''));
|
|
364
|
+
self_1.publishEvent(eventNames.silentSigninAsync_end, result);
|
|
365
|
+
iframe_1.remove();
|
|
366
|
+
isResolved_1 = true;
|
|
367
|
+
resolve(result);
|
|
368
|
+
}
|
|
369
|
+
}
|
|
370
|
+
};
|
|
371
|
+
var silentSigninTimeout = configuration_1.silent_signin_timeout ? configuration_1.silent_signin_timeout : 12000;
|
|
372
|
+
setTimeout(function () {
|
|
365
373
|
if (!isResolved_1) {
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
iframe.remove();
|
|
374
|
+
self_1.publishEvent(eventNames.silentSigninAsync_error, "timeout");
|
|
375
|
+
iframe_1.remove();
|
|
369
376
|
isResolved_1 = true;
|
|
377
|
+
reject("timeout");
|
|
370
378
|
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
reject(e);
|
|
386
|
-
self.publishEvent(eventNames.silentSigninAsync_error, e);
|
|
387
|
-
}
|
|
388
|
-
})];
|
|
379
|
+
}, silentSigninTimeout);
|
|
380
|
+
}
|
|
381
|
+
catch (e) {
|
|
382
|
+
iframe_1.remove();
|
|
383
|
+
self_1.publishEvent(eventNames.silentSigninAsync_error, e);
|
|
384
|
+
reject(e);
|
|
385
|
+
}
|
|
386
|
+
})];
|
|
387
|
+
}
|
|
388
|
+
catch (e) {
|
|
389
|
+
this.publishEvent(eventNames.silentSigninAsync_error, e);
|
|
390
|
+
throw e;
|
|
391
|
+
}
|
|
392
|
+
return [2 /*return*/];
|
|
389
393
|
});
|
|
390
394
|
});
|
|
391
395
|
};
|
|
@@ -425,58 +429,54 @@ var Oidc = /** @class */ (function () {
|
|
|
425
429
|
return [2 /*return*/, this.tryKeepExistingSessionPromise];
|
|
426
430
|
}
|
|
427
431
|
funcAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
428
|
-
var serviceWorker, configuration, oidcServerConfiguration, tokens, updatedTokens, _a,
|
|
429
|
-
return __generator(this, function (
|
|
430
|
-
switch (
|
|
432
|
+
var serviceWorker, configuration, oidcServerConfiguration, tokens, updatedTokens, _a, session, tokens, updatedTokens, _b, exception_1;
|
|
433
|
+
return __generator(this, function (_c) {
|
|
434
|
+
switch (_c.label) {
|
|
431
435
|
case 0:
|
|
432
436
|
if (this.tokens != null) {
|
|
433
437
|
return [2 /*return*/, false];
|
|
434
438
|
}
|
|
435
439
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_begin, {});
|
|
436
|
-
|
|
440
|
+
_c.label = 1;
|
|
437
441
|
case 1:
|
|
438
|
-
|
|
442
|
+
_c.trys.push([1, 13, , 16]);
|
|
439
443
|
configuration = this.configuration;
|
|
440
444
|
return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
|
|
441
445
|
case 2:
|
|
442
|
-
oidcServerConfiguration =
|
|
446
|
+
oidcServerConfiguration = _c.sent();
|
|
443
447
|
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
|
|
444
448
|
case 3:
|
|
445
|
-
serviceWorker =
|
|
446
|
-
if (!serviceWorker) return [3 /*break*/,
|
|
449
|
+
serviceWorker = _c.sent();
|
|
450
|
+
if (!serviceWorker) return [3 /*break*/, 8];
|
|
447
451
|
return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "tryKeepExistingSessionAsync")];
|
|
448
452
|
case 4:
|
|
449
|
-
tokens = (
|
|
450
|
-
if (!tokens) return [3 /*break*/,
|
|
453
|
+
tokens = (_c.sent()).tokens;
|
|
454
|
+
if (!tokens) return [3 /*break*/, 7];
|
|
451
455
|
serviceWorker.startKeepAliveServiceWorker();
|
|
452
456
|
return [4 /*yield*/, this.refreshTokensAsync(tokens.refresh_token, true)];
|
|
453
457
|
case 5:
|
|
454
|
-
updatedTokens =
|
|
458
|
+
updatedTokens = _c.sent();
|
|
455
459
|
// @ts-ignore
|
|
456
460
|
_a = this;
|
|
457
461
|
return [4 /*yield*/, setTokensAsync(serviceWorker, updatedTokens)];
|
|
458
462
|
case 6:
|
|
459
463
|
// @ts-ignore
|
|
460
|
-
_a.tokens =
|
|
464
|
+
_a.tokens = _c.sent();
|
|
461
465
|
this.serviceWorker = serviceWorker;
|
|
462
466
|
// @ts-ignore
|
|
463
|
-
|
|
464
|
-
return [4 /*yield*/, autoRenewTokensAsync(this, updatedTokens.refreshToken, this.tokens.expiresAt)];
|
|
465
|
-
case 7:
|
|
466
|
-
// @ts-ignore
|
|
467
|
-
_b.timeoutId = _e.sent();
|
|
467
|
+
this.timeoutId = autoRenewTokens(this, updatedTokens.refreshToken, this.tokens.expiresAt);
|
|
468
468
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
469
469
|
success: true,
|
|
470
470
|
message: "tokens inside ServiceWorker are valid"
|
|
471
471
|
});
|
|
472
472
|
return [2 /*return*/, true];
|
|
473
|
-
case
|
|
473
|
+
case 7:
|
|
474
474
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
475
475
|
success: false,
|
|
476
476
|
message: "no exiting session found"
|
|
477
477
|
});
|
|
478
|
-
return [3 /*break*/,
|
|
479
|
-
case
|
|
478
|
+
return [3 /*break*/, 12];
|
|
479
|
+
case 8:
|
|
480
480
|
if (configuration.service_worker_relative_url) {
|
|
481
481
|
this.publishEvent(eventNames.service_worker_not_supported_by_browser, {
|
|
482
482
|
message: "service worker is not supported by this browser"
|
|
@@ -484,48 +484,44 @@ var Oidc = /** @class */ (function () {
|
|
|
484
484
|
}
|
|
485
485
|
session = (0, initSession_1.initSession)(this.configurationName);
|
|
486
486
|
return [4 /*yield*/, session.initAsync()];
|
|
487
|
-
case
|
|
488
|
-
tokens = (
|
|
489
|
-
if (!tokens) return [3 /*break*/,
|
|
487
|
+
case 9:
|
|
488
|
+
tokens = (_c.sent()).tokens;
|
|
489
|
+
if (!tokens) return [3 /*break*/, 12];
|
|
490
490
|
return [4 /*yield*/, this.refreshTokensAsync(tokens.refreshToken, true)];
|
|
491
|
-
case
|
|
492
|
-
updatedTokens =
|
|
491
|
+
case 10:
|
|
492
|
+
updatedTokens = _c.sent();
|
|
493
493
|
// @ts-ignore
|
|
494
|
-
|
|
494
|
+
_b = this;
|
|
495
495
|
return [4 /*yield*/, setTokensAsync(serviceWorker, updatedTokens)];
|
|
496
|
-
case
|
|
496
|
+
case 11:
|
|
497
497
|
// @ts-ignore
|
|
498
|
-
|
|
498
|
+
_b.tokens = _c.sent();
|
|
499
499
|
session.setTokens(this.tokens);
|
|
500
500
|
this.session = session;
|
|
501
501
|
// @ts-ignore
|
|
502
|
-
|
|
503
|
-
return [4 /*yield*/, autoRenewTokensAsync(this, updatedTokens.refreshToken, this.tokens.expiresAt)];
|
|
504
|
-
case 13:
|
|
505
|
-
// @ts-ignore
|
|
506
|
-
_d.timeoutId = _e.sent();
|
|
502
|
+
this.timeoutId = autoRenewTokens(this, updatedTokens.refreshToken, this.tokens.expiresAt);
|
|
507
503
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
508
504
|
success: true,
|
|
509
505
|
message: "tokens inside ServiceWorker are valid"
|
|
510
506
|
});
|
|
511
507
|
return [2 /*return*/, true];
|
|
512
|
-
case
|
|
508
|
+
case 12:
|
|
513
509
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
514
510
|
success: false,
|
|
515
|
-
message: "
|
|
511
|
+
message: serviceWorker ? "service worker sessions not retrieved" : "session storage sessions not retrieved"
|
|
516
512
|
});
|
|
517
513
|
return [2 /*return*/, false];
|
|
518
|
-
case
|
|
519
|
-
exception_1 =
|
|
520
|
-
if (!serviceWorker) return [3 /*break*/,
|
|
514
|
+
case 13:
|
|
515
|
+
exception_1 = _c.sent();
|
|
516
|
+
if (!serviceWorker) return [3 /*break*/, 15];
|
|
521
517
|
return [4 /*yield*/, serviceWorker.clearAsync()];
|
|
522
|
-
case
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
case
|
|
518
|
+
case 14:
|
|
519
|
+
_c.sent();
|
|
520
|
+
_c.label = 15;
|
|
521
|
+
case 15:
|
|
526
522
|
this.publishEvent(eventNames.tryKeepExistingSessionAsync_error, "tokens inside ServiceWorker are invalid");
|
|
527
523
|
return [2 /*return*/, false];
|
|
528
|
-
case
|
|
524
|
+
case 16: return [2 /*return*/];
|
|
529
525
|
}
|
|
530
526
|
});
|
|
531
527
|
}); };
|
|
@@ -634,10 +630,13 @@ var Oidc = /** @class */ (function () {
|
|
|
634
630
|
_b.label = 4;
|
|
635
631
|
case 4:
|
|
636
632
|
_b.trys.push([4, 9, , 10]);
|
|
633
|
+
this.publishEvent(eventNames.syncTokensAsync_begin, {});
|
|
637
634
|
this.syncTokensAsyncPromise = this.silentSigninAsync();
|
|
638
635
|
return [4 /*yield*/, this.syncTokensAsyncPromise];
|
|
639
636
|
case 5:
|
|
640
637
|
silent_token_response = _b.sent();
|
|
638
|
+
console.log("silent_token_response");
|
|
639
|
+
console.log(silent_token_response);
|
|
641
640
|
if (!silent_token_response) return [3 /*break*/, 7];
|
|
642
641
|
_a = this;
|
|
643
642
|
return [4 /*yield*/, setTokensAsync(serviceWorker, silent_token_response)];
|
|
@@ -645,16 +644,25 @@ var Oidc = /** @class */ (function () {
|
|
|
645
644
|
_a.tokens = _b.sent();
|
|
646
645
|
return [3 /*break*/, 8];
|
|
647
646
|
case 7:
|
|
648
|
-
this.publishEvent(eventNames.
|
|
649
|
-
|
|
647
|
+
this.publishEvent(eventNames.syncTokensAsync_error, null);
|
|
648
|
+
if (this.timeoutId) {
|
|
649
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
650
|
+
this.timeoutId = null;
|
|
651
|
+
}
|
|
652
|
+
return [2 /*return*/];
|
|
650
653
|
case 8: return [3 /*break*/, 10];
|
|
651
654
|
case 9:
|
|
652
655
|
exceptionSilent_1 = _b.sent();
|
|
653
656
|
console.error(exceptionSilent_1);
|
|
654
|
-
this.publishEvent(eventNames.
|
|
655
|
-
|
|
657
|
+
this.publishEvent(eventNames.syncTokensAsync_error, exceptionSilent_1);
|
|
658
|
+
if (this.timeoutId) {
|
|
659
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
660
|
+
this.timeoutId = null;
|
|
661
|
+
}
|
|
662
|
+
return [2 /*return*/];
|
|
656
663
|
case 10:
|
|
657
664
|
this.syncTokensAsyncPromise = null;
|
|
665
|
+
this.publishEvent(eventNames.syncTokensAsync_end, {});
|
|
658
666
|
_b.label = 11;
|
|
659
667
|
case 11: return [2 /*return*/];
|
|
660
668
|
}
|
|
@@ -663,22 +671,22 @@ var Oidc = /** @class */ (function () {
|
|
|
663
671
|
};
|
|
664
672
|
Oidc.prototype.loginCallbackAsync = function () {
|
|
665
673
|
return __awaiter(this, void 0, void 0, function () {
|
|
666
|
-
var
|
|
674
|
+
var configuration_2, clientId_1, redirectURL_1, authority, tokenRequestTimeout_1, oidcServerConfiguration_1, serviceWorker, storage_1, items, dummy, session, items, exception_3;
|
|
667
675
|
var _this = this;
|
|
668
676
|
return __generator(this, function (_a) {
|
|
669
677
|
switch (_a.label) {
|
|
670
678
|
case 0:
|
|
671
679
|
_a.trys.push([0, 10, , 11]);
|
|
672
680
|
this.publishEvent(eventNames.loginCallbackAsync_begin, {});
|
|
673
|
-
|
|
674
|
-
clientId_1 =
|
|
675
|
-
redirectURL_1 =
|
|
676
|
-
authority =
|
|
677
|
-
tokenRequestTimeout_1 =
|
|
678
|
-
return [4 /*yield*/, this.initAsync(authority,
|
|
681
|
+
configuration_2 = this.configuration;
|
|
682
|
+
clientId_1 = configuration_2.client_id;
|
|
683
|
+
redirectURL_1 = configuration_2.redirect_uri;
|
|
684
|
+
authority = configuration_2.authority;
|
|
685
|
+
tokenRequestTimeout_1 = configuration_2.token_request_timeout;
|
|
686
|
+
return [4 /*yield*/, this.initAsync(authority, configuration_2.authority_configuration)];
|
|
679
687
|
case 1:
|
|
680
688
|
oidcServerConfiguration_1 = _a.sent();
|
|
681
|
-
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(
|
|
689
|
+
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration_2.service_worker_relative_url, this.configurationName)];
|
|
682
690
|
case 2:
|
|
683
691
|
serviceWorker = _a.sent();
|
|
684
692
|
storage_1 = null;
|
|
@@ -712,7 +720,7 @@ var Oidc = /** @class */ (function () {
|
|
|
712
720
|
_a.label = 9;
|
|
713
721
|
case 9: return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
714
722
|
// @ts-ignore
|
|
715
|
-
var queryStringUtil =
|
|
723
|
+
var queryStringUtil = configuration_2.redirect_uri.includes("#") ? new noHashQueryStringUtils_1.HashQueryStringUtils() : new noHashQueryStringUtils_1.NoHashQueryStringUtils();
|
|
716
724
|
// @ts-ignore
|
|
717
725
|
var authorizationHandler = new appauth_1.RedirectRequestHandler(storage_1, queryStringUtil, window.location, new appauth_1.DefaultCrypto());
|
|
718
726
|
var notifier = new appauth_1.AuthorizationNotifier();
|
|
@@ -730,8 +738,8 @@ var Oidc = /** @class */ (function () {
|
|
|
730
738
|
if (request && request.internal) {
|
|
731
739
|
extras = {};
|
|
732
740
|
extras.code_verifier = request.internal.code_verifier;
|
|
733
|
-
if (
|
|
734
|
-
for (var _i = 0, _a = Object.entries(
|
|
741
|
+
if (configuration_2.token_request_extras) {
|
|
742
|
+
for (var _i = 0, _a = Object.entries(configuration_2.token_request_extras); _i < _a.length; _i++) {
|
|
735
743
|
var _b = _a[_i], key = _b[0], value = _b[1];
|
|
736
744
|
extras[key] = value;
|
|
737
745
|
}
|
|
@@ -755,18 +763,20 @@ var Oidc = /** @class */ (function () {
|
|
|
755
763
|
if (timeoutId) {
|
|
756
764
|
var loginParams = (0, exports.getLoginParams)(_this.configurationName);
|
|
757
765
|
clearTimeout(timeoutId);
|
|
766
|
+
_this.timeoutId = null;
|
|
767
|
+
_this.publishEvent(eventNames.loginCallbackAsync_end, {});
|
|
758
768
|
resolve({
|
|
759
769
|
tokens: tokenResponse,
|
|
760
770
|
state: request.state,
|
|
761
771
|
callbackPath: loginParams.callbackPath,
|
|
762
772
|
});
|
|
763
|
-
_this.publishEvent(eventNames.loginCallbackAsync_end, {});
|
|
764
773
|
}
|
|
765
774
|
});
|
|
766
775
|
}
|
|
767
776
|
catch (exception) {
|
|
768
777
|
if (timeoutId) {
|
|
769
778
|
clearTimeout(timeoutId);
|
|
779
|
+
_this.timeoutId = null;
|
|
770
780
|
_this.publishEvent(eventNames.loginCallbackAsync_error, exception);
|
|
771
781
|
console.error(exception);
|
|
772
782
|
reject(exception);
|
|
@@ -813,6 +823,10 @@ var Oidc = /** @class */ (function () {
|
|
|
813
823
|
console.error(exceptionSilent_2);
|
|
814
824
|
return [3 /*break*/, 3];
|
|
815
825
|
case 3:
|
|
826
|
+
if (this.timeoutId) {
|
|
827
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
828
|
+
this.timeoutId = null;
|
|
829
|
+
}
|
|
816
830
|
this.publishEvent(silentEvent ? eventNames.refreshTokensAsync_silent_error : eventNames.refreshTokensAsync_error, exception);
|
|
817
831
|
return [2 /*return*/, null];
|
|
818
832
|
}
|
|
@@ -901,6 +915,7 @@ var Oidc = /** @class */ (function () {
|
|
|
901
915
|
this.userInfo = null;
|
|
902
916
|
this.events = [];
|
|
903
917
|
timer_1.default.clearTimeout(this.timeoutId);
|
|
918
|
+
this.timeoutId = null;
|
|
904
919
|
return [2 /*return*/];
|
|
905
920
|
}
|
|
906
921
|
});
|