@axa-fr/react-oidc 6.4.1 → 6.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/OidcSecure.js +3 -3
- package/dist/OidcSecure.js.map +1 -1
- package/dist/ReactOidc.d.ts +2 -2
- package/dist/ReactOidc.d.ts.map +1 -1
- package/dist/ReactOidc.js +7 -6
- package/dist/ReactOidc.js.map +1 -1
- package/dist/core/default-component/SilentLogin.component.js +1 -1
- package/dist/core/default-component/SilentLogin.component.js.map +1 -1
- package/dist/vanilla/oidc.d.ts +3 -5
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +144 -112
- package/dist/vanilla/oidc.js.map +1 -1
- package/package.json +10 -10
- package/src/oidc/OidcSecure.tsx +3 -3
- package/src/oidc/ReactOidc.tsx +5 -5
- package/src/oidc/core/default-component/SilentLogin.component.tsx +1 -1
- package/src/oidc/vanilla/oidc.ts +66 -41
package/dist/vanilla/oidc.js
CHANGED
|
@@ -98,7 +98,6 @@ var performTokenRequestAsync = function (url, details, extras, oldTokens) { retu
|
|
|
98
98
|
headers: {
|
|
99
99
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
100
100
|
},
|
|
101
|
-
//mode: 'cors',
|
|
102
101
|
body: formBodyString,
|
|
103
102
|
})];
|
|
104
103
|
case 1:
|
|
@@ -184,37 +183,43 @@ var loginCallbackWithAutoTokensRenewAsync = function (oidc) { return __awaiter(v
|
|
|
184
183
|
}
|
|
185
184
|
});
|
|
186
185
|
}); };
|
|
187
|
-
function renewTokensAndStartTimerAsync(oidc, refreshToken, forceRefresh) {
|
|
186
|
+
function renewTokensAndStartTimerAsync(oidc, refreshToken, forceRefresh, extras) {
|
|
188
187
|
if (forceRefresh === void 0) { forceRefresh = false; }
|
|
188
|
+
if (extras === void 0) { extras = null; }
|
|
189
189
|
return __awaiter(this, void 0, void 0, function () {
|
|
190
|
-
var _a, tokens, status;
|
|
190
|
+
var _a, tokens, status, serviceWorker, session;
|
|
191
191
|
return __generator(this, function (_b) {
|
|
192
192
|
switch (_b.label) {
|
|
193
|
-
case 0: return [4 /*yield*/, oidc.synchroniseTokensAsync(refreshToken, 0, forceRefresh)];
|
|
193
|
+
case 0: return [4 /*yield*/, oidc.synchroniseTokensAsync(refreshToken, 0, forceRefresh, extras)];
|
|
194
194
|
case 1:
|
|
195
195
|
_a = _b.sent(), tokens = _a.tokens, status = _a.status;
|
|
196
196
|
oidc.tokens = tokens;
|
|
197
|
-
|
|
198
|
-
return [4 /*yield*/, oidc.session.setTokens(oidc.tokens)];
|
|
197
|
+
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(oidc.configuration.service_worker_relative_url, oidc.configurationName)];
|
|
199
198
|
case 2:
|
|
200
|
-
_b.sent();
|
|
201
|
-
|
|
199
|
+
serviceWorker = _b.sent();
|
|
200
|
+
if (!!serviceWorker) return [3 /*break*/, 4];
|
|
201
|
+
session = (0, initSession_1.initSession)(this.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
|
|
202
|
+
return [4 /*yield*/, session.setTokens(oidc.tokens)];
|
|
202
203
|
case 3:
|
|
203
|
-
|
|
204
|
-
|
|
204
|
+
_b.sent();
|
|
205
|
+
_b.label = 4;
|
|
205
206
|
case 4:
|
|
207
|
+
if (!!oidc.tokens) return [3 /*break*/, 6];
|
|
208
|
+
return [4 /*yield*/, oidc.destroyAsync(status)];
|
|
209
|
+
case 5:
|
|
206
210
|
_b.sent();
|
|
207
211
|
return [2 /*return*/];
|
|
208
|
-
case
|
|
212
|
+
case 6:
|
|
209
213
|
if (oidc.timeoutId) {
|
|
210
|
-
oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt);
|
|
214
|
+
oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt, extras);
|
|
211
215
|
}
|
|
212
216
|
return [2 /*return*/];
|
|
213
217
|
}
|
|
214
218
|
});
|
|
215
219
|
});
|
|
216
220
|
}
|
|
217
|
-
var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
|
|
221
|
+
var autoRenewTokens = function (oidc, refreshToken, expiresAt, extras) {
|
|
222
|
+
if (extras === void 0) { extras = null; }
|
|
218
223
|
var refreshTimeBeforeTokensExpirationInSecond = oidc.configuration.refresh_time_before_tokens_expiration_in_second;
|
|
219
224
|
return timer_1.default.setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
|
|
220
225
|
var timeLeft, timeInfo;
|
|
@@ -224,7 +229,7 @@ var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
|
|
|
224
229
|
timeLeft = (0, parseTokens_1.computeTimeLeft)(refreshTimeBeforeTokensExpirationInSecond, expiresAt);
|
|
225
230
|
timeInfo = { timeLeft: timeLeft };
|
|
226
231
|
oidc.publishEvent(Oidc.eventNames.token_timer, timeInfo);
|
|
227
|
-
return [4 /*yield*/, renewTokensAndStartTimerAsync(oidc, refreshToken)];
|
|
232
|
+
return [4 /*yield*/, renewTokensAndStartTimerAsync(oidc, refreshToken, false, extras)];
|
|
228
233
|
case 1:
|
|
229
234
|
_a.sent();
|
|
230
235
|
return [2 /*return*/];
|
|
@@ -281,7 +286,6 @@ var userInfoAsync = function (oidc) { return __awaiter(void 0, void 0, void 0, f
|
|
|
281
286
|
case 0: return [4 /*yield*/, fetch(url, {
|
|
282
287
|
headers: {
|
|
283
288
|
authorization: "Bearer ".concat(accessToken),
|
|
284
|
-
// credentials: 'include'
|
|
285
289
|
}
|
|
286
290
|
})];
|
|
287
291
|
case 1:
|
|
@@ -411,8 +415,6 @@ var Oidc = /** @class */ (function () {
|
|
|
411
415
|
this.userInfo = null;
|
|
412
416
|
this.events = [];
|
|
413
417
|
this.timeoutId = null;
|
|
414
|
-
this.serviceWorker = null;
|
|
415
|
-
this.session = null;
|
|
416
418
|
this.synchroniseTokensAsync.bind(this);
|
|
417
419
|
this.loginCallbackWithAutoTokensRenewAsync.bind(this);
|
|
418
420
|
this.initAsync.bind(this);
|
|
@@ -665,7 +667,6 @@ var Oidc = /** @class */ (function () {
|
|
|
665
667
|
serviceWorker.startKeepAliveServiceWorker();
|
|
666
668
|
// @ts-ignore
|
|
667
669
|
this.tokens = tokens;
|
|
668
|
-
this.serviceWorker = serviceWorker;
|
|
669
670
|
// @ts-ignore
|
|
670
671
|
this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt);
|
|
671
672
|
return [4 /*yield*/, serviceWorker.getSessionStateAsync()];
|
|
@@ -699,9 +700,7 @@ var Oidc = /** @class */ (function () {
|
|
|
699
700
|
tokens = (_b.sent()).tokens;
|
|
700
701
|
if (!tokens) return [3 /*break*/, 11];
|
|
701
702
|
// @ts-ignore
|
|
702
|
-
this.tokens = (0, parseTokens_1.setTokens)(tokens
|
|
703
|
-
//session.setTokens(this.tokens);
|
|
704
|
-
this.session = session;
|
|
703
|
+
this.tokens = (0, parseTokens_1.setTokens)(tokens);
|
|
705
704
|
// @ts-ignore
|
|
706
705
|
this.timeoutId = autoRenewTokens(this, tokens.refreshToken, this.tokens.expiresAt);
|
|
707
706
|
sessionState = session.getSessionState();
|
|
@@ -744,12 +743,12 @@ var Oidc = /** @class */ (function () {
|
|
|
744
743
|
});
|
|
745
744
|
});
|
|
746
745
|
};
|
|
747
|
-
Oidc.prototype.loginAsync = function (callbackPath, extras,
|
|
746
|
+
Oidc.prototype.loginAsync = function (callbackPath, extras, isSilentSignin, scope, silentLoginOnly) {
|
|
748
747
|
if (callbackPath === void 0) { callbackPath = undefined; }
|
|
749
748
|
if (extras === void 0) { extras = null; }
|
|
750
|
-
if (state === void 0) { state = undefined; }
|
|
751
749
|
if (isSilentSignin === void 0) { isSilentSignin = false; }
|
|
752
750
|
if (scope === void 0) { scope = undefined; }
|
|
751
|
+
if (silentLoginOnly === void 0) { silentLoginOnly = false; }
|
|
753
752
|
return __awaiter(this, void 0, void 0, function () {
|
|
754
753
|
var loginLocalAsync;
|
|
755
754
|
var _this = this;
|
|
@@ -758,16 +757,43 @@ var Oidc = /** @class */ (function () {
|
|
|
758
757
|
return [2 /*return*/, this.loginPromise];
|
|
759
758
|
}
|
|
760
759
|
loginLocalAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
761
|
-
var
|
|
762
|
-
var _a;
|
|
763
|
-
return __generator(this, function (
|
|
764
|
-
switch (
|
|
760
|
+
var location, url, configuration, state, extraFinal, silentResult, e_2, redirectUri, randomString, extraFinal, nonce, serviceWorker, oidcServerConfiguration, storage, session, queryStringUtil, authorizationHandler, authRequest, exception_2;
|
|
761
|
+
var _a, _b;
|
|
762
|
+
return __generator(this, function (_c) {
|
|
763
|
+
switch (_c.label) {
|
|
765
764
|
case 0:
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
url = callbackPath || location_1.pathname + (location_1.search || '') + (location_1.hash || '');
|
|
769
|
-
this.publishEvent(eventNames.loginAsync_begin, {});
|
|
765
|
+
location = window.location;
|
|
766
|
+
url = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
|
|
770
767
|
configuration = this.configuration;
|
|
768
|
+
state = undefined;
|
|
769
|
+
if (extras && "state" in extras) {
|
|
770
|
+
state = extras["state"];
|
|
771
|
+
delete extras["state"];
|
|
772
|
+
}
|
|
773
|
+
if (!silentLoginOnly) return [3 /*break*/, 4];
|
|
774
|
+
_c.label = 1;
|
|
775
|
+
case 1:
|
|
776
|
+
_c.trys.push([1, 3, , 4]);
|
|
777
|
+
extraFinal = (_a = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _a !== void 0 ? _a : {};
|
|
778
|
+
return [4 /*yield*/, this.silentLoginAsync(__assign(__assign({}, extraFinal), { prompt: "none" }), state, scope)];
|
|
779
|
+
case 2:
|
|
780
|
+
silentResult = _c.sent();
|
|
781
|
+
if (silentResult) {
|
|
782
|
+
this.tokens = silentResult.tokens;
|
|
783
|
+
this.publishEvent(eventNames.token_aquired, {});
|
|
784
|
+
// @ts-ignore
|
|
785
|
+
this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt, extras);
|
|
786
|
+
return [2 /*return*/, {}];
|
|
787
|
+
}
|
|
788
|
+
return [3 /*break*/, 4];
|
|
789
|
+
case 3:
|
|
790
|
+
e_2 = _c.sent();
|
|
791
|
+
return [2 /*return*/, e_2];
|
|
792
|
+
case 4:
|
|
793
|
+
this.publishEvent(eventNames.loginAsync_begin, {});
|
|
794
|
+
_c.label = 5;
|
|
795
|
+
case 5:
|
|
796
|
+
_c.trys.push([5, 14, , 15]);
|
|
771
797
|
redirectUri = isSilentSignin ? configuration.silent_redirect_uri : configuration.redirect_uri;
|
|
772
798
|
if (!scope) {
|
|
773
799
|
scope = configuration.scope;
|
|
@@ -781,39 +807,39 @@ var Oidc = /** @class */ (function () {
|
|
|
781
807
|
return text;
|
|
782
808
|
};
|
|
783
809
|
setLoginParams(this.configurationName, redirectUri, { callbackPath: url, extras: extras, state: state });
|
|
784
|
-
extraFinal = (
|
|
810
|
+
extraFinal = (_b = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _b !== void 0 ? _b : {};
|
|
785
811
|
if (!extraFinal.nonce) {
|
|
786
812
|
extraFinal["nonce"] = randomString(12);
|
|
787
813
|
}
|
|
788
814
|
nonce = { "nonce": extraFinal.nonce };
|
|
789
815
|
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
|
|
790
|
-
case
|
|
791
|
-
serviceWorker =
|
|
816
|
+
case 6:
|
|
817
|
+
serviceWorker = _c.sent();
|
|
792
818
|
return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
|
|
793
|
-
case
|
|
794
|
-
oidcServerConfiguration =
|
|
819
|
+
case 7:
|
|
820
|
+
oidcServerConfiguration = _c.sent();
|
|
795
821
|
storage = void 0;
|
|
796
|
-
if (!serviceWorker) return [3 /*break*/,
|
|
822
|
+
if (!serviceWorker) return [3 /*break*/, 11];
|
|
797
823
|
serviceWorker.startKeepAliveServiceWorker();
|
|
798
824
|
return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "loginAsync")];
|
|
799
|
-
case
|
|
800
|
-
|
|
825
|
+
case 8:
|
|
826
|
+
_c.sent();
|
|
801
827
|
return [4 /*yield*/, serviceWorker.setNonceAsync(nonce)];
|
|
802
|
-
case
|
|
803
|
-
|
|
828
|
+
case 9:
|
|
829
|
+
_c.sent();
|
|
804
830
|
storage = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker.saveItemsAsync, {});
|
|
805
831
|
return [4 /*yield*/, storage.setItem("dummy", {})];
|
|
806
|
-
case
|
|
807
|
-
|
|
808
|
-
return [3 /*break*/,
|
|
809
|
-
case
|
|
832
|
+
case 10:
|
|
833
|
+
_c.sent();
|
|
834
|
+
return [3 /*break*/, 13];
|
|
835
|
+
case 11:
|
|
810
836
|
session = (0, initSession_1.initSession)(this.configurationName, redirectUri);
|
|
811
837
|
return [4 /*yield*/, session.setNonceAsync(nonce)];
|
|
812
|
-
case
|
|
813
|
-
|
|
838
|
+
case 12:
|
|
839
|
+
_c.sent();
|
|
814
840
|
storage = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, {});
|
|
815
|
-
|
|
816
|
-
case
|
|
841
|
+
_c.label = 13;
|
|
842
|
+
case 13:
|
|
817
843
|
queryStringUtil = redirectUri.includes("#") ? new noHashQueryStringUtils_1.HashQueryStringUtils() : new noHashQueryStringUtils_1.NoHashQueryStringUtils();
|
|
818
844
|
authorizationHandler = new appauth_1.RedirectRequestHandler(storage, queryStringUtil, window.location, new appauth_1.DefaultCrypto());
|
|
819
845
|
authRequest = new appauth_1.AuthorizationRequest({
|
|
@@ -825,12 +851,12 @@ var Oidc = /** @class */ (function () {
|
|
|
825
851
|
extras: extraFinal
|
|
826
852
|
});
|
|
827
853
|
authorizationHandler.performAuthorizationRequest(oidcServerConfiguration, authRequest);
|
|
828
|
-
return [3 /*break*/,
|
|
829
|
-
case
|
|
830
|
-
exception_2 =
|
|
854
|
+
return [3 /*break*/, 15];
|
|
855
|
+
case 14:
|
|
856
|
+
exception_2 = _c.sent();
|
|
831
857
|
this.publishEvent(eventNames.loginAsync_error, exception_2);
|
|
832
858
|
throw exception_2;
|
|
833
|
-
case
|
|
859
|
+
case 15: return [2 /*return*/];
|
|
834
860
|
}
|
|
835
861
|
});
|
|
836
862
|
}); };
|
|
@@ -928,7 +954,7 @@ var Oidc = /** @class */ (function () {
|
|
|
928
954
|
return [2 /*return*/, this.loginCallbackPromise];
|
|
929
955
|
}
|
|
930
956
|
loginCallbackLocalAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
931
|
-
var response, tokens, parsedTokens;
|
|
957
|
+
var response, tokens, parsedTokens, oidc, serviceWorker, session;
|
|
932
958
|
return __generator(this, function (_a) {
|
|
933
959
|
switch (_a.label) {
|
|
934
960
|
case 0: return [4 /*yield*/, this._loginCallbackAsync(isSilenSignin)];
|
|
@@ -937,12 +963,17 @@ var Oidc = /** @class */ (function () {
|
|
|
937
963
|
tokens = response.tokens;
|
|
938
964
|
parsedTokens = (0, parseTokens_1.setTokens)(tokens);
|
|
939
965
|
this.tokens = parsedTokens;
|
|
940
|
-
|
|
941
|
-
return [4 /*yield*/,
|
|
966
|
+
oidc = this;
|
|
967
|
+
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(oidc.configuration.service_worker_relative_url, oidc.configurationName)];
|
|
942
968
|
case 2:
|
|
943
|
-
_a.sent();
|
|
944
|
-
|
|
969
|
+
serviceWorker = _a.sent();
|
|
970
|
+
if (!!serviceWorker) return [3 /*break*/, 4];
|
|
971
|
+
session = (0, initSession_1.initSession)(this.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
|
|
972
|
+
return [4 /*yield*/, session.setTokens(parsedTokens)];
|
|
945
973
|
case 3:
|
|
974
|
+
_a.sent();
|
|
975
|
+
_a.label = 4;
|
|
976
|
+
case 4:
|
|
946
977
|
this.publishEvent(Oidc.eventNames.token_aquired, parsedTokens);
|
|
947
978
|
// @ts-ignore
|
|
948
979
|
return [2 /*return*/, { parsedTokens: parsedTokens, state: response.state, callbackPath: response.callbackPath }];
|
|
@@ -958,15 +989,14 @@ var Oidc = /** @class */ (function () {
|
|
|
958
989
|
});
|
|
959
990
|
};
|
|
960
991
|
Oidc.prototype._loginCallbackAsync = function (isSilentSignin) {
|
|
961
|
-
var _a;
|
|
962
992
|
if (isSilentSignin === void 0) { isSilentSignin = false; }
|
|
963
993
|
return __awaiter(this, void 0, void 0, function () {
|
|
964
994
|
var configuration_2, clientId_1, redirectUri_1, authority, tokenRequestTimeout_1, oidcServerConfiguration_1, queryParams, sessionState_2, serviceWorker_1, storage_1, nonceData_1, items, dummy, session, items, exception_3;
|
|
965
995
|
var _this = this;
|
|
966
|
-
return __generator(this, function (
|
|
967
|
-
switch (
|
|
996
|
+
return __generator(this, function (_a) {
|
|
997
|
+
switch (_a.label) {
|
|
968
998
|
case 0:
|
|
969
|
-
|
|
999
|
+
_a.trys.push([0, 13, , 14]);
|
|
970
1000
|
this.publishEvent(eventNames.loginCallbackAsync_begin, {});
|
|
971
1001
|
configuration_2 = this.configuration;
|
|
972
1002
|
clientId_1 = configuration_2.client_id;
|
|
@@ -975,52 +1005,50 @@ var Oidc = /** @class */ (function () {
|
|
|
975
1005
|
tokenRequestTimeout_1 = configuration_2.token_request_timeout;
|
|
976
1006
|
return [4 /*yield*/, this.initAsync(authority, configuration_2.authority_configuration)];
|
|
977
1007
|
case 1:
|
|
978
|
-
oidcServerConfiguration_1 =
|
|
1008
|
+
oidcServerConfiguration_1 = _a.sent();
|
|
979
1009
|
queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
|
|
980
1010
|
sessionState_2 = queryParams.session_state;
|
|
981
1011
|
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration_2.service_worker_relative_url, this.configurationName)];
|
|
982
1012
|
case 2:
|
|
983
|
-
serviceWorker_1 =
|
|
1013
|
+
serviceWorker_1 = _a.sent();
|
|
984
1014
|
storage_1 = null;
|
|
985
1015
|
nonceData_1 = null;
|
|
986
1016
|
if (!serviceWorker_1) return [3 /*break*/, 9];
|
|
987
1017
|
serviceWorker_1.startKeepAliveServiceWorker();
|
|
988
|
-
this.serviceWorker = serviceWorker_1;
|
|
989
1018
|
return [4 /*yield*/, serviceWorker_1.initAsync(oidcServerConfiguration_1, "loginCallbackAsync")];
|
|
990
1019
|
case 3:
|
|
991
|
-
|
|
1020
|
+
_a.sent();
|
|
992
1021
|
return [4 /*yield*/, serviceWorker_1.loadItemsAsync()];
|
|
993
1022
|
case 4:
|
|
994
|
-
items =
|
|
1023
|
+
items = _a.sent();
|
|
995
1024
|
storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker_1.saveItemsAsync, items);
|
|
996
1025
|
return [4 /*yield*/, storage_1.getItem("dummy")];
|
|
997
1026
|
case 5:
|
|
998
|
-
dummy =
|
|
1027
|
+
dummy = _a.sent();
|
|
999
1028
|
if (!dummy) {
|
|
1000
1029
|
throw new Error("Service Worker storage disapear");
|
|
1001
1030
|
}
|
|
1002
1031
|
return [4 /*yield*/, storage_1.removeItem("dummy")];
|
|
1003
1032
|
case 6:
|
|
1004
|
-
|
|
1033
|
+
_a.sent();
|
|
1005
1034
|
return [4 /*yield*/, serviceWorker_1.setSessionStateAsync(sessionState_2)];
|
|
1006
1035
|
case 7:
|
|
1007
|
-
|
|
1036
|
+
_a.sent();
|
|
1008
1037
|
return [4 /*yield*/, serviceWorker_1.getNonceAsync()];
|
|
1009
1038
|
case 8:
|
|
1010
|
-
nonceData_1 =
|
|
1039
|
+
nonceData_1 = _a.sent();
|
|
1011
1040
|
return [3 /*break*/, 12];
|
|
1012
1041
|
case 9:
|
|
1013
|
-
this.session = (0, initSession_1.initSession)(this.configurationName, redirectUri_1, (_a = configuration_2.storage) !== null && _a !== void 0 ? _a : sessionStorage);
|
|
1014
1042
|
session = (0, initSession_1.initSession)(this.configurationName, redirectUri_1);
|
|
1015
1043
|
session.setSessionState(sessionState_2);
|
|
1016
1044
|
return [4 /*yield*/, session.loadItemsAsync()];
|
|
1017
1045
|
case 10:
|
|
1018
|
-
items =
|
|
1046
|
+
items = _a.sent();
|
|
1019
1047
|
storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, items);
|
|
1020
1048
|
return [4 /*yield*/, session.getNonceAsync()];
|
|
1021
1049
|
case 11:
|
|
1022
|
-
nonceData_1 =
|
|
1023
|
-
|
|
1050
|
+
nonceData_1 = _a.sent();
|
|
1051
|
+
_a.label = 12;
|
|
1024
1052
|
case 12: return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
1025
1053
|
// @ts-ignore
|
|
1026
1054
|
var queryStringUtil = new noHashQueryStringUtils_1.NoHashQueryStringUtils();
|
|
@@ -1124,7 +1152,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1124
1152
|
authorizationHandler.completeAuthorizationRequestIfPossible();
|
|
1125
1153
|
})];
|
|
1126
1154
|
case 13:
|
|
1127
|
-
exception_3 =
|
|
1155
|
+
exception_3 = _a.sent();
|
|
1128
1156
|
console.error(exception_3);
|
|
1129
1157
|
this.publishEvent(eventNames.loginCallbackAsync_error, exception_3);
|
|
1130
1158
|
throw exception_3;
|
|
@@ -1133,34 +1161,38 @@ var Oidc = /** @class */ (function () {
|
|
|
1133
1161
|
});
|
|
1134
1162
|
});
|
|
1135
1163
|
};
|
|
1136
|
-
Oidc.prototype.synchroniseTokensAsync = function (refreshToken, index, forceRefresh) {
|
|
1164
|
+
Oidc.prototype.synchroniseTokensAsync = function (refreshToken, index, forceRefresh, extras) {
|
|
1137
1165
|
if (index === void 0) { index = 0; }
|
|
1138
1166
|
if (forceRefresh === void 0) { forceRefresh = false; }
|
|
1167
|
+
if (extras === void 0) { extras = null; }
|
|
1139
1168
|
return __awaiter(this, void 0, void 0, function () {
|
|
1140
|
-
var numberTryOnline, configuration, localsilentLoginAsync, _a, status_1, tokens, _b, clientId, redirectUri, authority,
|
|
1169
|
+
var numberTryOnline, configuration, localsilentLoginAsync, _a, status_1, tokens, _b, clientId, redirectUri, authority, tokenExtras, finalExtras, details, oidcServerConfiguration, tokenResponse, exception_4;
|
|
1141
1170
|
var _this = this;
|
|
1142
|
-
return __generator(this, function (
|
|
1143
|
-
switch (
|
|
1171
|
+
return __generator(this, function (_c) {
|
|
1172
|
+
switch (_c.label) {
|
|
1144
1173
|
case 0:
|
|
1145
1174
|
if (!document.hidden) return [3 /*break*/, 3];
|
|
1146
1175
|
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1147
1176
|
case 1:
|
|
1148
|
-
|
|
1177
|
+
_c.sent();
|
|
1149
1178
|
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because document is hidden" });
|
|
1150
1179
|
return [4 /*yield*/, this.synchroniseTokensAsync(refreshToken, index, forceRefresh)];
|
|
1151
|
-
case 2: return [2 /*return*/,
|
|
1180
|
+
case 2: return [2 /*return*/, _c.sent()];
|
|
1152
1181
|
case 3:
|
|
1153
1182
|
numberTryOnline = 6;
|
|
1154
|
-
|
|
1183
|
+
_c.label = 4;
|
|
1155
1184
|
case 4:
|
|
1156
1185
|
if (!(!navigator.onLine && numberTryOnline > 0)) return [3 /*break*/, 6];
|
|
1157
1186
|
return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
|
|
1158
1187
|
case 5:
|
|
1159
|
-
|
|
1188
|
+
_c.sent();
|
|
1160
1189
|
numberTryOnline--;
|
|
1161
1190
|
this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because navigator is offline try ".concat(numberTryOnline) });
|
|
1162
1191
|
return [3 /*break*/, 4];
|
|
1163
1192
|
case 6:
|
|
1193
|
+
if (!extras) {
|
|
1194
|
+
extras = {};
|
|
1195
|
+
}
|
|
1164
1196
|
configuration = this.configuration;
|
|
1165
1197
|
localsilentLoginAsync = function () { return __awaiter(_this, void 0, void 0, function () {
|
|
1166
1198
|
var loginParams, silent_token_response, exceptionSilent_1;
|
|
@@ -1169,7 +1201,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1169
1201
|
case 0:
|
|
1170
1202
|
_a.trys.push([0, 2, , 4]);
|
|
1171
1203
|
loginParams = getLoginParams(this.configurationName, configuration.redirect_uri);
|
|
1172
|
-
return [4 /*yield*/, this.silentLoginAsync(__assign(__assign({}, loginParams.extras), { prompt: "none" }), loginParams.state)];
|
|
1204
|
+
return [4 /*yield*/, this.silentLoginAsync(__assign(__assign(__assign({}, loginParams.extras), extras), { prompt: "none" }), loginParams.state)];
|
|
1173
1205
|
case 1:
|
|
1174
1206
|
silent_token_response = _a.sent();
|
|
1175
1207
|
if (silent_token_response) {
|
|
@@ -1196,12 +1228,12 @@ var Oidc = /** @class */ (function () {
|
|
|
1196
1228
|
});
|
|
1197
1229
|
}); };
|
|
1198
1230
|
if (!(index <= 4)) return [3 /*break*/, 25];
|
|
1199
|
-
|
|
1231
|
+
_c.label = 7;
|
|
1200
1232
|
case 7:
|
|
1201
|
-
|
|
1233
|
+
_c.trys.push([7, 24, , 25]);
|
|
1202
1234
|
return [4 /*yield*/, this.syncTokensInfoAsync(configuration, this.configurationName, this.tokens, forceRefresh)];
|
|
1203
1235
|
case 8:
|
|
1204
|
-
_a =
|
|
1236
|
+
_a = _c.sent(), status_1 = _a.status, tokens = _a.tokens;
|
|
1205
1237
|
_b = status_1;
|
|
1206
1238
|
switch (_b) {
|
|
1207
1239
|
case "SESSION_LOST": return [3 /*break*/, 9];
|
|
@@ -1226,24 +1258,19 @@ var Oidc = /** @class */ (function () {
|
|
|
1226
1258
|
case 14:
|
|
1227
1259
|
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, status: status_1, tryNumber: index });
|
|
1228
1260
|
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1229
|
-
case 15: return [2 /*return*/,
|
|
1261
|
+
case 15: return [2 /*return*/, _c.sent()];
|
|
1230
1262
|
case 16:
|
|
1231
1263
|
if (!!refreshToken) return [3 /*break*/, 18];
|
|
1232
1264
|
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, tryNumber: index });
|
|
1233
1265
|
return [4 /*yield*/, localsilentLoginAsync()];
|
|
1234
|
-
case 17: return [2 /*return*/,
|
|
1266
|
+
case 17: return [2 /*return*/, _c.sent()];
|
|
1235
1267
|
case 18:
|
|
1236
1268
|
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, status: status_1, tryNumber: index });
|
|
1237
1269
|
clientId = configuration.client_id;
|
|
1238
1270
|
redirectUri = configuration.redirect_uri;
|
|
1239
1271
|
authority = configuration.authority;
|
|
1240
|
-
|
|
1241
|
-
|
|
1242
|
-
for (_i = 0, _c = Object.entries(configuration.token_request_extras); _i < _c.length; _i++) {
|
|
1243
|
-
_d = _c[_i], key = _d[0], value = _d[1];
|
|
1244
|
-
extras[key] = value;
|
|
1245
|
-
}
|
|
1246
|
-
}
|
|
1272
|
+
tokenExtras = configuration.token_request_extras ? configuration.token_request_extras : {};
|
|
1273
|
+
finalExtras = __assign(__assign({}, tokenExtras), extras);
|
|
1247
1274
|
details = {
|
|
1248
1275
|
client_id: clientId,
|
|
1249
1276
|
redirect_uri: redirectUri,
|
|
@@ -1252,10 +1279,10 @@ var Oidc = /** @class */ (function () {
|
|
|
1252
1279
|
};
|
|
1253
1280
|
return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
|
|
1254
1281
|
case 19:
|
|
1255
|
-
oidcServerConfiguration =
|
|
1256
|
-
return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details,
|
|
1282
|
+
oidcServerConfiguration = _c.sent();
|
|
1283
|
+
return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens)];
|
|
1257
1284
|
case 20:
|
|
1258
|
-
tokenResponse =
|
|
1285
|
+
tokenResponse = _c.sent();
|
|
1259
1286
|
if (!tokenResponse.success) return [3 /*break*/, 21];
|
|
1260
1287
|
if (!(0, parseTokens_1.isTokensOidcValid)(tokenResponse.data, null, oidcServerConfiguration)) {
|
|
1261
1288
|
this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token return not valid tokens" });
|
|
@@ -1270,10 +1297,10 @@ var Oidc = /** @class */ (function () {
|
|
|
1270
1297
|
tokenResponse: tokenResponse
|
|
1271
1298
|
});
|
|
1272
1299
|
return [4 /*yield*/, this.synchroniseTokensAsync(null, index + 1, forceRefresh)];
|
|
1273
|
-
case 22: return [2 /*return*/,
|
|
1300
|
+
case 22: return [2 /*return*/, _c.sent()];
|
|
1274
1301
|
case 23: return [3 /*break*/, 25];
|
|
1275
1302
|
case 24:
|
|
1276
|
-
exception_4 =
|
|
1303
|
+
exception_4 = _c.sent();
|
|
1277
1304
|
console.error(exception_4);
|
|
1278
1305
|
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "exception", exception: exception_4.message });
|
|
1279
1306
|
return [2 /*return*/, this.synchroniseTokensAsync(refreshToken, index + 1, forceRefresh)];
|
|
@@ -1372,7 +1399,8 @@ var Oidc = /** @class */ (function () {
|
|
|
1372
1399
|
return result;
|
|
1373
1400
|
});
|
|
1374
1401
|
};
|
|
1375
|
-
Oidc.prototype.renewTokensAsync = function () {
|
|
1402
|
+
Oidc.prototype.renewTokensAsync = function (extras) {
|
|
1403
|
+
if (extras === void 0) { extras = null; }
|
|
1376
1404
|
return __awaiter(this, void 0, void 0, function () {
|
|
1377
1405
|
return __generator(this, function (_a) {
|
|
1378
1406
|
switch (_a.label) {
|
|
@@ -1382,7 +1410,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1382
1410
|
}
|
|
1383
1411
|
timer_1.default.clearTimeout(this.timeoutId);
|
|
1384
1412
|
// @ts-ignore
|
|
1385
|
-
return [4 /*yield*/, renewTokensAndStartTimerAsync(this, this.tokens.refreshToken, true)];
|
|
1413
|
+
return [4 /*yield*/, renewTokensAndStartTimerAsync(this, this.tokens.refreshToken, true, extras)];
|
|
1386
1414
|
case 1:
|
|
1387
1415
|
// @ts-ignore
|
|
1388
1416
|
_a.sent();
|
|
@@ -1393,6 +1421,7 @@ var Oidc = /** @class */ (function () {
|
|
|
1393
1421
|
};
|
|
1394
1422
|
Oidc.prototype.destroyAsync = function (status) {
|
|
1395
1423
|
return __awaiter(this, void 0, void 0, function () {
|
|
1424
|
+
var oidc, serviceWorker, session;
|
|
1396
1425
|
return __generator(this, function (_a) {
|
|
1397
1426
|
switch (_a.label) {
|
|
1398
1427
|
case 0:
|
|
@@ -1401,18 +1430,21 @@ var Oidc = /** @class */ (function () {
|
|
|
1401
1430
|
if (this.checkSessionIFrame) {
|
|
1402
1431
|
this.checkSessionIFrame.stop();
|
|
1403
1432
|
}
|
|
1404
|
-
|
|
1405
|
-
return [4 /*yield*/,
|
|
1433
|
+
oidc = this;
|
|
1434
|
+
return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(oidc.configuration.service_worker_relative_url, oidc.configurationName)];
|
|
1406
1435
|
case 1:
|
|
1407
|
-
_a.sent();
|
|
1408
|
-
|
|
1436
|
+
serviceWorker = _a.sent();
|
|
1437
|
+
if (!!serviceWorker) return [3 /*break*/, 3];
|
|
1438
|
+
session = (0, initSession_1.initSession)(this.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
|
|
1439
|
+
return [4 /*yield*/, session.clearAsync(status)];
|
|
1409
1440
|
case 2:
|
|
1410
|
-
if (!this.session) return [3 /*break*/, 4];
|
|
1411
|
-
return [4 /*yield*/, this.session.clearAsync(status)];
|
|
1412
|
-
case 3:
|
|
1413
1441
|
_a.sent();
|
|
1414
|
-
|
|
1442
|
+
return [3 /*break*/, 5];
|
|
1443
|
+
case 3: return [4 /*yield*/, serviceWorker.clearAsync(status)];
|
|
1415
1444
|
case 4:
|
|
1445
|
+
_a.sent();
|
|
1446
|
+
_a.label = 5;
|
|
1447
|
+
case 5:
|
|
1416
1448
|
this.tokens = null;
|
|
1417
1449
|
this.userInfo = null;
|
|
1418
1450
|
return [2 /*return*/];
|