@axa-fr/react-oidc 6.12.0 → 6.13.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.
Files changed (78) hide show
  1. package/bin/copy.js +12 -9
  2. package/dist/OidcProvider.d.ts +1 -1
  3. package/dist/OidcProvider.d.ts.map +1 -1
  4. package/dist/OidcSecure.d.ts +1 -1
  5. package/dist/OidcSecure.d.ts.map +1 -1
  6. package/dist/ReactOidc.d.ts +1 -1
  7. package/dist/ReactOidc.d.ts.map +1 -1
  8. package/dist/index.d.ts +1 -1
  9. package/dist/index.d.ts.map +1 -1
  10. package/dist/index.js.map +1 -1
  11. package/dist/vanilla/checkSession.d.ts +5 -0
  12. package/dist/vanilla/checkSession.d.ts.map +1 -0
  13. package/dist/vanilla/checkSession.js +68 -0
  14. package/dist/vanilla/checkSession.js.map +1 -0
  15. package/dist/vanilla/events.d.ts +29 -0
  16. package/dist/vanilla/events.d.ts.map +1 -0
  17. package/dist/vanilla/events.js +32 -0
  18. package/dist/vanilla/events.js.map +1 -0
  19. package/dist/vanilla/initSession.d.ts +3 -3
  20. package/dist/vanilla/initSession.d.ts.map +1 -1
  21. package/dist/vanilla/initSession.js +19 -23
  22. package/dist/vanilla/initSession.js.map +1 -1
  23. package/dist/vanilla/initWorker.d.ts +4 -4
  24. package/dist/vanilla/initWorker.d.ts.map +1 -1
  25. package/dist/vanilla/initWorker.js +11 -15
  26. package/dist/vanilla/initWorker.js.map +1 -1
  27. package/dist/vanilla/login.d.ts +4 -0
  28. package/dist/vanilla/login.d.ts.map +1 -0
  29. package/dist/vanilla/login.js +244 -0
  30. package/dist/vanilla/login.js.map +1 -0
  31. package/dist/vanilla/oidc.d.ts +4 -37
  32. package/dist/vanilla/oidc.d.ts.map +1 -1
  33. package/dist/vanilla/oidc.js +99 -519
  34. package/dist/vanilla/oidc.js.map +1 -1
  35. package/dist/vanilla/renewTokens.d.ts +4 -0
  36. package/dist/vanilla/renewTokens.d.ts.map +1 -0
  37. package/dist/vanilla/renewTokens.js +50 -0
  38. package/dist/vanilla/renewTokens.js.map +1 -0
  39. package/dist/vanilla/requests.d.ts +2 -0
  40. package/dist/vanilla/requests.d.ts.map +1 -1
  41. package/dist/vanilla/requests.js +20 -1
  42. package/dist/vanilla/requests.js.map +1 -1
  43. package/dist/vanilla/route-utils.js +1 -1
  44. package/dist/vanilla/route-utils.js.map +1 -1
  45. package/dist/vanilla/silentLogin.d.ts +9 -0
  46. package/dist/vanilla/silentLogin.d.ts.map +1 -0
  47. package/dist/vanilla/silentLogin.js +145 -0
  48. package/dist/vanilla/silentLogin.js.map +1 -0
  49. package/dist/vanilla/types.d.ts +33 -0
  50. package/dist/vanilla/types.d.ts.map +1 -0
  51. package/dist/vanilla/types.js +3 -0
  52. package/dist/vanilla/types.js.map +1 -0
  53. package/dist/vanilla/user.d.ts +2 -0
  54. package/dist/vanilla/user.d.ts.map +1 -0
  55. package/dist/vanilla/user.js +48 -0
  56. package/dist/vanilla/user.js.map +1 -0
  57. package/dist/vanilla/vanillaOidc.d.ts +2 -1
  58. package/dist/vanilla/vanillaOidc.d.ts.map +1 -1
  59. package/dist/vanilla/vanillaOidc.js.map +1 -1
  60. package/package.json +1 -1
  61. package/src/oidc/OidcProvider.tsx +1 -1
  62. package/src/oidc/OidcSecure.tsx +1 -1
  63. package/src/oidc/ReactOidc.tsx +1 -1
  64. package/src/oidc/index.ts +1 -1
  65. package/src/oidc/vanilla/checkSession.ts +55 -0
  66. package/src/oidc/vanilla/events.ts +29 -0
  67. package/src/oidc/vanilla/index.ts +1 -1
  68. package/src/oidc/vanilla/initSession.ts +19 -25
  69. package/src/oidc/vanilla/initWorker.ts +12 -18
  70. package/src/oidc/vanilla/login.ts +242 -0
  71. package/src/oidc/vanilla/oidc.ts +53 -554
  72. package/src/oidc/vanilla/renewTokens.ts +36 -0
  73. package/src/oidc/vanilla/requests.ts +24 -0
  74. package/src/oidc/vanilla/route-utils.ts +1 -1
  75. package/src/oidc/vanilla/silentLogin.ts +143 -0
  76. package/src/oidc/vanilla/types.ts +35 -0
  77. package/src/oidc/vanilla/user.ts +39 -0
  78. package/src/oidc/vanilla/vanillaOidc.ts +2 -1
@@ -1,4 +1,27 @@
1
1
  "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
2
25
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
3
26
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
4
27
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -14,24 +37,18 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
37
  Object.defineProperty(exports, "__esModule", { value: true });
15
38
  exports.Oidc = exports.OidcAuthorizationServiceConfiguration = void 0;
16
39
  const appauth_1 = require("@openid/appauth");
17
- const cache_1 = require("./cache");
18
- const checkSessionIFrame_1 = require("./checkSessionIFrame");
40
+ const checkSession_1 = require("./checkSession");
41
+ const events_1 = require("./events");
19
42
  const initSession_1 = require("./initSession");
20
43
  const initWorker_1 = require("./initWorker");
21
- const memoryStorageBackend_1 = require("./memoryStorageBackend");
22
- const noHashQueryStringUtils_1 = require("./noHashQueryStringUtils");
44
+ const login_1 = require("./login");
23
45
  const parseTokens_1 = require("./parseTokens");
46
+ const renewTokens_1 = require("./renewTokens");
24
47
  const requests_1 = require("./requests");
25
48
  const route_utils_1 = require("./route-utils");
49
+ const silentLogin_1 = __importStar(require("./silentLogin"));
26
50
  const timer_1 = __importDefault(require("./timer"));
27
- const randomString = function (length) {
28
- let text = '';
29
- const possible = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
30
- for (let i = 0; i < length; i++) {
31
- text += possible.charAt(Math.floor(Math.random() * possible.length));
32
- }
33
- return text;
34
- };
51
+ const user_1 = require("./user");
35
52
  class OidcAuthorizationServiceConfiguration extends appauth_1.AuthorizationServiceConfiguration {
36
53
  constructor(request) {
37
54
  super(request);
@@ -54,115 +71,12 @@ const oidcFactory = (configuration, name = 'default') => {
54
71
  };
55
72
  const loginCallbackWithAutoTokensRenewAsync = (oidc) => __awaiter(void 0, void 0, void 0, function* () {
56
73
  const { parsedTokens, callbackPath } = yield oidc.loginCallbackAsync();
57
- oidc.timeoutId = autoRenewTokens(oidc, parsedTokens.refreshToken, parsedTokens.expiresAt);
74
+ oidc.timeoutId = (0, renewTokens_1.autoRenewTokens)(oidc, parsedTokens.refreshToken, parsedTokens.expiresAt);
58
75
  return { callbackPath };
59
76
  });
60
- function renewTokensAndStartTimerAsync(oidc, refreshToken, forceRefresh = false, extras = null) {
61
- return __awaiter(this, void 0, void 0, function* () {
62
- const updateTokens = (tokens) => { oidc.tokens = tokens; };
63
- const { tokens, status } = yield oidc.synchroniseTokensAsync(refreshToken, 0, forceRefresh, extras, updateTokens);
64
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(oidc.configuration.service_worker_relative_url, oidc.configurationName, oidc.configuration.redirect_uri);
65
- if (!serviceWorker) {
66
- const session = (0, initSession_1.initSession)(oidc.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
67
- yield session.setTokens(oidc.tokens);
68
- }
69
- if (!oidc.tokens) {
70
- yield oidc.destroyAsync(status);
71
- return;
72
- }
73
- if (oidc.timeoutId) {
74
- oidc.timeoutId = autoRenewTokens(oidc, tokens.refreshToken, oidc.tokens.expiresAt, extras);
75
- }
76
- });
77
- }
78
- const autoRenewTokens = (oidc, refreshToken, expiresAt, extras = null) => {
79
- const refreshTimeBeforeTokensExpirationInSecond = oidc.configuration.refresh_time_before_tokens_expiration_in_second;
80
- return timer_1.default.setTimeout(() => __awaiter(void 0, void 0, void 0, function* () {
81
- const timeLeft = (0, parseTokens_1.computeTimeLeft)(refreshTimeBeforeTokensExpirationInSecond, expiresAt);
82
- const timeInfo = { timeLeft };
83
- oidc.publishEvent(Oidc.eventNames.token_timer, timeInfo);
84
- yield renewTokensAndStartTimerAsync(oidc, refreshToken, false, extras);
85
- }), 1000);
86
- };
87
- const userInfoAsync = (oidc) => __awaiter(void 0, void 0, void 0, function* () {
88
- if (oidc.userInfo != null) {
89
- return oidc.userInfo;
90
- }
91
- if (!oidc.tokens) {
92
- return null;
93
- }
94
- const accessToken = oidc.tokens.accessToken;
95
- if (!accessToken) {
96
- return null;
97
- }
98
- // We wait the synchronisation before making a request
99
- while (oidc.tokens && !(0, parseTokens_1.isTokensValid)(oidc.tokens)) {
100
- yield (0, initWorker_1.sleepAsync)(200);
101
- }
102
- const oidcServerConfiguration = yield oidc.initAsync(oidc.configuration.authority, oidc.configuration.authority_configuration);
103
- const url = oidcServerConfiguration.userInfoEndpoint;
104
- const fetchUserInfo = (accessToken) => __awaiter(void 0, void 0, void 0, function* () {
105
- const res = yield fetch(url, {
106
- headers: {
107
- authorization: `Bearer ${accessToken}`,
108
- },
109
- });
110
- if (res.status !== 200) {
111
- return null;
112
- }
113
- return res.json();
114
- });
115
- const userInfo = yield fetchUserInfo(accessToken);
116
- oidc.userInfo = userInfo;
117
- return userInfo;
118
- });
119
- const eventNames = {
120
- service_worker_not_supported_by_browser: 'service_worker_not_supported_by_browser',
121
- token_aquired: 'token_aquired',
122
- logout_from_another_tab: 'logout_from_another_tab',
123
- logout_from_same_tab: 'logout_from_same_tab',
124
- token_renewed: 'token_renewed',
125
- token_timer: 'token_timer',
126
- loginAsync_begin: 'loginAsync_begin',
127
- loginAsync_error: 'loginAsync_error',
128
- loginCallbackAsync_begin: 'loginCallbackAsync_begin',
129
- loginCallbackAsync_end: 'loginCallbackAsync_end',
130
- loginCallbackAsync_error: 'loginCallbackAsync_error',
131
- refreshTokensAsync_begin: 'refreshTokensAsync_begin',
132
- refreshTokensAsync: 'refreshTokensAsync',
133
- refreshTokensAsync_end: 'refreshTokensAsync_end',
134
- refreshTokensAsync_error: 'refreshTokensAsync_error',
135
- refreshTokensAsync_silent_error: 'refreshTokensAsync_silent_error',
136
- tryKeepExistingSessionAsync_begin: 'tryKeepExistingSessionAsync_begin',
137
- tryKeepExistingSessionAsync_end: 'tryKeepExistingSessionAsync_end',
138
- tryKeepExistingSessionAsync_error: 'tryKeepExistingSessionAsync_error',
139
- silentLoginAsync_begin: 'silentLoginAsync_begin',
140
- silentLoginAsync: 'silentLoginAsync',
141
- silentLoginAsync_end: 'silentLoginAsync_end',
142
- silentLoginAsync_error: 'silentLoginAsync_error',
143
- syncTokensAsync_begin: 'syncTokensAsync_begin',
144
- syncTokensAsync_end: 'syncTokensAsync_end',
145
- syncTokensAsync_error: 'syncTokensAsync_error',
146
- };
147
77
  const getRandomInt = (max) => {
148
78
  return Math.floor(Math.random() * max);
149
79
  };
150
- const oneHourSecond = 60 * 60;
151
- const fetchFromIssuer = (openIdIssuerUrl, timeCacheSecond = oneHourSecond, storage = window.sessionStorage) => __awaiter(void 0, void 0, void 0, function* () {
152
- const fullUrl = `${openIdIssuerUrl}/.well-known/openid-configuration`;
153
- const localStorageKey = `oidc.server:${openIdIssuerUrl}`;
154
- const data = (0, cache_1.getFromCache)(localStorageKey, storage, timeCacheSecond);
155
- if (data) {
156
- return new OidcAuthorizationServiceConfiguration(data);
157
- }
158
- const response = yield fetch(fullUrl);
159
- if (response.status !== 200) {
160
- return null;
161
- }
162
- const result = yield response.json();
163
- (0, cache_1.setCache)(localStorageKey, result, storage);
164
- return new OidcAuthorizationServiceConfiguration(result);
165
- });
166
80
  class Oidc {
167
81
  constructor(configuration, configurationName = 'default') {
168
82
  var _a, _b, _c, _d;
@@ -186,7 +100,6 @@ class Oidc {
186
100
  this.loginCallbackWithAutoTokensRenewAsync.bind(this);
187
101
  this.initAsync.bind(this);
188
102
  this.loginCallbackAsync.bind(this);
189
- this._loginCallbackAsync.bind(this);
190
103
  this.subscribeEvents.bind(this);
191
104
  this.removeEventSubscription.bind(this);
192
105
  this.publishEvent.bind(this);
@@ -244,98 +157,6 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
244
157
  }
245
158
  });
246
159
  }
247
- silentLoginAsync(extras = null, state = null, scope = null) {
248
- return __awaiter(this, void 0, void 0, function* () {
249
- if (!this.configuration.silent_redirect_uri || !this.configuration.silent_login_uri) {
250
- return Promise.resolve(null);
251
- }
252
- try {
253
- this.publishEvent(eventNames.silentLoginAsync_begin, {});
254
- const configuration = this.configuration;
255
- let queries = '';
256
- if (state) {
257
- if (extras == null) {
258
- extras = {};
259
- }
260
- extras.state = state;
261
- }
262
- if (scope) {
263
- if (extras == null) {
264
- extras = {};
265
- }
266
- extras.scope = scope;
267
- }
268
- if (extras != null) {
269
- for (const [key, value] of Object.entries(extras)) {
270
- if (queries === '') {
271
- queries = `?${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
272
- }
273
- else {
274
- queries += `&${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
275
- }
276
- }
277
- }
278
- const link = configuration.silent_login_uri + queries;
279
- const idx = link.indexOf('/', link.indexOf('//') + 2);
280
- const iFrameOrigin = link.substr(0, idx);
281
- const iframe = document.createElement('iframe');
282
- iframe.width = '0px';
283
- iframe.height = '0px';
284
- iframe.id = `${this.configurationName}_oidc_iframe`;
285
- iframe.setAttribute('src', link);
286
- document.body.appendChild(iframe);
287
- return new Promise((resolve, reject) => {
288
- try {
289
- let isResolved = false;
290
- window.onmessage = (e) => {
291
- if (e.origin === iFrameOrigin &&
292
- e.source === iframe.contentWindow) {
293
- const key = `${this.configurationName}_oidc_tokens:`;
294
- const key_error = `${this.configurationName}_oidc_error:`;
295
- const data = e.data;
296
- if (data && typeof (data) === 'string') {
297
- if (!isResolved) {
298
- if (data.startsWith(key)) {
299
- const result = JSON.parse(e.data.replace(key, ''));
300
- this.publishEvent(eventNames.silentLoginAsync_end, {});
301
- iframe.remove();
302
- isResolved = true;
303
- resolve(result);
304
- }
305
- else if (data.startsWith(key_error)) {
306
- const result = JSON.parse(e.data.replace(key_error, ''));
307
- this.publishEvent(eventNames.silentLoginAsync_error, result);
308
- iframe.remove();
309
- isResolved = true;
310
- reject(new Error('oidc_' + result.error));
311
- }
312
- }
313
- }
314
- }
315
- };
316
- const silentSigninTimeout = configuration.silent_login_timeout;
317
- setTimeout(() => {
318
- if (!isResolved) {
319
- this.publishEvent(eventNames.silentLoginAsync_error, { reason: 'timeout' });
320
- iframe.remove();
321
- isResolved = true;
322
- reject(new Error('timeout'));
323
- }
324
- }, silentSigninTimeout);
325
- }
326
- catch (e) {
327
- iframe.remove();
328
- this.publishEvent(eventNames.silentLoginAsync_error, e);
329
- reject(e);
330
- }
331
- });
332
- }
333
- catch (e) {
334
- this.publishEvent(eventNames.silentLoginAsync_error, e);
335
- throw e;
336
- }
337
- });
338
- }
339
160
  initAsync(authority, authorityConfiguration) {
340
161
  return __awaiter(this, void 0, void 0, function* () {
341
162
  if (this.initPromise !== null) {
@@ -354,9 +175,9 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
354
175
  issuer: authorityConfiguration.issuer,
355
176
  });
356
177
  }
357
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
178
+ const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName);
358
179
  const storage = serviceWorker ? window.localStorage : null;
359
- return yield fetchFromIssuer(authority, (_a = this.configuration.authority_time_cache_wellknowurl_in_second) !== null && _a !== void 0 ? _a : 60 * 60, storage);
180
+ return yield (0, requests_1.fetchFromIssuer)(authority, (_a = this.configuration.authority_time_cache_wellknowurl_in_second) !== null && _a !== void 0 ? _a : 60 * 60, storage);
360
181
  });
361
182
  this.initPromise = localFuncAsync();
362
183
  return this.initPromise.then((result) => {
@@ -376,57 +197,59 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
376
197
  if (this.tokens != null) {
377
198
  return false;
378
199
  }
379
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_begin, {});
200
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_begin, {});
380
201
  try {
381
202
  const configuration = this.configuration;
382
203
  const oidcServerConfiguration = yield this.initAsync(configuration.authority, configuration.authority_configuration);
383
- serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName, configuration.redirect_uri);
204
+ serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName);
384
205
  if (serviceWorker) {
385
206
  const { tokens } = yield serviceWorker.initAsync(oidcServerConfiguration, 'tryKeepExistingSessionAsync', configuration);
386
207
  if (tokens) {
387
208
  serviceWorker.startKeepAliveServiceWorker();
388
209
  // @ts-ignore
389
210
  this.tokens = tokens;
211
+ const getLoginParams = serviceWorker.getLoginParams(this.configurationName);
390
212
  // @ts-ignore
391
- this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt);
213
+ this.timeoutId = (0, renewTokens_1.autoRenewTokens)(this, this.tokens.refreshToken, this.tokens.expiresAt, getLoginParams.extras);
392
214
  const sessionState = yield serviceWorker.getSessionStateAsync();
393
215
  // @ts-ignore
394
216
  yield this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
395
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
217
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
396
218
  success: true,
397
219
  message: 'tokens inside ServiceWorker are valid',
398
220
  });
399
221
  return true;
400
222
  }
401
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
223
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
402
224
  success: false,
403
225
  message: 'no exiting session found',
404
226
  });
405
227
  }
406
228
  else {
407
229
  if (configuration.service_worker_relative_url) {
408
- this.publishEvent(eventNames.service_worker_not_supported_by_browser, {
230
+ this.publishEvent(events_1.eventNames.service_worker_not_supported_by_browser, {
409
231
  message: 'service worker is not supported by this browser',
410
232
  });
411
233
  }
412
- const session = (0, initSession_1.initSession)(this.configurationName, configuration.redirect_uri, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
234
+ const session = (0, initSession_1.initSession)(this.configurationName, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
413
235
  const { tokens } = yield session.initAsync();
414
236
  if (tokens) {
415
237
  // @ts-ignore
416
238
  this.tokens = (0, parseTokens_1.setTokens)(tokens, null, configuration.token_renew_mode);
239
+ const getLoginParams = session.getLoginParams(this.configurationName);
417
240
  // @ts-ignore
418
- this.timeoutId = autoRenewTokens(this, tokens.refreshToken, this.tokens.expiresAt);
241
+ this.timeoutId = (0, renewTokens_1.autoRenewTokens)(this, tokens.refreshToken, this.tokens.expiresAt, getLoginParams.extras);
419
242
  const sessionState = session.getSessionState();
420
243
  // @ts-ignore
421
244
  yield this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
422
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
245
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
423
246
  success: true,
424
247
  message: 'tokens inside storage are valid',
425
248
  });
426
249
  return true;
427
250
  }
428
251
  }
429
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
252
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
430
253
  success: false,
431
254
  message: serviceWorker ? 'service worker sessions not retrieved' : 'session storage sessions not retrieved',
432
255
  });
@@ -437,7 +260,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
437
260
  if (serviceWorker) {
438
261
  yield serviceWorker.clearAsync();
439
262
  }
440
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_error, 'tokens inside ServiceWorker are invalid');
263
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_error, 'tokens inside ServiceWorker are invalid');
441
264
  return false;
442
265
  }
443
266
  });
@@ -448,159 +271,44 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
448
271
  });
449
272
  });
450
273
  }
274
+ startCheckSessionAsync(checkSessionIFrameUri, clientId, sessionState, isSilentSignin = false) {
275
+ return __awaiter(this, void 0, void 0, function* () {
276
+ const getCurrentTokens = () => this.tokens;
277
+ const silentLoginAsync = (extras, state, scope) => {
278
+ return (0, silentLogin_1._silentLoginAsync)(this.configurationName, this.configuration, this.publishEvent.bind(this))(extras, state, scope);
279
+ };
280
+ this.checkSessionIFrame = yield (0, checkSession_1.startCheckSessionAsync)(oidcDatabase, this.configuration, this.checkSessionIFrame, silentLoginAsync.bind(this), getCurrentTokens)(checkSessionIFrameUri, clientId, sessionState, isSilentSignin);
281
+ });
282
+ }
451
283
  loginAsync(callbackPath = undefined, extras = null, isSilentSignin = false, scope = undefined, silentLoginOnly = false) {
452
284
  return __awaiter(this, void 0, void 0, function* () {
453
285
  if (this.loginPromise !== null) {
454
286
  return this.loginPromise;
455
287
  }
456
- const loginLocalAsync = () => __awaiter(this, void 0, void 0, function* () {
457
- var _a, _b;
458
- const location = window.location;
459
- const url = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
460
- const configuration = this.configuration;
461
- let state;
462
- if (extras && 'state' in extras) {
463
- state = extras.state;
464
- delete extras.state;
465
- }
466
- if (silentLoginOnly) {
467
- try {
468
- const extraFinal = (_a = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _a !== void 0 ? _a : {};
469
- const silentResult = yield this.silentLoginAsync(Object.assign(Object.assign({}, extraFinal), { prompt: 'none' }), state, scope);
470
- if (silentResult) {
471
- this.tokens = silentResult.tokens;
472
- this.publishEvent(eventNames.token_aquired, {});
473
- // @ts-ignore
474
- this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt, extras);
475
- return {};
476
- }
477
- }
478
- catch (e) {
479
- return e;
480
- }
481
- }
482
- this.publishEvent(eventNames.loginAsync_begin, {});
483
- try {
484
- const redirectUri = isSilentSignin ? configuration.silent_redirect_uri : configuration.redirect_uri;
485
- if (!scope) {
486
- scope = configuration.scope;
487
- }
488
- const extraFinal = (_b = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _b !== void 0 ? _b : {};
489
- if (!extraFinal.nonce) {
490
- extraFinal.nonce = randomString(12);
491
- }
492
- const nonce = { nonce: extraFinal.nonce };
493
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
494
- const oidcServerConfiguration = yield this.initAsync(configuration.authority, configuration.authority_configuration);
495
- let storage;
496
- if (serviceWorker) {
497
- serviceWorker.setLoginParams(this.configurationName, redirectUri, { callbackPath: url, extras, state });
498
- serviceWorker.startKeepAliveServiceWorker();
499
- yield serviceWorker.initAsync(oidcServerConfiguration, 'loginAsync', configuration);
500
- yield serviceWorker.setNonceAsync(nonce);
501
- storage = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker.saveItemsAsync, {});
502
- yield storage.setItem('dummy', {});
503
- }
504
- else {
505
- const session = (0, initSession_1.initSession)(this.configurationName, redirectUri);
506
- session.setLoginParams(this.configurationName, redirectUri, { callbackPath: url, extras, state });
507
- yield session.setNonceAsync(nonce);
508
- storage = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, {});
509
- }
510
- // @ts-ignore
511
- const queryStringUtil = redirectUri.includes('#') ? new noHashQueryStringUtils_1.HashQueryStringUtils() : new noHashQueryStringUtils_1.NoHashQueryStringUtils();
512
- const authorizationHandler = new appauth_1.RedirectRequestHandler(storage, queryStringUtil, window.location, new appauth_1.DefaultCrypto());
513
- const authRequest = new appauth_1.AuthorizationRequest({
514
- client_id: configuration.client_id,
515
- redirect_uri: redirectUri,
516
- scope,
517
- response_type: appauth_1.AuthorizationRequest.RESPONSE_TYPE_CODE,
518
- state,
519
- extras: extraFinal,
520
- });
521
- authorizationHandler.performAuthorizationRequest(oidcServerConfiguration, authRequest);
522
- }
523
- catch (exception) {
524
- this.publishEvent(eventNames.loginAsync_error, exception);
525
- throw exception;
526
- }
527
- });
528
- this.loginPromise = loginLocalAsync();
288
+ if (silentLoginOnly) {
289
+ return (0, silentLogin_1.default)(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(extras, scope);
290
+ }
291
+ this.loginPromise = (0, login_1.defaultLoginAsync)(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this.initAsync.bind(this))(callbackPath, extras, isSilentSignin, scope);
529
292
  return this.loginPromise.then(result => {
530
293
  this.loginPromise = null;
531
294
  return result;
532
295
  });
533
296
  });
534
297
  }
535
- startCheckSessionAsync(checkSessionIFrameUri, clientId, sessionState, isSilentSignin = false) {
536
- return __awaiter(this, void 0, void 0, function* () {
537
- return new Promise((resolve, reject) => {
538
- if (this.configuration.silent_login_uri && this.configuration.silent_redirect_uri && this.configuration.monitor_session && checkSessionIFrameUri && sessionState && !isSilentSignin) {
539
- const checkSessionCallback = () => {
540
- this.checkSessionIFrame.stop();
541
- if (this.tokens === null) {
542
- return;
543
- }
544
- // @ts-ignore
545
- const idToken = this.tokens.idToken;
546
- // @ts-ignore
547
- const idTokenPayload = this.tokens.idTokenPayload;
548
- this.silentLoginAsync({
549
- prompt: 'none',
550
- id_token_hint: idToken,
551
- scope: 'openid',
552
- }).then((silentSigninResponse) => {
553
- const iFrameIdTokenPayload = silentSigninResponse.tokens.idTokenPayload;
554
- if (idTokenPayload.sub === iFrameIdTokenPayload.sub) {
555
- const sessionState = silentSigninResponse.sessionState;
556
- this.checkSessionIFrame.start(silentSigninResponse.sessionState);
557
- if (idTokenPayload.sid === iFrameIdTokenPayload.sid) {
558
- console.debug('SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:', sessionState);
559
- }
560
- else {
561
- console.debug('SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:', sessionState);
562
- }
563
- }
564
- else {
565
- console.debug('SessionMonitor._callback: Different subject signed into OP:', iFrameIdTokenPayload.sub);
566
- }
567
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
568
- }).catch((e) => __awaiter(this, void 0, void 0, function* () {
569
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
570
- for (const [key, oidc] of Object.entries(oidcDatabase)) {
571
- // @ts-ignore
572
- yield oidc.logoutOtherTabAsync(this.configuration.client_id, idTokenPayload.sub);
573
- }
574
- }));
575
- };
576
- this.checkSessionIFrame = new checkSessionIFrame_1.CheckSessionIFrame(checkSessionCallback, clientId, checkSessionIFrameUri);
577
- this.checkSessionIFrame.load().then(() => {
578
- this.checkSessionIFrame.start(sessionState);
579
- resolve();
580
- }).catch((e) => {
581
- reject(e);
582
- });
583
- }
584
- else {
585
- resolve();
586
- }
587
- });
588
- });
589
- }
590
298
  loginCallbackAsync(isSilenSignin = false) {
591
299
  return __awaiter(this, void 0, void 0, function* () {
592
300
  if (this.loginCallbackPromise !== null) {
593
301
  return this.loginCallbackPromise;
594
302
  }
595
303
  const loginCallbackLocalAsync = () => __awaiter(this, void 0, void 0, function* () {
596
- const response = yield this._loginCallbackAsync(isSilenSignin);
304
+ const response = yield (0, login_1.loginCallbackAsync)(this)(isSilenSignin);
597
305
  // @ts-ignore
598
306
  const parsedTokens = response.tokens;
599
307
  // @ts-ignore
600
308
  this.tokens = response.tokens;
601
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
309
+ const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName);
602
310
  if (!serviceWorker) {
603
- const session = (0, initSession_1.initSession)(this.configurationName, this.configuration.redirect_uri, this.configuration.storage);
311
+ const session = (0, initSession_1.initSession)(this.configurationName, this.configuration.storage);
604
312
  session.setTokens(parsedTokens);
605
313
  }
606
314
  this.publishEvent(Oidc.eventNames.token_aquired, parsedTokens);
@@ -614,159 +322,23 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
614
322
  });
615
323
  });
616
324
  }
617
- _loginCallbackAsync(isSilentSignin = false) {
618
- return __awaiter(this, void 0, void 0, function* () {
619
- try {
620
- this.publishEvent(eventNames.loginCallbackAsync_begin, {});
621
- const configuration = this.configuration;
622
- const clientId = configuration.client_id;
623
- const redirectUri = isSilentSignin ? configuration.silent_redirect_uri : configuration.redirect_uri;
624
- const authority = configuration.authority;
625
- const tokenRequestTimeout = configuration.token_request_timeout;
626
- const oidcServerConfiguration = yield this.initAsync(authority, configuration.authority_configuration);
627
- const queryParams = (0, route_utils_1.getParseQueryStringFromLocation)(window.location.href);
628
- const sessionState = queryParams.session_state;
629
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName, configuration.redirect_uri);
630
- let storage = null;
631
- let nonceData = null;
632
- if (serviceWorker) {
633
- serviceWorker.startKeepAliveServiceWorker();
634
- yield serviceWorker.initAsync(oidcServerConfiguration, 'loginCallbackAsync', configuration);
635
- const items = yield serviceWorker.loadItemsAsync();
636
- storage = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker.saveItemsAsync, items);
637
- const dummy = yield storage.getItem('dummy');
638
- if (!dummy) {
639
- throw new Error('Service Worker storage disapear');
640
- }
641
- yield storage.removeItem('dummy');
642
- yield serviceWorker.setSessionStateAsync(sessionState);
643
- nonceData = yield serviceWorker.getNonceAsync();
644
- }
645
- else {
646
- const session = (0, initSession_1.initSession)(this.configurationName, redirectUri);
647
- session.setSessionState(sessionState);
648
- const items = yield session.loadItemsAsync();
649
- storage = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, items);
650
- nonceData = yield session.getNonceAsync();
651
- }
652
- return new Promise((resolve, reject) => {
653
- let queryStringUtil = new noHashQueryStringUtils_1.NoHashQueryStringUtils();
654
- if (redirectUri.includes('#')) {
655
- const splithash = window.location.href.split('#');
656
- if (splithash.length === 2 && splithash[1].includes('?')) {
657
- queryStringUtil = new noHashQueryStringUtils_1.HashQueryStringUtils();
658
- }
659
- }
660
- const authorizationHandler = new appauth_1.RedirectRequestHandler(storage, queryStringUtil, window.location, new appauth_1.DefaultCrypto());
661
- const notifier = new appauth_1.AuthorizationNotifier();
662
- authorizationHandler.setAuthorizationNotifier(notifier);
663
- notifier.setAuthorizationListener((request, response, error) => {
664
- if (error) {
665
- reject(error);
666
- return;
667
- }
668
- if (!response) {
669
- reject(new Error('no response'));
670
- return;
671
- }
672
- let extras = null;
673
- if (request && request.internal) {
674
- extras = {};
675
- extras.code_verifier = request.internal.code_verifier;
676
- if (configuration.token_request_extras) {
677
- for (const [key, value] of Object.entries(configuration.token_request_extras)) {
678
- extras[key] = value;
679
- }
680
- }
681
- }
682
- const tokenRequest = new appauth_1.TokenRequest({
683
- client_id: clientId,
684
- redirect_uri: redirectUri,
685
- grant_type: appauth_1.GRANT_TYPE_AUTHORIZATION_CODE,
686
- code: response.code,
687
- refresh_token: undefined,
688
- extras,
689
- });
690
- let timeoutId = setTimeout(() => {
691
- reject(new Error('performTokenRequest timeout'));
692
- timeoutId = null;
693
- }, tokenRequestTimeout !== null && tokenRequestTimeout !== void 0 ? tokenRequestTimeout : 12000);
694
- try {
695
- const tokenHandler = new appauth_1.BaseTokenRequestHandler(new appauth_1.FetchRequestor());
696
- tokenHandler.performTokenRequest(oidcServerConfiguration, tokenRequest).then((tokenResponse) => __awaiter(this, void 0, void 0, function* () {
697
- if (timeoutId) {
698
- clearTimeout(timeoutId);
699
- this.timeoutId = null;
700
- let loginParams = null;
701
- let formattedTokens = null;
702
- if (serviceWorker) {
703
- const { tokens } = yield serviceWorker.initAsync(oidcServerConfiguration, 'syncTokensAsync', configuration);
704
- loginParams = serviceWorker.getLoginParams(this.configurationName, redirectUri);
705
- formattedTokens = tokens;
706
- }
707
- else {
708
- const session = (0, initSession_1.initSession)(this.configurationName, redirectUri, configuration.storage);
709
- loginParams = session.getLoginParams(this.configurationName, redirectUri);
710
- formattedTokens = (0, parseTokens_1.setTokens)(tokenResponse, null, configuration.token_renew_mode);
711
- }
712
- if (!(0, parseTokens_1.isTokensOidcValid)(formattedTokens, nonceData.nonce, oidcServerConfiguration)) {
713
- const exception = new Error('Tokens are not OpenID valid');
714
- if (timeoutId) {
715
- clearTimeout(timeoutId);
716
- this.timeoutId = null;
717
- this.publishEvent(eventNames.loginCallbackAsync_error, exception);
718
- console.error(exception);
719
- reject(exception);
720
- }
721
- }
722
- this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, clientId, sessionState, isSilentSignin).then(() => {
723
- this.publishEvent(eventNames.loginCallbackAsync_end, {});
724
- resolve({
725
- tokens: formattedTokens,
726
- state: request.state,
727
- callbackPath: loginParams.callbackPath,
728
- });
729
- });
730
- }
731
- }));
732
- }
733
- catch (exception) {
734
- if (timeoutId) {
735
- clearTimeout(timeoutId);
736
- this.timeoutId = null;
737
- this.publishEvent(eventNames.loginCallbackAsync_error, exception);
738
- console.error(exception);
739
- reject(exception);
740
- }
741
- }
742
- });
743
- authorizationHandler.completeAuthorizationRequestIfPossible();
744
- });
745
- }
746
- catch (exception) {
747
- console.error(exception);
748
- this.publishEvent(eventNames.loginCallbackAsync_error, exception);
749
- throw exception;
750
- }
751
- });
752
- }
753
325
  synchroniseTokensAsync(refreshToken, index = 0, forceRefresh = false, extras = null, updateTokens) {
754
326
  return __awaiter(this, void 0, void 0, function* () {
755
327
  while (!navigator.onLine && document.hidden) {
756
328
  yield (0, initWorker_1.sleepAsync)(1000);
757
- this.publishEvent(eventNames.refreshTokensAsync, { message: 'wait because navigator is offline and hidden' });
329
+ this.publishEvent(events_1.eventNames.refreshTokensAsync, { message: 'wait because navigator is offline and hidden' });
758
330
  }
759
331
  let numberTryOnline = 6;
760
332
  while (!navigator.onLine && numberTryOnline > 0) {
761
333
  yield (0, initWorker_1.sleepAsync)(1000);
762
334
  numberTryOnline--;
763
- this.publishEvent(eventNames.refreshTokensAsync, { message: `wait because navigator is offline try ${numberTryOnline}` });
335
+ this.publishEvent(events_1.eventNames.refreshTokensAsync, { message: `wait because navigator is offline try ${numberTryOnline}` });
764
336
  }
765
337
  let numberTryHidden = Math.floor(Math.random() * 15) + 10;
766
338
  while (document.hidden && numberTryHidden > 0) {
767
339
  yield (0, initWorker_1.sleepAsync)(1000);
768
340
  numberTryHidden--;
769
- this.publishEvent(eventNames.refreshTokensAsync, { message: `wait because navigator is hidden try ${numberTryHidden}` });
341
+ this.publishEvent(events_1.eventNames.refreshTokensAsync, { message: `wait because navigator is hidden try ${numberTryHidden}` });
770
342
  }
771
343
  const isDocumentHidden = document.hidden;
772
344
  const nextIndex = isDocumentHidden ? index : index + 1;
@@ -774,18 +346,21 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
774
346
  extras = {};
775
347
  }
776
348
  const configuration = this.configuration;
349
+ const silentLoginAsync = (extras, state, scope = null) => {
350
+ return (0, silentLogin_1._silentLoginAsync)(this.configurationName, this.configuration, this.publishEvent.bind(this))(extras, state, scope);
351
+ };
777
352
  const localsilentLoginAsync = () => __awaiter(this, void 0, void 0, function* () {
778
353
  try {
779
354
  let loginParams = null;
780
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName, configuration.redirect_uri);
355
+ const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName);
781
356
  if (serviceWorker) {
782
- loginParams = serviceWorker.getLoginParams(this.configurationName, configuration.redirect_uri);
357
+ loginParams = serviceWorker.getLoginParams(this.configurationName);
783
358
  }
784
359
  else {
785
- const session = (0, initSession_1.initSession)(this.configurationName, configuration.redirect_uri, configuration.storage);
786
- loginParams = session.getLoginParams(this.configurationName, configuration.redirect_uri);
360
+ const session = (0, initSession_1.initSession)(this.configurationName, configuration.storage);
361
+ loginParams = session.getLoginParams(this.configurationName);
787
362
  }
788
- const silent_token_response = yield this.silentLoginAsync(Object.assign(Object.assign(Object.assign({}, loginParams.extras), extras), { prompt: 'none' }), loginParams.state);
363
+ const silent_token_response = yield silentLoginAsync(Object.assign(Object.assign(Object.assign({}, loginParams.extras), extras), { prompt: 'none' }), loginParams.state);
789
364
  if (silent_token_response) {
790
365
  updateTokens(silent_token_response.tokens);
791
366
  this.publishEvent(Oidc.eventNames.token_renewed, {});
@@ -794,18 +369,18 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
794
369
  }
795
370
  catch (exceptionSilent) {
796
371
  console.error(exceptionSilent);
797
- this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: 'exceptionSilent', exception: exceptionSilent.message });
372
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_silent_error, { message: 'exceptionSilent', exception: exceptionSilent.message });
798
373
  if (exceptionSilent && exceptionSilent.message && exceptionSilent.message.startsWith('oidc')) {
799
374
  updateTokens(null);
800
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token silent' });
375
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token silent' });
801
376
  return { tokens: null, status: 'SESSION_LOST' };
802
377
  }
803
378
  }
804
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token silent return' });
379
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token silent return' });
805
380
  return yield this.synchroniseTokensAsync(null, nextIndex, forceRefresh, extras, updateTokens);
806
381
  });
807
382
  if (index > 4) {
808
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token' });
383
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token' });
809
384
  return { tokens: null, status: 'SESSION_LOST' };
810
385
  }
811
386
  try {
@@ -813,7 +388,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
813
388
  switch (status) {
814
389
  case 'SESSION_LOST':
815
390
  updateTokens(null);
816
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token session lost' });
391
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token session lost' });
817
392
  return { tokens: null, status: 'SESSION_LOST' };
818
393
  case 'NOT_CONNECTED':
819
394
  updateTokens(null);
@@ -827,13 +402,13 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
827
402
  return { tokens, status: 'LOGGED_IN' };
828
403
  case 'LOGOUT_FROM_ANOTHER_TAB':
829
404
  updateTokens(null);
830
- this.publishEvent(eventNames.logout_from_another_tab, { status: 'session syncTokensAsync' });
405
+ this.publishEvent(events_1.eventNames.logout_from_another_tab, { status: 'session syncTokensAsync' });
831
406
  return { tokens: null, status: 'LOGGED_OUT' };
832
407
  case 'REQUIRE_SYNC_TOKENS':
833
- this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
408
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
834
409
  return yield localsilentLoginAsync();
835
410
  default: {
836
- this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
411
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
837
412
  if (!refreshToken) {
838
413
  return yield localsilentLoginAsync();
839
414
  }
@@ -841,7 +416,12 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
841
416
  const redirectUri = configuration.redirect_uri;
842
417
  const authority = configuration.authority;
843
418
  const tokenExtras = configuration.token_request_extras ? configuration.token_request_extras : {};
844
- const finalExtras = Object.assign(Object.assign({}, tokenExtras), extras);
419
+ const finalExtras = Object.assign({}, tokenExtras);
420
+ for (const [key, value] of Object.entries(extras)) {
421
+ if (key.endsWith(':token_request')) {
422
+ finalExtras[key.replace(':token_request', '')] = value;
423
+ }
424
+ }
845
425
  const localFunctionAsync = () => __awaiter(this, void 0, void 0, function* () {
846
426
  const details = {
847
427
  client_id: clientId,
@@ -855,16 +435,16 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
855
435
  if (tokenResponse.success) {
856
436
  if (!(0, parseTokens_1.isTokensOidcValid)(tokenResponse.data, nonce.nonce, oidcServerConfiguration)) {
857
437
  updateTokens(null);
858
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token return not valid tokens' });
438
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token return not valid tokens' });
859
439
  return { tokens: null, status: 'SESSION_LOST' };
860
440
  }
861
441
  updateTokens(tokenResponse.data);
862
- this.publishEvent(eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
442
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
863
443
  this.publishEvent(Oidc.eventNames.token_renewed, { reason: 'REFRESH_TOKEN' });
864
444
  return { tokens: tokenResponse.data, status: 'LOGGED_IN' };
865
445
  }
866
446
  else {
867
- this.publishEvent(eventNames.refreshTokensAsync_silent_error, {
447
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_silent_error, {
868
448
  message: 'bad request',
869
449
  tokenResponse,
870
450
  });
@@ -878,7 +458,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
878
458
  }
879
459
  catch (exception) {
880
460
  console.error(exception);
881
- this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: 'exception', exception: exception.message });
461
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_silent_error, { message: 'exception', exception: exception.message });
882
462
  return this.synchroniseTokensAsync(refreshToken, nextIndex, forceRefresh, extras, updateTokens);
883
463
  }
884
464
  });
@@ -894,7 +474,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
894
474
  }
895
475
  let nonce = nullNonce;
896
476
  const oidcServerConfiguration = yield this.initAsync(configuration.authority, configuration.authority_configuration);
897
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, configurationName, configuration.redirect_uri);
477
+ const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, configurationName);
898
478
  if (serviceWorker) {
899
479
  const { status, tokens } = yield serviceWorker.initAsync(oidcServerConfiguration, 'syncTokensAsync', configuration);
900
480
  if (status === 'LOGGED_OUT') {
@@ -915,7 +495,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
915
495
  nonce = yield serviceWorker.getNonceAsync();
916
496
  }
917
497
  else {
918
- const session = (0, initSession_1.initSession)(configurationName, configuration.redirect_uri, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
498
+ const session = (0, initSession_1.initSession)(configurationName, (_a = configuration.storage) !== null && _a !== void 0 ? _a : sessionStorage);
919
499
  const { tokens, status } = yield session.initAsync();
920
500
  if (!tokens) {
921
501
  return { tokens: null, status: 'LOGOUT_FROM_ANOTHER_TAB', nonce: nullNonce };
@@ -953,7 +533,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
953
533
  if (this.userInfoPromise !== null) {
954
534
  return this.userInfoPromise;
955
535
  }
956
- this.userInfoPromise = userInfoAsync(this);
536
+ this.userInfoPromise = (0, user_1.userInfoAsync)(this);
957
537
  return this.userInfoPromise.then(result => {
958
538
  this.userInfoPromise = null;
959
539
  return result;
@@ -966,7 +546,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
966
546
  }
967
547
  timer_1.default.clearTimeout(this.timeoutId);
968
548
  // @ts-ignore
969
- yield renewTokensAndStartTimerAsync(this, this.tokens.refreshToken, true, extras);
549
+ yield (0, renewTokens_1.renewTokensAndStartTimerAsync)(this, this.tokens.refreshToken, true, extras);
970
550
  });
971
551
  }
972
552
  destroyAsync(status) {
@@ -976,9 +556,9 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
976
556
  if (this.checkSessionIFrame) {
977
557
  this.checkSessionIFrame.stop();
978
558
  }
979
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
559
+ const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName);
980
560
  if (!serviceWorker) {
981
- const session = (0, initSession_1.initSession)(this.configurationName, this.configuration.redirect_uri, this.configuration.storage);
561
+ const session = (0, initSession_1.initSession)(this.configurationName, this.configuration.storage);
982
562
  yield session.clearAsync(status);
983
563
  }
984
564
  else {
@@ -993,7 +573,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
993
573
  return __awaiter(this, void 0, void 0, function* () {
994
574
  // @ts-ignore
995
575
  if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
996
- this.publishEvent(eventNames.logout_from_same_tab, { message: sub });
576
+ this.publishEvent(events_1.eventNames.logout_from_same_tab, { message: sub });
997
577
  yield this.destroyAsync('LOGGED_OUT');
998
578
  }
999
579
  });
@@ -1003,7 +583,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1003
583
  // @ts-ignore
1004
584
  if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
1005
585
  yield this.destroyAsync('LOGGED_OUT');
1006
- this.publishEvent(eventNames.logout_from_another_tab, { message: 'SessionMonitor', sub });
586
+ this.publishEvent(events_1.eventNames.logout_from_another_tab, { message: 'SessionMonitor', sub });
1007
587
  }
1008
588
  });
1009
589
  }
@@ -1083,6 +663,6 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1083
663
  }
1084
664
  }
1085
665
  exports.Oidc = Oidc;
1086
- Oidc.eventNames = eventNames;
666
+ Oidc.eventNames = events_1.eventNames;
1087
667
  exports.default = Oidc;
1088
668
  //# sourceMappingURL=oidc.js.map