@axa-fr/react-oidc 6.0.0-alpha8 → 6.0.0-beta1
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 +15 -8
- package/dist/OidcProvider.d.ts +1 -2
- package/dist/OidcProvider.d.ts.map +1 -1
- package/dist/OidcProvider.js +1 -1
- package/dist/OidcProvider.js.map +1 -1
- package/dist/core/default-component/SilentCallback.component.js +2 -2
- 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 +9 -9
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +156 -135
- package/dist/vanilla/oidc.js.map +1 -1
- package/package.json +2 -2
- package/src/oidc/OidcProvider.tsx +2 -3
- package/src/oidc/core/default-component/SilentCallback.component.tsx +2 -2
- 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/checkSessionIFrame.ts +7 -7
- package/src/oidc/vanilla/oidc.ts +105 -110
- 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;
|
|
@@ -252,7 +297,8 @@ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, f
|
|
|
252
297
|
switch (_a.label) {
|
|
253
298
|
case 0: return [4 /*yield*/, fetch(url, {
|
|
254
299
|
headers: {
|
|
255
|
-
authorization: "Bearer ".concat(accessToken)
|
|
300
|
+
authorization: "Bearer ".concat(accessToken),
|
|
301
|
+
credentials: 'same-origin'
|
|
256
302
|
}
|
|
257
303
|
})];
|
|
258
304
|
case 1:
|
|
@@ -319,10 +365,10 @@ var eventNames = {
|
|
|
319
365
|
tryKeepExistingSessionAsync_begin: "tryKeepExistingSessionAsync_begin",
|
|
320
366
|
tryKeepExistingSessionAsync_end: "tryKeepExistingSessionAsync_end",
|
|
321
367
|
tryKeepExistingSessionAsync_error: "tryKeepExistingSessionAsync_error",
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
368
|
+
silentLoginAsync_begin: "silentLoginAsync_begin",
|
|
369
|
+
silentLoginAsync: "silentLoginAsync",
|
|
370
|
+
silentLoginAsync_end: "silentLoginAsync_end",
|
|
371
|
+
silentLoginAsync_error: "silentLoginAsync_error",
|
|
326
372
|
syncTokensAsync_begin: "syncTokensAsync_begin",
|
|
327
373
|
syncTokensAsync_end: "syncTokensAsync_end",
|
|
328
374
|
syncTokensAsync_error: "syncTokensAsync_error"
|
|
@@ -342,7 +388,7 @@ var fetchFromIssuer = function (openIdIssuerUrl, timeCacheSecond) {
|
|
|
342
388
|
case 0:
|
|
343
389
|
fullUrl = "".concat(openIdIssuerUrl, "/").concat(WELL_KNOWN_PATH, "/").concat(OPENID_CONFIGURATION);
|
|
344
390
|
localStorageKey = "oidc.server:".concat(openIdIssuerUrl);
|
|
345
|
-
cacheJson = window.
|
|
391
|
+
cacheJson = window.sessionStorage.getItem(localStorageKey);
|
|
346
392
|
oneHourMinisecond = 1000 * timeCacheSecond;
|
|
347
393
|
// @ts-ignore
|
|
348
394
|
if (cacheJson && (cacheJson.timestamp + oneHourMinisecond) > Date.now()) {
|
|
@@ -357,7 +403,7 @@ var fetchFromIssuer = function (openIdIssuerUrl, timeCacheSecond) {
|
|
|
357
403
|
return [4 /*yield*/, response.json()];
|
|
358
404
|
case 2:
|
|
359
405
|
result = _a.sent();
|
|
360
|
-
window.
|
|
406
|
+
window.sessionStorage.setItem(localStorageKey, JSON.stringify({ result: result, timestamp: Date.now() }));
|
|
361
407
|
return [2 /*return*/, new OidcAuthorizationServiceConfiguration(result)];
|
|
362
408
|
}
|
|
363
409
|
});
|
|
@@ -404,6 +450,7 @@ var Oidc = /** @class */ (function () {
|
|
|
404
450
|
this.removeEventSubscription.bind(this);
|
|
405
451
|
this.publishEvent.bind(this);
|
|
406
452
|
this.destroyAsync.bind(this);
|
|
453
|
+
this.logoutAsync.bind(this);
|
|
407
454
|
}
|
|
408
455
|
Oidc.prototype.subscriveEvents = function (func) {
|
|
409
456
|
var id = getRandomInt(9999999999999).toString();
|
|
@@ -431,19 +478,19 @@ var Oidc = /** @class */ (function () {
|
|
|
431
478
|
}
|
|
432
479
|
return oidcDatabase[name];
|
|
433
480
|
};
|
|
434
|
-
Oidc.prototype.
|
|
435
|
-
if (this.configuration.silent_redirect_uri) {
|
|
481
|
+
Oidc.prototype.silentLoginCallbackFromIFrame = function () {
|
|
482
|
+
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
436
483
|
var queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
|
|
437
484
|
window.top.postMessage("".concat(this.configurationName, "_oidc_tokens:").concat(JSON.stringify({ tokens: this.tokens, sessionState: queryParams.session_state })), window.location.origin);
|
|
438
485
|
}
|
|
439
486
|
};
|
|
440
|
-
Oidc.prototype.
|
|
441
|
-
if (this.configuration.silent_redirect_uri) {
|
|
487
|
+
Oidc.prototype.silentLoginErrorCallbackFromIFrame = function () {
|
|
488
|
+
if (this.configuration.silent_redirect_uri && this.configuration.silent_login_uri) {
|
|
442
489
|
var queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
|
|
443
490
|
window.top.postMessage("".concat(this.configurationName, "_oidc_error:").concat(JSON.stringify({ error: queryParams.error })), window.location.origin);
|
|
444
491
|
}
|
|
445
492
|
};
|
|
446
|
-
Oidc.prototype.
|
|
493
|
+
Oidc.prototype.silentLoginAsync = function (extras, state, scope) {
|
|
447
494
|
if (extras === void 0) { extras = null; }
|
|
448
495
|
if (state === void 0) { state = null; }
|
|
449
496
|
if (scope === void 0) { scope = null; }
|
|
@@ -452,7 +499,7 @@ var Oidc = /** @class */ (function () {
|
|
|
452
499
|
return __generator(this, function (_c) {
|
|
453
500
|
switch (_c.label) {
|
|
454
501
|
case 0:
|
|
455
|
-
if (!this.configuration.silent_redirect_uri || !this.configuration.
|
|
502
|
+
if (!this.configuration.silent_redirect_uri || !this.configuration.silent_login_uri) {
|
|
456
503
|
return [2 /*return*/, Promise.resolve(null)];
|
|
457
504
|
}
|
|
458
505
|
_c.label = 1;
|
|
@@ -461,11 +508,11 @@ var Oidc = /** @class */ (function () {
|
|
|
461
508
|
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
462
509
|
case 2:
|
|
463
510
|
_c.sent();
|
|
464
|
-
this.publishEvent(eventNames.
|
|
511
|
+
this.publishEvent(eventNames.silentLoginAsync, { message: "wait because document is hidden" });
|
|
465
512
|
return [3 /*break*/, 1];
|
|
466
513
|
case 3:
|
|
467
514
|
try {
|
|
468
|
-
this.publishEvent(eventNames.
|
|
515
|
+
this.publishEvent(eventNames.silentLoginAsync_begin, {});
|
|
469
516
|
configuration_1 = this.configuration;
|
|
470
517
|
queries = "";
|
|
471
518
|
if (state) {
|
|
@@ -491,7 +538,7 @@ var Oidc = /** @class */ (function () {
|
|
|
491
538
|
}
|
|
492
539
|
}
|
|
493
540
|
}
|
|
494
|
-
link = configuration_1.
|
|
541
|
+
link = configuration_1.silent_login_uri + queries;
|
|
495
542
|
idx = link.indexOf("/", link.indexOf("//") + 2);
|
|
496
543
|
iFrameOrigin_1 = link.substr(0, idx);
|
|
497
544
|
iframe_1 = document.createElement('iframe');
|
|
@@ -515,14 +562,14 @@ var Oidc = /** @class */ (function () {
|
|
|
515
562
|
if (!isResolved_1) {
|
|
516
563
|
if (data.startsWith(key)) {
|
|
517
564
|
var result = JSON.parse(e.data.replace(key, ''));
|
|
518
|
-
self_1.publishEvent(eventNames.
|
|
565
|
+
self_1.publishEvent(eventNames.silentLoginAsync_end, {});
|
|
519
566
|
iframe_1.remove();
|
|
520
567
|
isResolved_1 = true;
|
|
521
568
|
resolve(result);
|
|
522
569
|
}
|
|
523
570
|
else if (data.startsWith(key_error)) {
|
|
524
571
|
var result = JSON.parse(e.data.replace(key_error, ''));
|
|
525
|
-
self_1.publishEvent(eventNames.
|
|
572
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, result);
|
|
526
573
|
iframe_1.remove();
|
|
527
574
|
isResolved_1 = true;
|
|
528
575
|
reject(result);
|
|
@@ -531,10 +578,10 @@ var Oidc = /** @class */ (function () {
|
|
|
531
578
|
}
|
|
532
579
|
}
|
|
533
580
|
};
|
|
534
|
-
var silentSigninTimeout = (_a = configuration_1.
|
|
581
|
+
var silentSigninTimeout = (_a = configuration_1.silent_login_timeout) !== null && _a !== void 0 ? _a : 12000;
|
|
535
582
|
setTimeout(function () {
|
|
536
583
|
if (!isResolved_1) {
|
|
537
|
-
self_1.publishEvent(eventNames.
|
|
584
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, "timeout");
|
|
538
585
|
iframe_1.remove();
|
|
539
586
|
isResolved_1 = true;
|
|
540
587
|
reject("timeout");
|
|
@@ -543,13 +590,13 @@ var Oidc = /** @class */ (function () {
|
|
|
543
590
|
}
|
|
544
591
|
catch (e) {
|
|
545
592
|
iframe_1.remove();
|
|
546
|
-
self_1.publishEvent(eventNames.
|
|
593
|
+
self_1.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
547
594
|
reject(e);
|
|
548
595
|
}
|
|
549
596
|
})];
|
|
550
597
|
}
|
|
551
598
|
catch (e) {
|
|
552
|
-
this.publishEvent(eventNames.
|
|
599
|
+
this.publishEvent(eventNames.silentLoginAsync_error, e);
|
|
553
600
|
throw e;
|
|
554
601
|
}
|
|
555
602
|
return [2 /*return*/];
|
|
@@ -799,7 +846,7 @@ var Oidc = /** @class */ (function () {
|
|
|
799
846
|
var _this = this;
|
|
800
847
|
return __generator(this, function (_a) {
|
|
801
848
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
802
|
-
if (_this.configuration.
|
|
849
|
+
if (_this.configuration.silent_login_uri && _this.configuration.silent_redirect_uri && _this.configuration.monitor_session && checkSessionIFrameUri && sessionState && !isSilentSignin) {
|
|
803
850
|
var checkSessionCallback = function () {
|
|
804
851
|
_this.checkSessionIFrame.stop();
|
|
805
852
|
if (_this.tokens === null) {
|
|
@@ -809,7 +856,7 @@ var Oidc = /** @class */ (function () {
|
|
|
809
856
|
var idToken = _this.tokens.idToken;
|
|
810
857
|
// @ts-ignore
|
|
811
858
|
var idTokenPayload = _this.tokens.idTokenPayload;
|
|
812
|
-
_this.
|
|
859
|
+
_this.silentLoginAsync({
|
|
813
860
|
prompt: "none",
|
|
814
861
|
id_token_hint: idToken,
|
|
815
862
|
scope: "openid"
|
|
@@ -1033,125 +1080,99 @@ var Oidc = /** @class */ (function () {
|
|
|
1033
1080
|
};
|
|
1034
1081
|
Oidc.prototype.refreshTokensAsync = function (refreshToken) {
|
|
1035
1082
|
return __awaiter(this, void 0, void 0, function () {
|
|
1036
|
-
var
|
|
1083
|
+
var localsilentLoginAsync, configuration, clientId, redirectUri, authority, extras, _i, _a, _b, key, value, oidcServerConfiguration, details, index, tokenResponse, exception_4;
|
|
1037
1084
|
var _this = this;
|
|
1038
1085
|
return __generator(this, function (_c) {
|
|
1039
1086
|
switch (_c.label) {
|
|
1040
1087
|
case 0:
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
return
|
|
1044
|
-
|
|
1045
|
-
|
|
1046
|
-
|
|
1047
|
-
|
|
1048
|
-
|
|
1049
|
-
|
|
1050
|
-
|
|
1051
|
-
|
|
1052
|
-
|
|
1053
|
-
|
|
1054
|
-
|
|
1055
|
-
|
|
1056
|
-
|
|
1057
|
-
|
|
1058
|
-
|
|
1059
|
-
|
|
1060
|
-
|
|
1061
|
-
|
|
1062
|
-
|
|
1063
|
-
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
return [2 /*return*/, null];
|
|
1067
|
-
}
|
|
1068
|
-
});
|
|
1088
|
+
localsilentLoginAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1089
|
+
var silent_token_response, exceptionSilent_1;
|
|
1090
|
+
return __generator(this, function (_a) {
|
|
1091
|
+
switch (_a.label) {
|
|
1092
|
+
case 0:
|
|
1093
|
+
_a.trys.push([0, 2, , 3]);
|
|
1094
|
+
return [4 /*yield*/, this.silentLoginAsync()];
|
|
1095
|
+
case 1:
|
|
1096
|
+
silent_token_response = _a.sent();
|
|
1097
|
+
if (silent_token_response) {
|
|
1098
|
+
return [2 /*return*/, silent_token_response.tokens];
|
|
1099
|
+
}
|
|
1100
|
+
return [3 /*break*/, 3];
|
|
1101
|
+
case 2:
|
|
1102
|
+
exceptionSilent_1 = _a.sent();
|
|
1103
|
+
console.error(exceptionSilent_1);
|
|
1104
|
+
return [3 /*break*/, 3];
|
|
1105
|
+
case 3:
|
|
1106
|
+
if (this.timeoutId) {
|
|
1107
|
+
timer_1.default.clearTimeout(this.timeoutId);
|
|
1108
|
+
this.timeoutId = null;
|
|
1109
|
+
}
|
|
1110
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token and silent refresh failed" });
|
|
1111
|
+
return [2 /*return*/, null];
|
|
1112
|
+
}
|
|
1069
1113
|
});
|
|
1070
|
-
};
|
|
1071
|
-
_c.label = 1;
|
|
1072
|
-
case 1:
|
|
1073
|
-
_c.trys.push([1, 6, , 8]);
|
|
1074
|
-
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken });
|
|
1114
|
+
}); };
|
|
1075
1115
|
configuration = this.configuration;
|
|
1076
|
-
|
|
1077
|
-
|
|
1116
|
+
clientId = configuration.client_id;
|
|
1117
|
+
redirectUri = configuration.redirect_uri;
|
|
1078
1118
|
authority = configuration.authority;
|
|
1079
|
-
if (!!refreshToken) return [3 /*break*/,
|
|
1080
|
-
return [4 /*yield*/,
|
|
1081
|
-
case
|
|
1082
|
-
case
|
|
1083
|
-
|
|
1119
|
+
if (!!refreshToken) return [3 /*break*/, 2];
|
|
1120
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1121
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
1122
|
+
case 2:
|
|
1123
|
+
extras = {};
|
|
1084
1124
|
if (configuration.token_request_extras) {
|
|
1085
1125
|
for (_i = 0, _a = Object.entries(configuration.token_request_extras); _i < _a.length; _i++) {
|
|
1086
1126
|
_b = _a[_i], key = _b[0], value = _b[1];
|
|
1087
|
-
|
|
1127
|
+
extras[key] = value;
|
|
1088
1128
|
}
|
|
1089
1129
|
}
|
|
1090
1130
|
return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
|
|
1091
|
-
case
|
|
1131
|
+
case 3:
|
|
1092
1132
|
oidcServerConfiguration = _c.sent();
|
|
1093
|
-
|
|
1094
|
-
|
|
1095
|
-
|
|
1096
|
-
|
|
1097
|
-
|
|
1098
|
-
|
|
1099
|
-
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
|
|
1103
|
-
|
|
1104
|
-
for (_i = 0, _a = Object.entries(extras_1); _i < _a.length; _i++) {
|
|
1105
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
1106
|
-
if (details[key] === undefined) {
|
|
1107
|
-
details[key] = value;
|
|
1108
|
-
}
|
|
1109
|
-
}
|
|
1110
|
-
formBody = [];
|
|
1111
|
-
for (property in details) {
|
|
1112
|
-
encodedKey = encodeURIComponent(property);
|
|
1113
|
-
encodedValue = encodeURIComponent(details[property]);
|
|
1114
|
-
formBody.push("".concat(encodedKey, "=").concat(encodedValue));
|
|
1115
|
-
}
|
|
1116
|
-
formBodyString = formBody.join("&");
|
|
1117
|
-
return [4 /*yield*/, internalFetch(url, {
|
|
1118
|
-
method: 'POST',
|
|
1119
|
-
headers: {
|
|
1120
|
-
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
1121
|
-
},
|
|
1122
|
-
body: formBodyString,
|
|
1123
|
-
})];
|
|
1124
|
-
case 1:
|
|
1125
|
-
response = _c.sent();
|
|
1126
|
-
if (response.status >= 299) {
|
|
1127
|
-
throw new Error("Error refreshing token");
|
|
1128
|
-
}
|
|
1129
|
-
return [4 /*yield*/, response.json()];
|
|
1130
|
-
case 2:
|
|
1131
|
-
result = _c.sent();
|
|
1132
|
-
return [2 /*return*/, {
|
|
1133
|
-
accessToken: result.access_token,
|
|
1134
|
-
expiresIn: result.expires_in,
|
|
1135
|
-
idToken: result.id_token,
|
|
1136
|
-
refreshToken: result.refresh_token,
|
|
1137
|
-
scope: result.scope,
|
|
1138
|
-
tokenType: result.token_type,
|
|
1139
|
-
}];
|
|
1140
|
-
}
|
|
1141
|
-
});
|
|
1142
|
-
}); };
|
|
1143
|
-
return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint)];
|
|
1133
|
+
details = {
|
|
1134
|
+
client_id: clientId,
|
|
1135
|
+
redirect_uri: redirectUri,
|
|
1136
|
+
grant_type: appauth_1.GRANT_TYPE_REFRESH_TOKEN,
|
|
1137
|
+
refresh_token: refreshToken,
|
|
1138
|
+
};
|
|
1139
|
+
index = 0;
|
|
1140
|
+
_c.label = 4;
|
|
1141
|
+
case 4:
|
|
1142
|
+
if (!(index <= 2)) return [3 /*break*/, 15];
|
|
1143
|
+
_c.label = 5;
|
|
1144
1144
|
case 5:
|
|
1145
|
-
|
|
1146
|
-
this.publishEvent(eventNames.
|
|
1147
|
-
return [
|
|
1145
|
+
_c.trys.push([5, 13, , 14]);
|
|
1146
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, tryNumber: index });
|
|
1147
|
+
if (!(index > 1)) return [3 /*break*/, 8];
|
|
1148
|
+
_c.label = 6;
|
|
1148
1149
|
case 6:
|
|
1150
|
+
if (!document.hidden) return [3 /*break*/, 8];
|
|
1151
|
+
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1152
|
+
case 7:
|
|
1153
|
+
_c.sent();
|
|
1154
|
+
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because document is hidden" });
|
|
1155
|
+
return [3 /*break*/, 6];
|
|
1156
|
+
case 8: return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, extras)];
|
|
1157
|
+
case 9:
|
|
1158
|
+
tokenResponse = _c.sent();
|
|
1159
|
+
if (!tokenResponse.success) return [3 /*break*/, 10];
|
|
1160
|
+
this.publishEvent(eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
|
|
1161
|
+
return [2 /*return*/, tokenResponse.data];
|
|
1162
|
+
case 10:
|
|
1163
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "bad request", tokenResponse: tokenResponse });
|
|
1164
|
+
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1165
|
+
case 11: return [2 /*return*/, _c.sent()];
|
|
1166
|
+
case 12: return [3 /*break*/, 14];
|
|
1167
|
+
case 13:
|
|
1149
1168
|
exception_4 = _c.sent();
|
|
1150
1169
|
console.error(exception_4);
|
|
1151
|
-
this.publishEvent(eventNames.refreshTokensAsync_silent_error, exception_4);
|
|
1152
|
-
return [
|
|
1153
|
-
case
|
|
1154
|
-
|
|
1170
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "exception", exception: exception_4.message });
|
|
1171
|
+
return [3 /*break*/, 14];
|
|
1172
|
+
case 14:
|
|
1173
|
+
index++;
|
|
1174
|
+
return [3 /*break*/, 4];
|
|
1175
|
+
case 15: return [2 /*return*/];
|
|
1155
1176
|
}
|
|
1156
1177
|
});
|
|
1157
1178
|
});
|
|
@@ -1189,7 +1210,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1189
1210
|
case 6:
|
|
1190
1211
|
_c.trys.push([6, 11, , 12]);
|
|
1191
1212
|
this.publishEvent(eventNames.syncTokensAsync_begin, {});
|
|
1192
|
-
this.syncTokensAsyncPromise = this.
|
|
1213
|
+
this.syncTokensAsyncPromise = this.silentLoginAsync({ prompt: "none" });
|
|
1193
1214
|
return [4 /*yield*/, this.syncTokensAsyncPromise];
|
|
1194
1215
|
case 7:
|
|
1195
1216
|
silent_token_response = _c.sent();
|
|
@@ -1200,7 +1221,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1200
1221
|
_b.tokens = _c.sent();
|
|
1201
1222
|
return [3 /*break*/, 10];
|
|
1202
1223
|
case 9:
|
|
1203
|
-
this.publishEvent(eventNames.syncTokensAsync_error,
|
|
1224
|
+
this.publishEvent(eventNames.syncTokensAsync_error, { message: "no token found in result" });
|
|
1204
1225
|
if (this.timeoutId) {
|
|
1205
1226
|
timer_1.default.clearTimeout(this.timeoutId);
|
|
1206
1227
|
this.timeoutId = null;
|