@axa-fr/react-oidc 6.4.0 → 6.5.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.
@@ -75,7 +75,7 @@ var timer_1 = __importDefault(require("./timer"));
75
75
  var checkSessionIFrame_1 = require("./checkSessionIFrame");
76
76
  var route_utils_1 = require("./route-utils");
77
77
  var parseTokens_1 = require("./parseTokens");
78
- var performTokenRequestAsync = function (url, details, extras) { return __awaiter(void 0, void 0, void 0, function () {
78
+ var performTokenRequestAsync = function (url, details, extras, oldTokens) { return __awaiter(void 0, void 0, void 0, function () {
79
79
  var _i, _a, _b, key, value, formBody, property, encodedKey, encodedValue, formBodyString, response, tokens;
80
80
  return __generator(this, function (_c) {
81
81
  switch (_c.label) {
@@ -111,7 +111,7 @@ var performTokenRequestAsync = function (url, details, extras) { return __awaite
111
111
  tokens = _c.sent();
112
112
  return [2 /*return*/, {
113
113
  success: true,
114
- data: (0, parseTokens_1.parseOriginalTokens)(tokens)
114
+ data: (0, parseTokens_1.parseOriginalTokens)(tokens, oldTokens)
115
115
  }];
116
116
  }
117
117
  });
@@ -184,37 +184,43 @@ var loginCallbackWithAutoTokensRenewAsync = function (oidc) { return __awaiter(v
184
184
  }
185
185
  });
186
186
  }); };
187
- function renewTokensAndStartTimerAsync(oidc, refreshToken, forceRefresh) {
187
+ function renewTokensAndStartTimerAsync(oidc, refreshToken, forceRefresh, extras) {
188
188
  if (forceRefresh === void 0) { forceRefresh = false; }
189
+ if (extras === void 0) { extras = null; }
189
190
  return __awaiter(this, void 0, void 0, function () {
190
- var _a, tokens, status;
191
+ var _a, tokens, status, serviceWorker, session;
191
192
  return __generator(this, function (_b) {
192
193
  switch (_b.label) {
193
- case 0: return [4 /*yield*/, oidc.synchroniseTokensAsync(refreshToken, 0, forceRefresh)];
194
+ case 0: return [4 /*yield*/, oidc.synchroniseTokensAsync(refreshToken, 0, forceRefresh, extras)];
194
195
  case 1:
195
196
  _a = _b.sent(), tokens = _a.tokens, status = _a.status;
196
197
  oidc.tokens = tokens;
197
- if (!!oidc.serviceWorker) return [3 /*break*/, 3];
198
- return [4 /*yield*/, oidc.session.setTokens(oidc.tokens)];
198
+ return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(oidc.configuration.service_worker_relative_url, oidc.configurationName)];
199
199
  case 2:
200
- _b.sent();
201
- _b.label = 3;
200
+ serviceWorker = _b.sent();
201
+ if (!!serviceWorker) return [3 /*break*/, 4];
202
+ session = (0, initSession_1.initSession)(this.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
203
+ return [4 /*yield*/, session.setTokens(oidc.tokens)];
202
204
  case 3:
203
- if (!!oidc.tokens) return [3 /*break*/, 5];
204
- return [4 /*yield*/, oidc.destroyAsync(status)];
205
+ _b.sent();
206
+ _b.label = 4;
205
207
  case 4:
208
+ if (!!oidc.tokens) return [3 /*break*/, 6];
209
+ return [4 /*yield*/, oidc.destroyAsync(status)];
210
+ case 5:
206
211
  _b.sent();
207
212
  return [2 /*return*/];
208
- case 5:
213
+ case 6:
209
214
  if (oidc.timeoutId) {
210
- oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt);
215
+ oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt, extras);
211
216
  }
212
217
  return [2 /*return*/];
213
218
  }
214
219
  });
215
220
  });
216
221
  }
217
- var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
222
+ var autoRenewTokens = function (oidc, refreshToken, expiresAt, extras) {
223
+ if (extras === void 0) { extras = null; }
218
224
  var refreshTimeBeforeTokensExpirationInSecond = oidc.configuration.refresh_time_before_tokens_expiration_in_second;
219
225
  return timer_1.default.setTimeout(function () { return __awaiter(void 0, void 0, void 0, function () {
220
226
  var timeLeft, timeInfo;
@@ -224,7 +230,7 @@ var autoRenewTokens = function (oidc, refreshToken, expiresAt) {
224
230
  timeLeft = (0, parseTokens_1.computeTimeLeft)(refreshTimeBeforeTokensExpirationInSecond, expiresAt);
225
231
  timeInfo = { timeLeft: timeLeft };
226
232
  oidc.publishEvent(Oidc.eventNames.token_timer, timeInfo);
227
- return [4 /*yield*/, renewTokensAndStartTimerAsync(oidc, refreshToken)];
233
+ return [4 /*yield*/, renewTokensAndStartTimerAsync(oidc, refreshToken, false, extras)];
228
234
  case 1:
229
235
  _a.sent();
230
236
  return [2 /*return*/];
@@ -411,8 +417,8 @@ var Oidc = /** @class */ (function () {
411
417
  this.userInfo = null;
412
418
  this.events = [];
413
419
  this.timeoutId = null;
414
- this.serviceWorker = null;
415
- this.session = null;
420
+ //this.serviceWorker = null;
421
+ //this.session = null;
416
422
  this.synchroniseTokensAsync.bind(this);
417
423
  this.loginCallbackWithAutoTokensRenewAsync.bind(this);
418
424
  this.initAsync.bind(this);
@@ -665,7 +671,7 @@ var Oidc = /** @class */ (function () {
665
671
  serviceWorker.startKeepAliveServiceWorker();
666
672
  // @ts-ignore
667
673
  this.tokens = tokens;
668
- this.serviceWorker = serviceWorker;
674
+ //this.serviceWorker = serviceWorker;
669
675
  // @ts-ignore
670
676
  this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt);
671
677
  return [4 /*yield*/, serviceWorker.getSessionStateAsync()];
@@ -701,7 +707,7 @@ var Oidc = /** @class */ (function () {
701
707
  // @ts-ignore
702
708
  this.tokens = (0, parseTokens_1.setTokens)(tokens);
703
709
  //session.setTokens(this.tokens);
704
- this.session = session;
710
+ //this.session = session;
705
711
  // @ts-ignore
706
712
  this.timeoutId = autoRenewTokens(this, tokens.refreshToken, this.tokens.expiresAt);
707
713
  sessionState = session.getSessionState();
@@ -744,12 +750,12 @@ var Oidc = /** @class */ (function () {
744
750
  });
745
751
  });
746
752
  };
747
- Oidc.prototype.loginAsync = function (callbackPath, extras, state, isSilentSignin, scope) {
753
+ Oidc.prototype.loginAsync = function (callbackPath, extras, isSilentSignin, scope, silentLoginOnly) {
748
754
  if (callbackPath === void 0) { callbackPath = undefined; }
749
755
  if (extras === void 0) { extras = null; }
750
- if (state === void 0) { state = undefined; }
751
756
  if (isSilentSignin === void 0) { isSilentSignin = false; }
752
757
  if (scope === void 0) { scope = undefined; }
758
+ if (silentLoginOnly === void 0) { silentLoginOnly = false; }
753
759
  return __awaiter(this, void 0, void 0, function () {
754
760
  var loginLocalAsync;
755
761
  var _this = this;
@@ -758,16 +764,43 @@ var Oidc = /** @class */ (function () {
758
764
  return [2 /*return*/, this.loginPromise];
759
765
  }
760
766
  loginLocalAsync = function () { return __awaiter(_this, void 0, void 0, function () {
761
- var location_1, url, configuration, redirectUri, randomString, extraFinal, nonce, serviceWorker, oidcServerConfiguration, storage, session, queryStringUtil, authorizationHandler, authRequest, exception_2;
762
- var _a;
763
- return __generator(this, function (_b) {
764
- switch (_b.label) {
767
+ var location, url, configuration, state, extraFinal, silentResult, e_2, redirectUri, randomString, extraFinal, nonce, serviceWorker, oidcServerConfiguration, storage, session, queryStringUtil, authorizationHandler, authRequest, exception_2;
768
+ var _a, _b;
769
+ return __generator(this, function (_c) {
770
+ switch (_c.label) {
765
771
  case 0:
766
- _b.trys.push([0, 9, , 10]);
767
- location_1 = window.location;
768
- url = callbackPath || location_1.pathname + (location_1.search || '') + (location_1.hash || '');
769
- this.publishEvent(eventNames.loginAsync_begin, {});
772
+ location = window.location;
773
+ url = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
770
774
  configuration = this.configuration;
775
+ state = undefined;
776
+ if (extras && "state" in extras) {
777
+ state = extras["state"];
778
+ delete extras["state"];
779
+ }
780
+ if (!silentLoginOnly) return [3 /*break*/, 4];
781
+ _c.label = 1;
782
+ case 1:
783
+ _c.trys.push([1, 3, , 4]);
784
+ extraFinal = (_a = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _a !== void 0 ? _a : {};
785
+ return [4 /*yield*/, this.silentLoginAsync(__assign(__assign({}, extraFinal), { prompt: "none" }), state, scope)];
786
+ case 2:
787
+ silentResult = _c.sent();
788
+ if (silentResult) {
789
+ this.tokens = silentResult.tokens;
790
+ this.publishEvent(eventNames.token_aquired, {});
791
+ // @ts-ignore
792
+ this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt, extras);
793
+ return [2 /*return*/, {}];
794
+ }
795
+ return [3 /*break*/, 4];
796
+ case 3:
797
+ e_2 = _c.sent();
798
+ return [2 /*return*/, e_2];
799
+ case 4:
800
+ this.publishEvent(eventNames.loginAsync_begin, {});
801
+ _c.label = 5;
802
+ case 5:
803
+ _c.trys.push([5, 14, , 15]);
771
804
  redirectUri = isSilentSignin ? configuration.silent_redirect_uri : configuration.redirect_uri;
772
805
  if (!scope) {
773
806
  scope = configuration.scope;
@@ -781,39 +814,39 @@ var Oidc = /** @class */ (function () {
781
814
  return text;
782
815
  };
783
816
  setLoginParams(this.configurationName, redirectUri, { callbackPath: url, extras: extras, state: state });
784
- extraFinal = (_a = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _a !== void 0 ? _a : {};
817
+ extraFinal = (_b = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _b !== void 0 ? _b : {};
785
818
  if (!extraFinal.nonce) {
786
819
  extraFinal["nonce"] = randomString(12);
787
820
  }
788
821
  nonce = { "nonce": extraFinal.nonce };
789
822
  return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName)];
790
- case 1:
791
- serviceWorker = _b.sent();
823
+ case 6:
824
+ serviceWorker = _c.sent();
792
825
  return [4 /*yield*/, this.initAsync(configuration.authority, configuration.authority_configuration)];
793
- case 2:
794
- oidcServerConfiguration = _b.sent();
826
+ case 7:
827
+ oidcServerConfiguration = _c.sent();
795
828
  storage = void 0;
796
- if (!serviceWorker) return [3 /*break*/, 6];
829
+ if (!serviceWorker) return [3 /*break*/, 11];
797
830
  serviceWorker.startKeepAliveServiceWorker();
798
831
  return [4 /*yield*/, serviceWorker.initAsync(oidcServerConfiguration, "loginAsync")];
799
- case 3:
800
- _b.sent();
832
+ case 8:
833
+ _c.sent();
801
834
  return [4 /*yield*/, serviceWorker.setNonceAsync(nonce)];
802
- case 4:
803
- _b.sent();
835
+ case 9:
836
+ _c.sent();
804
837
  storage = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker.saveItemsAsync, {});
805
838
  return [4 /*yield*/, storage.setItem("dummy", {})];
806
- case 5:
807
- _b.sent();
808
- return [3 /*break*/, 8];
809
- case 6:
839
+ case 10:
840
+ _c.sent();
841
+ return [3 /*break*/, 13];
842
+ case 11:
810
843
  session = (0, initSession_1.initSession)(this.configurationName, redirectUri);
811
844
  return [4 /*yield*/, session.setNonceAsync(nonce)];
812
- case 7:
813
- _b.sent();
845
+ case 12:
846
+ _c.sent();
814
847
  storage = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, {});
815
- _b.label = 8;
816
- case 8:
848
+ _c.label = 13;
849
+ case 13:
817
850
  queryStringUtil = redirectUri.includes("#") ? new noHashQueryStringUtils_1.HashQueryStringUtils() : new noHashQueryStringUtils_1.NoHashQueryStringUtils();
818
851
  authorizationHandler = new appauth_1.RedirectRequestHandler(storage, queryStringUtil, window.location, new appauth_1.DefaultCrypto());
819
852
  authRequest = new appauth_1.AuthorizationRequest({
@@ -825,12 +858,12 @@ var Oidc = /** @class */ (function () {
825
858
  extras: extraFinal
826
859
  });
827
860
  authorizationHandler.performAuthorizationRequest(oidcServerConfiguration, authRequest);
828
- return [3 /*break*/, 10];
829
- case 9:
830
- exception_2 = _b.sent();
861
+ return [3 /*break*/, 15];
862
+ case 14:
863
+ exception_2 = _c.sent();
831
864
  this.publishEvent(eventNames.loginAsync_error, exception_2);
832
865
  throw exception_2;
833
- case 10: return [2 /*return*/];
866
+ case 15: return [2 /*return*/];
834
867
  }
835
868
  });
836
869
  }); };
@@ -928,7 +961,7 @@ var Oidc = /** @class */ (function () {
928
961
  return [2 /*return*/, this.loginCallbackPromise];
929
962
  }
930
963
  loginCallbackLocalAsync = function () { return __awaiter(_this, void 0, void 0, function () {
931
- var response, tokens, parsedTokens;
964
+ var response, tokens, parsedTokens, oidc, serviceWorker, session;
932
965
  return __generator(this, function (_a) {
933
966
  switch (_a.label) {
934
967
  case 0: return [4 /*yield*/, this._loginCallbackAsync(isSilenSignin)];
@@ -937,12 +970,17 @@ var Oidc = /** @class */ (function () {
937
970
  tokens = response.tokens;
938
971
  parsedTokens = (0, parseTokens_1.setTokens)(tokens);
939
972
  this.tokens = parsedTokens;
940
- if (!!this.serviceWorker) return [3 /*break*/, 3];
941
- return [4 /*yield*/, this.session.setTokens(parsedTokens)];
973
+ oidc = this;
974
+ return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(oidc.configuration.service_worker_relative_url, oidc.configurationName)];
942
975
  case 2:
943
- _a.sent();
944
- _a.label = 3;
976
+ serviceWorker = _a.sent();
977
+ if (!!serviceWorker) return [3 /*break*/, 4];
978
+ session = (0, initSession_1.initSession)(this.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
979
+ return [4 /*yield*/, session.setTokens(parsedTokens)];
945
980
  case 3:
981
+ _a.sent();
982
+ _a.label = 4;
983
+ case 4:
946
984
  this.publishEvent(Oidc.eventNames.token_aquired, parsedTokens);
947
985
  // @ts-ignore
948
986
  return [2 /*return*/, { parsedTokens: parsedTokens, state: response.state, callbackPath: response.callbackPath }];
@@ -958,15 +996,14 @@ var Oidc = /** @class */ (function () {
958
996
  });
959
997
  };
960
998
  Oidc.prototype._loginCallbackAsync = function (isSilentSignin) {
961
- var _a;
962
999
  if (isSilentSignin === void 0) { isSilentSignin = false; }
963
1000
  return __awaiter(this, void 0, void 0, function () {
964
1001
  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
1002
  var _this = this;
966
- return __generator(this, function (_b) {
967
- switch (_b.label) {
1003
+ return __generator(this, function (_a) {
1004
+ switch (_a.label) {
968
1005
  case 0:
969
- _b.trys.push([0, 13, , 14]);
1006
+ _a.trys.push([0, 13, , 14]);
970
1007
  this.publishEvent(eventNames.loginCallbackAsync_begin, {});
971
1008
  configuration_2 = this.configuration;
972
1009
  clientId_1 = configuration_2.client_id;
@@ -975,52 +1012,52 @@ var Oidc = /** @class */ (function () {
975
1012
  tokenRequestTimeout_1 = configuration_2.token_request_timeout;
976
1013
  return [4 /*yield*/, this.initAsync(authority, configuration_2.authority_configuration)];
977
1014
  case 1:
978
- oidcServerConfiguration_1 = _b.sent();
1015
+ oidcServerConfiguration_1 = _a.sent();
979
1016
  queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
980
1017
  sessionState_2 = queryParams.session_state;
981
1018
  return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(configuration_2.service_worker_relative_url, this.configurationName)];
982
1019
  case 2:
983
- serviceWorker_1 = _b.sent();
1020
+ serviceWorker_1 = _a.sent();
984
1021
  storage_1 = null;
985
1022
  nonceData_1 = null;
986
1023
  if (!serviceWorker_1) return [3 /*break*/, 9];
987
1024
  serviceWorker_1.startKeepAliveServiceWorker();
988
- this.serviceWorker = serviceWorker_1;
1025
+ //const serviceWorker = serviceWorker;
989
1026
  return [4 /*yield*/, serviceWorker_1.initAsync(oidcServerConfiguration_1, "loginCallbackAsync")];
990
1027
  case 3:
991
- _b.sent();
1028
+ //const serviceWorker = serviceWorker;
1029
+ _a.sent();
992
1030
  return [4 /*yield*/, serviceWorker_1.loadItemsAsync()];
993
1031
  case 4:
994
- items = _b.sent();
1032
+ items = _a.sent();
995
1033
  storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker_1.saveItemsAsync, items);
996
1034
  return [4 /*yield*/, storage_1.getItem("dummy")];
997
1035
  case 5:
998
- dummy = _b.sent();
1036
+ dummy = _a.sent();
999
1037
  if (!dummy) {
1000
1038
  throw new Error("Service Worker storage disapear");
1001
1039
  }
1002
1040
  return [4 /*yield*/, storage_1.removeItem("dummy")];
1003
1041
  case 6:
1004
- _b.sent();
1042
+ _a.sent();
1005
1043
  return [4 /*yield*/, serviceWorker_1.setSessionStateAsync(sessionState_2)];
1006
1044
  case 7:
1007
- _b.sent();
1045
+ _a.sent();
1008
1046
  return [4 /*yield*/, serviceWorker_1.getNonceAsync()];
1009
1047
  case 8:
1010
- nonceData_1 = _b.sent();
1048
+ nonceData_1 = _a.sent();
1011
1049
  return [3 /*break*/, 12];
1012
1050
  case 9:
1013
- this.session = (0, initSession_1.initSession)(this.configurationName, redirectUri_1, (_a = configuration_2.storage) !== null && _a !== void 0 ? _a : sessionStorage);
1014
1051
  session = (0, initSession_1.initSession)(this.configurationName, redirectUri_1);
1015
1052
  session.setSessionState(sessionState_2);
1016
1053
  return [4 /*yield*/, session.loadItemsAsync()];
1017
1054
  case 10:
1018
- items = _b.sent();
1055
+ items = _a.sent();
1019
1056
  storage_1 = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, items);
1020
1057
  return [4 /*yield*/, session.getNonceAsync()];
1021
1058
  case 11:
1022
- nonceData_1 = _b.sent();
1023
- _b.label = 12;
1059
+ nonceData_1 = _a.sent();
1060
+ _a.label = 12;
1024
1061
  case 12: return [2 /*return*/, new Promise(function (resolve, reject) {
1025
1062
  // @ts-ignore
1026
1063
  var queryStringUtil = new noHashQueryStringUtils_1.NoHashQueryStringUtils();
@@ -1124,7 +1161,7 @@ var Oidc = /** @class */ (function () {
1124
1161
  authorizationHandler.completeAuthorizationRequestIfPossible();
1125
1162
  })];
1126
1163
  case 13:
1127
- exception_3 = _b.sent();
1164
+ exception_3 = _a.sent();
1128
1165
  console.error(exception_3);
1129
1166
  this.publishEvent(eventNames.loginCallbackAsync_error, exception_3);
1130
1167
  throw exception_3;
@@ -1133,34 +1170,38 @@ var Oidc = /** @class */ (function () {
1133
1170
  });
1134
1171
  });
1135
1172
  };
1136
- Oidc.prototype.synchroniseTokensAsync = function (refreshToken, index, forceRefresh) {
1173
+ Oidc.prototype.synchroniseTokensAsync = function (refreshToken, index, forceRefresh, extras) {
1137
1174
  if (index === void 0) { index = 0; }
1138
1175
  if (forceRefresh === void 0) { forceRefresh = false; }
1176
+ if (extras === void 0) { extras = null; }
1139
1177
  return __awaiter(this, void 0, void 0, function () {
1140
- var numberTryOnline, configuration, localsilentLoginAsync, _a, status_1, tokens, _b, clientId, redirectUri, authority, extras, _i, _c, _d, key, value, details, oidcServerConfiguration, tokenResponse, exception_4;
1178
+ var numberTryOnline, configuration, localsilentLoginAsync, _a, status_1, tokens, _b, clientId, redirectUri, authority, tokenExtras, finalExtras, details, oidcServerConfiguration, tokenResponse, exception_4;
1141
1179
  var _this = this;
1142
- return __generator(this, function (_e) {
1143
- switch (_e.label) {
1180
+ return __generator(this, function (_c) {
1181
+ switch (_c.label) {
1144
1182
  case 0:
1145
1183
  if (!document.hidden) return [3 /*break*/, 3];
1146
1184
  return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
1147
1185
  case 1:
1148
- _e.sent();
1186
+ _c.sent();
1149
1187
  this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because document is hidden" });
1150
1188
  return [4 /*yield*/, this.synchroniseTokensAsync(refreshToken, index, forceRefresh)];
1151
- case 2: return [2 /*return*/, _e.sent()];
1189
+ case 2: return [2 /*return*/, _c.sent()];
1152
1190
  case 3:
1153
1191
  numberTryOnline = 6;
1154
- _e.label = 4;
1192
+ _c.label = 4;
1155
1193
  case 4:
1156
1194
  if (!(!navigator.onLine && numberTryOnline > 0)) return [3 /*break*/, 6];
1157
1195
  return [4 /*yield*/, (0, initWorker_1.sleepAsync)(1000)];
1158
1196
  case 5:
1159
- _e.sent();
1197
+ _c.sent();
1160
1198
  numberTryOnline--;
1161
1199
  this.publishEvent(eventNames.refreshTokensAsync, { message: "wait because navigator is offline try ".concat(numberTryOnline) });
1162
1200
  return [3 /*break*/, 4];
1163
1201
  case 6:
1202
+ if (!extras) {
1203
+ extras = {};
1204
+ }
1164
1205
  configuration = this.configuration;
1165
1206
  localsilentLoginAsync = function () { return __awaiter(_this, void 0, void 0, function () {
1166
1207
  var loginParams, silent_token_response, exceptionSilent_1;
@@ -1169,7 +1210,7 @@ var Oidc = /** @class */ (function () {
1169
1210
  case 0:
1170
1211
  _a.trys.push([0, 2, , 4]);
1171
1212
  loginParams = getLoginParams(this.configurationName, configuration.redirect_uri);
1172
- return [4 /*yield*/, this.silentLoginAsync(__assign(__assign({}, loginParams.extras), { prompt: "none" }), loginParams.state)];
1213
+ return [4 /*yield*/, this.silentLoginAsync(__assign(__assign(__assign({}, loginParams.extras), extras), { prompt: "none" }), loginParams.state)];
1173
1214
  case 1:
1174
1215
  silent_token_response = _a.sent();
1175
1216
  if (silent_token_response) {
@@ -1196,12 +1237,12 @@ var Oidc = /** @class */ (function () {
1196
1237
  });
1197
1238
  }); };
1198
1239
  if (!(index <= 4)) return [3 /*break*/, 25];
1199
- _e.label = 7;
1240
+ _c.label = 7;
1200
1241
  case 7:
1201
- _e.trys.push([7, 24, , 25]);
1242
+ _c.trys.push([7, 24, , 25]);
1202
1243
  return [4 /*yield*/, this.syncTokensInfoAsync(configuration, this.configurationName, this.tokens, forceRefresh)];
1203
1244
  case 8:
1204
- _a = _e.sent(), status_1 = _a.status, tokens = _a.tokens;
1245
+ _a = _c.sent(), status_1 = _a.status, tokens = _a.tokens;
1205
1246
  _b = status_1;
1206
1247
  switch (_b) {
1207
1248
  case "SESSION_LOST": return [3 /*break*/, 9];
@@ -1226,24 +1267,19 @@ var Oidc = /** @class */ (function () {
1226
1267
  case 14:
1227
1268
  this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, status: status_1, tryNumber: index });
1228
1269
  return [4 /*yield*/, localsilentLoginAsync()];
1229
- case 15: return [2 /*return*/, _e.sent()];
1270
+ case 15: return [2 /*return*/, _c.sent()];
1230
1271
  case 16:
1231
1272
  if (!!refreshToken) return [3 /*break*/, 18];
1232
1273
  this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, tryNumber: index });
1233
1274
  return [4 /*yield*/, localsilentLoginAsync()];
1234
- case 17: return [2 /*return*/, _e.sent()];
1275
+ case 17: return [2 /*return*/, _c.sent()];
1235
1276
  case 18:
1236
1277
  this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken: refreshToken, status: status_1, tryNumber: index });
1237
1278
  clientId = configuration.client_id;
1238
1279
  redirectUri = configuration.redirect_uri;
1239
1280
  authority = configuration.authority;
1240
- extras = {};
1241
- if (configuration.token_request_extras) {
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
- }
1281
+ tokenExtras = configuration.token_request_extras ? configuration.token_request_extras : {};
1282
+ finalExtras = __assign(__assign({}, tokenExtras), extras);
1247
1283
  details = {
1248
1284
  client_id: clientId,
1249
1285
  redirect_uri: redirectUri,
@@ -1252,10 +1288,10 @@ var Oidc = /** @class */ (function () {
1252
1288
  };
1253
1289
  return [4 /*yield*/, this.initAsync(authority, configuration.authority_configuration)];
1254
1290
  case 19:
1255
- oidcServerConfiguration = _e.sent();
1256
- return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, extras)];
1291
+ oidcServerConfiguration = _c.sent();
1292
+ return [4 /*yield*/, performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens)];
1257
1293
  case 20:
1258
- tokenResponse = _e.sent();
1294
+ tokenResponse = _c.sent();
1259
1295
  if (!tokenResponse.success) return [3 /*break*/, 21];
1260
1296
  if (!(0, parseTokens_1.isTokensOidcValid)(tokenResponse.data, null, oidcServerConfiguration)) {
1261
1297
  this.publishEvent(eventNames.refreshTokensAsync_error, { message: "refresh token return not valid tokens" });
@@ -1270,10 +1306,10 @@ var Oidc = /** @class */ (function () {
1270
1306
  tokenResponse: tokenResponse
1271
1307
  });
1272
1308
  return [4 /*yield*/, this.synchroniseTokensAsync(null, index + 1, forceRefresh)];
1273
- case 22: return [2 /*return*/, _e.sent()];
1309
+ case 22: return [2 /*return*/, _c.sent()];
1274
1310
  case 23: return [3 /*break*/, 25];
1275
1311
  case 24:
1276
- exception_4 = _e.sent();
1312
+ exception_4 = _c.sent();
1277
1313
  console.error(exception_4);
1278
1314
  this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: "exception", exception: exception_4.message });
1279
1315
  return [2 /*return*/, this.synchroniseTokensAsync(refreshToken, index + 1, forceRefresh)];
@@ -1372,7 +1408,8 @@ var Oidc = /** @class */ (function () {
1372
1408
  return result;
1373
1409
  });
1374
1410
  };
1375
- Oidc.prototype.renewTokensAsync = function () {
1411
+ Oidc.prototype.renewTokensAsync = function (extras) {
1412
+ if (extras === void 0) { extras = null; }
1376
1413
  return __awaiter(this, void 0, void 0, function () {
1377
1414
  return __generator(this, function (_a) {
1378
1415
  switch (_a.label) {
@@ -1382,7 +1419,7 @@ var Oidc = /** @class */ (function () {
1382
1419
  }
1383
1420
  timer_1.default.clearTimeout(this.timeoutId);
1384
1421
  // @ts-ignore
1385
- return [4 /*yield*/, renewTokensAndStartTimerAsync(this, this.tokens.refreshToken, true)];
1422
+ return [4 /*yield*/, renewTokensAndStartTimerAsync(this, this.tokens.refreshToken, true, extras)];
1386
1423
  case 1:
1387
1424
  // @ts-ignore
1388
1425
  _a.sent();
@@ -1393,6 +1430,7 @@ var Oidc = /** @class */ (function () {
1393
1430
  };
1394
1431
  Oidc.prototype.destroyAsync = function (status) {
1395
1432
  return __awaiter(this, void 0, void 0, function () {
1433
+ var oidc, serviceWorker, session;
1396
1434
  return __generator(this, function (_a) {
1397
1435
  switch (_a.label) {
1398
1436
  case 0:
@@ -1401,18 +1439,21 @@ var Oidc = /** @class */ (function () {
1401
1439
  if (this.checkSessionIFrame) {
1402
1440
  this.checkSessionIFrame.stop();
1403
1441
  }
1404
- if (!this.serviceWorker) return [3 /*break*/, 2];
1405
- return [4 /*yield*/, this.serviceWorker.clearAsync(status)];
1442
+ oidc = this;
1443
+ return [4 /*yield*/, (0, initWorker_1.initWorkerAsync)(oidc.configuration.service_worker_relative_url, oidc.configurationName)];
1406
1444
  case 1:
1407
- _a.sent();
1408
- _a.label = 2;
1445
+ serviceWorker = _a.sent();
1446
+ if (!!serviceWorker) return [3 /*break*/, 3];
1447
+ session = (0, initSession_1.initSession)(this.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
1448
+ return [4 /*yield*/, session.clearAsync(status)];
1409
1449
  case 2:
1410
- if (!this.session) return [3 /*break*/, 4];
1411
- return [4 /*yield*/, this.session.clearAsync(status)];
1412
- case 3:
1413
1450
  _a.sent();
1414
- _a.label = 4;
1451
+ return [3 /*break*/, 5];
1452
+ case 3: return [4 /*yield*/, serviceWorker.clearAsync(status)];
1415
1453
  case 4:
1454
+ _a.sent();
1455
+ _a.label = 5;
1456
+ case 5:
1416
1457
  this.tokens = null;
1417
1458
  this.userInfo = null;
1418
1459
  return [2 /*return*/];