@axa-fr/react-oidc 6.0.0-alpha9 → 6.0.0-beta2
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 +12 -9
- 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 +4 -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 -5
- 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 +10 -9
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +183 -139
- 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 -6
- package/src/oidc/vanilla/OidcServiceWorker.js +4 -2
- package/src/oidc/vanilla/checkSessionIFrame.ts +7 -7
- package/src/oidc/vanilla/oidc.ts +122 -118
- 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/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,71 @@ 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, result;
|
|
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
|
+
result = _c.sent();
|
|
110
|
+
return [2 /*return*/, { success: true,
|
|
111
|
+
data: {
|
|
112
|
+
accessToken: result.access_token,
|
|
113
|
+
expiresIn: result.expires_in,
|
|
114
|
+
idToken: result.id_token,
|
|
115
|
+
refreshToken: result.refresh_token,
|
|
116
|
+
scope: result.scope,
|
|
117
|
+
tokenType: result.token_type,
|
|
118
|
+
}
|
|
119
|
+
}];
|
|
120
|
+
}
|
|
121
|
+
});
|
|
122
|
+
}); };
|
|
77
123
|
var internalFetch = function (url, headers, numberRetry) {
|
|
78
124
|
if (numberRetry === void 0) { numberRetry = 0; }
|
|
79
125
|
return __awaiter(void 0, void 0, void 0, function () {
|
|
80
|
-
var response, e_1;
|
|
126
|
+
var response, controller_1, e_1;
|
|
81
127
|
return __generator(this, function (_a) {
|
|
82
128
|
switch (_a.label) {
|
|
83
129
|
case 0:
|
|
84
130
|
_a.trys.push([0, 2, , 8]);
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
])];
|
|
131
|
+
controller_1 = new AbortController();
|
|
132
|
+
setTimeout(function () { return controller_1.abort(); }, 10000);
|
|
133
|
+
return [4 /*yield*/, fetch(url, __assign(__assign({}, headers), { signal: controller_1.signal }))];
|
|
89
134
|
case 1:
|
|
90
135
|
response = _a.sent();
|
|
91
136
|
return [3 /*break*/, 8];
|
|
92
137
|
case 2:
|
|
93
138
|
e_1 = _a.sent();
|
|
94
|
-
if (!(e_1.message === '
|
|
95
|
-
|| e_1.message === 'Network request failed'
|
|
96
|
-
if (!(numberRetry <=
|
|
139
|
+
if (!(e_1.message === 'AbortError'
|
|
140
|
+
|| e_1.message === 'Network request failed')) return [3 /*break*/, 6];
|
|
141
|
+
if (!(numberRetry <= 1)) return [3 /*break*/, 4];
|
|
97
142
|
return [4 /*yield*/, internalFetch(url, headers, numberRetry + 1)];
|
|
98
143
|
case 3: return [2 /*return*/, _a.sent()];
|
|
99
144
|
case 4: throw e_1;
|
|
@@ -253,7 +298,7 @@ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, f
|
|
|
253
298
|
case 0: return [4 /*yield*/, fetch(url, {
|
|
254
299
|
headers: {
|
|
255
300
|
authorization: "Bearer ".concat(accessToken),
|
|
256
|
-
credentials: '
|
|
301
|
+
credentials: 'include'
|
|
257
302
|
}
|
|
258
303
|
})];
|
|
259
304
|
case 1:
|
|
@@ -320,10 +365,10 @@ var eventNames = {
|
|
|
320
365
|
tryKeepExistingSessionAsync_begin: "tryKeepExistingSessionAsync_begin",
|
|
321
366
|
tryKeepExistingSessionAsync_end: "tryKeepExistingSessionAsync_end",
|
|
322
367
|
tryKeepExistingSessionAsync_error: "tryKeepExistingSessionAsync_error",
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
368
|
+
silentLoginAsync_begin: "silentLoginAsync_begin",
|
|
369
|
+
silentLoginAsync: "silentLoginAsync",
|
|
370
|
+
silentLoginAsync_end: "silentLoginAsync_end",
|
|
371
|
+
silentLoginAsync_error: "silentLoginAsync_error",
|
|
327
372
|
syncTokensAsync_begin: "syncTokensAsync_begin",
|
|
328
373
|
syncTokensAsync_end: "syncTokensAsync_end",
|
|
329
374
|
syncTokensAsync_error: "syncTokensAsync_error"
|
|
@@ -331,8 +376,6 @@ var eventNames = {
|
|
|
331
376
|
var getRandomInt = function (max) {
|
|
332
377
|
return Math.floor(Math.random() * max);
|
|
333
378
|
};
|
|
334
|
-
var WELL_KNOWN_PATH = '.well-known';
|
|
335
|
-
var OPENID_CONFIGURATION = 'openid-configuration';
|
|
336
379
|
var oneHourSecond = 60 * 60;
|
|
337
380
|
var fetchFromIssuer = function (openIdIssuerUrl, timeCacheSecond) {
|
|
338
381
|
if (timeCacheSecond === void 0) { timeCacheSecond = oneHourSecond; }
|
|
@@ -341,9 +384,9 @@ var fetchFromIssuer = function (openIdIssuerUrl, timeCacheSecond) {
|
|
|
341
384
|
return __generator(this, function (_a) {
|
|
342
385
|
switch (_a.label) {
|
|
343
386
|
case 0:
|
|
344
|
-
fullUrl = "".concat(openIdIssuerUrl, "/")
|
|
387
|
+
fullUrl = "".concat(openIdIssuerUrl, "/.well-known/openid-configuration");
|
|
345
388
|
localStorageKey = "oidc.server:".concat(openIdIssuerUrl);
|
|
346
|
-
cacheJson = window.
|
|
389
|
+
cacheJson = window.sessionStorage.getItem(localStorageKey);
|
|
347
390
|
oneHourMinisecond = 1000 * timeCacheSecond;
|
|
348
391
|
// @ts-ignore
|
|
349
392
|
if (cacheJson && (cacheJson.timestamp + oneHourMinisecond) > Date.now()) {
|
|
@@ -358,7 +401,7 @@ var fetchFromIssuer = function (openIdIssuerUrl, timeCacheSecond) {
|
|
|
358
401
|
return [4 /*yield*/, response.json()];
|
|
359
402
|
case 2:
|
|
360
403
|
result = _a.sent();
|
|
361
|
-
window.
|
|
404
|
+
window.sessionStorage.setItem(localStorageKey, JSON.stringify({ result: result, timestamp: Date.now() }));
|
|
362
405
|
return [2 /*return*/, new OidcAuthorizationServiceConfiguration(result)];
|
|
363
406
|
}
|
|
364
407
|
});
|
|
@@ -388,7 +431,11 @@ var Oidc = /** @class */ (function () {
|
|
|
388
431
|
this.loginCallbackPromise = null;
|
|
389
432
|
this.syncTokensAsyncPromise = null;
|
|
390
433
|
this.loginCallbackWithAutoTokensRenewPromise = null;
|
|
391
|
-
|
|
434
|
+
var silent_login_uri = configuration.silent_login_uri;
|
|
435
|
+
if (configuration.silent_redirect_uri && !configuration.silent_login_uri) {
|
|
436
|
+
silent_login_uri = "".concat(configuration.silent_redirect_uri, "-login");
|
|
437
|
+
}
|
|
438
|
+
this.configuration = __assign(__assign({}, configuration), { silent_login_uri: silent_login_uri });
|
|
392
439
|
this.configurationName = configurationName;
|
|
393
440
|
this.tokens = null;
|
|
394
441
|
this.userInfo = null;
|
|
@@ -405,6 +452,7 @@ var Oidc = /** @class */ (function () {
|
|
|
405
452
|
this.removeEventSubscription.bind(this);
|
|
406
453
|
this.publishEvent.bind(this);
|
|
407
454
|
this.destroyAsync.bind(this);
|
|
455
|
+
this.logoutAsync.bind(this);
|
|
408
456
|
}
|
|
409
457
|
Oidc.prototype.subscriveEvents = function (func) {
|
|
410
458
|
var id = getRandomInt(9999999999999).toString();
|
|
@@ -432,19 +480,41 @@ var Oidc = /** @class */ (function () {
|
|
|
432
480
|
}
|
|
433
481
|
return oidcDatabase[name];
|
|
434
482
|
};
|
|
435
|
-
Oidc.prototype.
|
|
436
|
-
if (this.configuration.silent_redirect_uri) {
|
|
483
|
+
Oidc.prototype._silentLoginCallbackFromIFrame = function () {
|
|
484
|
+
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
437
485
|
var queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
|
|
438
486
|
window.top.postMessage("".concat(this.configurationName, "_oidc_tokens:").concat(JSON.stringify({ tokens: this.tokens, sessionState: queryParams.session_state })), window.location.origin);
|
|
439
487
|
}
|
|
440
488
|
};
|
|
441
|
-
Oidc.prototype.
|
|
442
|
-
if (this.configuration.silent_redirect_uri) {
|
|
489
|
+
Oidc.prototype._silentLoginErrorCallbackFromIFrame = function () {
|
|
490
|
+
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
443
491
|
var queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
|
|
444
492
|
window.top.postMessage("".concat(this.configurationName, "_oidc_error:").concat(JSON.stringify({ error: queryParams.error })), window.location.origin);
|
|
445
493
|
}
|
|
446
494
|
};
|
|
447
|
-
Oidc.prototype.
|
|
495
|
+
Oidc.prototype.silentLoginCallBackAsync = function () {
|
|
496
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
497
|
+
var error_1;
|
|
498
|
+
return __generator(this, function (_a) {
|
|
499
|
+
switch (_a.label) {
|
|
500
|
+
case 0:
|
|
501
|
+
_a.trys.push([0, 2, , 3]);
|
|
502
|
+
return [4 /*yield*/, this.loginCallbackAsync(true)];
|
|
503
|
+
case 1:
|
|
504
|
+
_a.sent();
|
|
505
|
+
this._silentLoginCallbackFromIFrame();
|
|
506
|
+
return [3 /*break*/, 3];
|
|
507
|
+
case 2:
|
|
508
|
+
error_1 = _a.sent();
|
|
509
|
+
console.error(error_1);
|
|
510
|
+
this._silentLoginErrorCallbackFromIFrame();
|
|
511
|
+
return [3 /*break*/, 3];
|
|
512
|
+
case 3: return [2 /*return*/];
|
|
513
|
+
}
|
|
514
|
+
});
|
|
515
|
+
});
|
|
516
|
+
};
|
|
517
|
+
Oidc.prototype.silentLoginAsync = function (extras, state, scope) {
|
|
448
518
|
if (extras === void 0) { extras = null; }
|
|
449
519
|
if (state === void 0) { state = null; }
|
|
450
520
|
if (scope === void 0) { scope = null; }
|
|
@@ -453,7 +523,7 @@ var Oidc = /** @class */ (function () {
|
|
|
453
523
|
return __generator(this, function (_c) {
|
|
454
524
|
switch (_c.label) {
|
|
455
525
|
case 0:
|
|
456
|
-
if (!this.configuration.silent_redirect_uri || !this.configuration.
|
|
526
|
+
if (!this.configuration.silent_redirect_uri || !this.configuration.silent_login_uri) {
|
|
457
527
|
return [2 /*return*/, Promise.resolve(null)];
|
|
458
528
|
}
|
|
459
529
|
_c.label = 1;
|
|
@@ -462,11 +532,11 @@ var Oidc = /** @class */ (function () {
|
|
|
462
532
|
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
463
533
|
case 2:
|
|
464
534
|
_c.sent();
|
|
465
|
-
this.publishEvent(eventNames.
|
|
535
|
+
this.publishEvent(eventNames.silentLoginAsync, { message: "wait because document is hidden" });
|
|
466
536
|
return [3 /*break*/, 1];
|
|
467
537
|
case 3:
|
|
468
538
|
try {
|
|
469
|
-
this.publishEvent(eventNames.
|
|
539
|
+
this.publishEvent(eventNames.silentLoginAsync_begin, {});
|
|
470
540
|
configuration_1 = this.configuration;
|
|
471
541
|
queries = "";
|
|
472
542
|
if (state) {
|
|
@@ -492,7 +562,7 @@ var Oidc = /** @class */ (function () {
|
|
|
492
562
|
}
|
|
493
563
|
}
|
|
494
564
|
}
|
|
495
|
-
link = configuration_1.
|
|
565
|
+
link = configuration_1.silent_login_uri + queries;
|
|
496
566
|
idx = link.indexOf("/", link.indexOf("//") + 2);
|
|
497
567
|
iFrameOrigin_1 = link.substr(0, idx);
|
|
498
568
|
iframe_1 = document.createElement('iframe');
|
|
@@ -516,14 +586,14 @@ var Oidc = /** @class */ (function () {
|
|
|
516
586
|
if (!isResolved_1) {
|
|
517
587
|
if (data.startsWith(key)) {
|
|
518
588
|
var result = JSON.parse(e.data.replace(key, ''));
|
|
519
|
-
self_1.publishEvent(eventNames.
|
|
589
|
+
self_1.publishEvent(eventNames.silentLoginAsync_end, {});
|
|
520
590
|
iframe_1.remove();
|
|
521
591
|
isResolved_1 = true;
|
|
522
592
|
resolve(result);
|
|
523
593
|
}
|
|
524
594
|
else if (data.startsWith(key_error)) {
|
|
525
595
|
var result = JSON.parse(e.data.replace(key_error, ''));
|
|
526
|
-
self_1.publishEvent(eventNames.
|
|
596
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, result);
|
|
527
597
|
iframe_1.remove();
|
|
528
598
|
isResolved_1 = true;
|
|
529
599
|
reject(result);
|
|
@@ -532,10 +602,10 @@ var Oidc = /** @class */ (function () {
|
|
|
532
602
|
}
|
|
533
603
|
}
|
|
534
604
|
};
|
|
535
|
-
var silentSigninTimeout = (_a = configuration_1.
|
|
605
|
+
var silentSigninTimeout = (_a = configuration_1.silent_login_timeout) !== null && _a !== void 0 ? _a : 12000;
|
|
536
606
|
setTimeout(function () {
|
|
537
607
|
if (!isResolved_1) {
|
|
538
|
-
self_1.publishEvent(eventNames.
|
|
608
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, "timeout");
|
|
539
609
|
iframe_1.remove();
|
|
540
610
|
isResolved_1 = true;
|
|
541
611
|
reject("timeout");
|
|
@@ -544,13 +614,13 @@ var Oidc = /** @class */ (function () {
|
|
|
544
614
|
}
|
|
545
615
|
catch (e) {
|
|
546
616
|
iframe_1.remove();
|
|
547
|
-
self_1.publishEvent(eventNames.
|
|
617
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
548
618
|
reject(e);
|
|
549
619
|
}
|
|
550
620
|
})];
|
|
551
621
|
}
|
|
552
622
|
catch (e) {
|
|
553
|
-
this.publishEvent(eventNames.
|
|
623
|
+
this.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
554
624
|
throw e;
|
|
555
625
|
}
|
|
556
626
|
return [2 /*return*/];
|
|
@@ -800,7 +870,7 @@ var Oidc = /** @class */ (function () {
|
|
|
800
870
|
var _this = this;
|
|
801
871
|
return __generator(this, function (_a) {
|
|
802
872
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
803
|
-
if (_this.configuration.
|
|
873
|
+
if (_this.configuration.silent_login_uri && _this.configuration.silent_redirect_uri && _this.configuration.monitor_session && checkSessionIFrameUri && sessionState && !isSilentSignin) {
|
|
804
874
|
var checkSessionCallback = function () {
|
|
805
875
|
_this.checkSessionIFrame.stop();
|
|
806
876
|
if (_this.tokens === null) {
|
|
@@ -810,7 +880,7 @@ var Oidc = /** @class */ (function () {
|
|
|
810
880
|
var idToken = _this.tokens.idToken;
|
|
811
881
|
// @ts-ignore
|
|
812
882
|
var idTokenPayload = _this.tokens.idTokenPayload;
|
|
813
|
-
_this.
|
|
883
|
+
_this.silentLoginAsync({
|
|
814
884
|
prompt: "none",
|
|
815
885
|
id_token_hint: idToken,
|
|
816
886
|
scope: "openid"
|
|
@@ -1034,125 +1104,99 @@ var Oidc = /** @class */ (function () {
|
|
|
1034
1104
|
};
|
|
1035
1105
|
Oidc.prototype.refreshTokensAsync = function (refreshToken) {
|
|
1036
1106
|
return __awaiter(this, void 0, void 0, function () {
|
|
1037
|
-
var
|
|
1107
|
+
var localsilentLoginAsync, configuration, clientId, redirectUri, authority, extras, _i, _a, _b, key, value, oidcServerConfiguration, details, index, tokenResponse, exception_4;
|
|
1038
1108
|
var _this = this;
|
|
1039
1109
|
return __generator(this, function (_c) {
|
|
1040
1110
|
switch (_c.label) {
|
|
1041
1111
|
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
|
-
return [2 /*return*/, null];
|
|
1068
|
-
}
|
|
1069
|
-
});
|
|
1112
|
+
localsilentLoginAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1113
|
+
var silent_token_response, exceptionSilent_1;
|
|
1114
|
+
return __generator(this, function (_a) {
|
|
1115
|
+
switch (_a.label) {
|
|
1116
|
+
case 0:
|
|
1117
|
+
_a.trys.push([0, 2, , 3]);
|
|
1118
|
+
return [4 /*yield*/, this.silentLoginAsync()];
|
|
1119
|
+
case 1:
|
|
1120
|
+
silent_token_response = _a.sent();
|
|
1121
|
+
if (silent_token_response) {
|
|
1122
|
+
return [2 /*return*/, silent_token_response.tokens];
|
|
1123
|
+
}
|
|
1124
|
+
return [3 /*break*/, 3];
|
|
1125
|
+
case 2:
|
|
1126
|
+
exceptionSilent_1 = _a.sent();
|
|
1127
|
+
console.error(exceptionSilent_1);
|
|
1128
|
+
return [3 /*break*/, 3];
|
|
1129
|
+
case 3:
|
|
1130
|
+
if (this.timeoutId) {
|
|
1131
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
1132
|
+
this.timeoutId = null;
|
|
1133
|
+
}
|
|
1134
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token and silent refresh failed" });
|
|
1135
|
+
return [2 /*return*/, null];
|
|
1136
|
+
}
|
|
1070
1137
|
});
|
|
1071
|
-
};
|
|
1072
|
-
_c.label = 1;
|
|
1073
|
-
case 1:
|
|
1074
|
-
_c.trys.push([1, 6, , 8]);
|
|
1075
|
-
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken });
|
|
1138
|
+
}); };
|
|
1076
1139
|
configuration = this.configuration;
|
|
1077
|
-
|
|
1078
|
-
|
|
1140
|
+
clientId = configuration.client_id;
|
|
1141
|
+
redirectUri = configuration.redirect_uri;
|
|
1079
1142
|
authority = configuration.authority;
|
|
1080
|
-
if (!!refreshToken) return [3 /*break*/,
|
|
1081
|
-
return [4 /*yield*/,
|
|
1082
|
-
case
|
|
1083
|
-
case
|
|
1084
|
-
|
|
1143
|
+
if (!!refreshToken) return [3 /*break*/, 2];
|
|
1144
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1145
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1146
|
+
case 2:
|
|
1147
|
+
extras = {};
|
|
1085
1148
|
if (configuration.token_request_extras) {
|
|
1086
1149
|
for (_i = 0, _a = Object.entries(configuration.token_request_extras); _i < _a.length; _i++) {
|
|
1087
1150
|
_b = _a[_i], key = _b[0], value = _b[1];
|
|
1088
|
-
|
|
1151
|
+
extras[key] = value;
|
|
1089
1152
|
}
|
|
1090
1153
|
}
|
|
1091
1154
|
return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
|
|
1092
|
-
case
|
|
1155
|
+
case 3:
|
|
1093
1156
|
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)];
|
|
1157
|
+
details = {
|
|
1158
|
+
client_id: clientId,
|
|
1159
|
+
redirect_uri: redirectUri,
|
|
1160
|
+
grant_type: appauth_1.GRANT_TYPE_REFRESH_TOKEN,
|
|
1161
|
+
refresh_token: refreshToken,
|
|
1162
|
+
};
|
|
1163
|
+
index = 0;
|
|
1164
|
+
_c.label = 4;
|
|
1165
|
+
case 4:
|
|
1166
|
+
if (!(index <= 2)) return [3 /*break*/, 15];
|
|
1167
|
+
_c.label = 5;
|
|
1145
1168
|
case 5:
|
|
1146
|
-
|
|
1147
|
-
this.publishEvent(eventNames.
|
|
1148
|
-
return [
|
|
1169
|
+
_c.trys.push([5, 13, , 14]);
|
|
1170
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, tryNumber: index });
|
|
1171
|
+
if (!(index > 1)) return [3 /*break*/, 8];
|
|
1172
|
+
_c.label = 6;
|
|
1149
1173
|
case 6:
|
|
1174
|
+
if (!document.hidden) return [3 /*break*/, 8];
|
|
1175
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1176
|
+
case 7:
|
|
1177
|
+
_c.sent();
|
|
1178
|
+
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because document is hidden" });
|
|
1179
|
+
return [3 /*break*/, 6];
|
|
1180
|
+
case 8: return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, extras)];
|
|
1181
|
+
case 9:
|
|
1182
|
+
tokenResponse = _c.sent();
|
|
1183
|
+
if (!tokenResponse.success) return [3 /*break*/, 10];
|
|
1184
|
+
this.publishEvent(eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
|
|
1185
|
+
return [2 /*return*/, tokenResponse.data];
|
|
1186
|
+
case 10:
|
|
1187
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "bad request", tokenResponse: tokenResponse });
|
|
1188
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1189
|
+
case 11: return [2 /*return*/, _c.sent()];
|
|
1190
|
+
case 12: return [3 /*break*/, 14];
|
|
1191
|
+
case 13:
|
|
1150
1192
|
exception_4 = _c.sent();
|
|
1151
1193
|
console.error(exception_4);
|
|
1152
|
-
this.publishEvent(eventNames.refreshTokensAsync_silent_error, exception_4);
|
|
1153
|
-
return [
|
|
1154
|
-
case
|
|
1155
|
-
|
|
1194
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "exception", exception: exception_4.message });
|
|
1195
|
+
return [3 /*break*/, 14];
|
|
1196
|
+
case 14:
|
|
1197
|
+
index++;
|
|
1198
|
+
return [3 /*break*/, 4];
|
|
1199
|
+
case 15: return [2 /*return*/];
|
|
1156
1200
|
}
|
|
1157
1201
|
});
|
|
1158
1202
|
});
|
|
@@ -1190,7 +1234,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1190
1234
|
case 6:
|
|
1191
1235
|
_c.trys.push([6, 11, , 12]);
|
|
1192
1236
|
this.publishEvent(eventNames.syncTokensAsync_begin, {});
|
|
1193
|
-
this.syncTokensAsyncPromise = this.
|
|
1237
|
+
this.syncTokensAsyncPromise = this.silentLoginAsync({ prompt: "none" });
|
|
1194
1238
|
return [4 /*yield*/, this.syncTokensAsyncPromise];
|
|
1195
1239
|
case 7:
|
|
1196
1240
|
silent_token_response = _c.sent();
|
|
@@ -1201,7 +1245,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1201
1245
|
_b.tokens = _c.sent();
|
|
1202
1246
|
return [3 /*break*/, 10];
|
|
1203
1247
|
case 9:
|
|
1204
|
-
this.publishEvent(eventNames.syncTokensAsync_error,
|
|
1248
|
+
this.publishEvent(eventNames.syncTokensAsync_error, { message: "no token found in result" });
|
|
1205
1249
|
if (this.timeoutId) {
|
|
1206
1250
|
timer_1.default.clearTimeout(this.timeoutId);
|
|
1207
1251
|
this.timeoutId = null;
|