@axa-fr/react-oidc 6.11.4-alpha0 → 6.11.4-alpha2

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 (64) hide show
  1. package/dist/OidcProvider.d.ts +1 -1
  2. package/dist/OidcProvider.d.ts.map +1 -1
  3. package/dist/OidcSecure.d.ts +1 -1
  4. package/dist/OidcSecure.d.ts.map +1 -1
  5. package/dist/ReactOidc.d.ts +1 -1
  6. package/dist/ReactOidc.d.ts.map +1 -1
  7. package/dist/index.d.ts +1 -1
  8. package/dist/index.d.ts.map +1 -1
  9. package/dist/index.js.map +1 -1
  10. package/dist/vanilla/checkSession.d.ts +5 -0
  11. package/dist/vanilla/checkSession.d.ts.map +1 -0
  12. package/dist/vanilla/checkSession.js +68 -0
  13. package/dist/vanilla/checkSession.js.map +1 -0
  14. package/dist/vanilla/events.d.ts +29 -0
  15. package/dist/vanilla/events.d.ts.map +1 -0
  16. package/dist/vanilla/events.js +32 -0
  17. package/dist/vanilla/events.js.map +1 -0
  18. package/dist/vanilla/initWorker.d.ts +1 -1
  19. package/dist/vanilla/initWorker.d.ts.map +1 -1
  20. package/dist/vanilla/initWorker.js +2 -2
  21. package/dist/vanilla/initWorker.js.map +1 -1
  22. package/dist/vanilla/login.d.ts +4 -0
  23. package/dist/vanilla/login.d.ts.map +1 -0
  24. package/dist/vanilla/login.js +125 -0
  25. package/dist/vanilla/login.js.map +1 -0
  26. package/dist/vanilla/oidc.d.ts +7 -36
  27. package/dist/vanilla/oidc.d.ts.map +1 -1
  28. package/dist/vanilla/oidc.js +53 -349
  29. package/dist/vanilla/oidc.js.map +1 -1
  30. package/dist/vanilla/requests.d.ts +2 -0
  31. package/dist/vanilla/requests.d.ts.map +1 -1
  32. package/dist/vanilla/requests.js +20 -1
  33. package/dist/vanilla/requests.js.map +1 -1
  34. package/dist/vanilla/silentLogin.d.ts +8 -0
  35. package/dist/vanilla/silentLogin.d.ts.map +1 -0
  36. package/dist/vanilla/silentLogin.js +95 -0
  37. package/dist/vanilla/silentLogin.js.map +1 -0
  38. package/dist/vanilla/types.d.ts +33 -0
  39. package/dist/vanilla/types.d.ts.map +1 -0
  40. package/dist/vanilla/types.js +3 -0
  41. package/dist/vanilla/types.js.map +1 -0
  42. package/dist/vanilla/user.d.ts +2 -0
  43. package/dist/vanilla/user.d.ts.map +1 -0
  44. package/dist/vanilla/user.js +48 -0
  45. package/dist/vanilla/user.js.map +1 -0
  46. package/dist/vanilla/vanillaOidc.d.ts +2 -1
  47. package/dist/vanilla/vanillaOidc.d.ts.map +1 -1
  48. package/dist/vanilla/vanillaOidc.js.map +1 -1
  49. package/package.json +1 -1
  50. package/src/oidc/OidcProvider.tsx +1 -1
  51. package/src/oidc/OidcSecure.tsx +1 -1
  52. package/src/oidc/ReactOidc.tsx +1 -1
  53. package/src/oidc/index.ts +1 -1
  54. package/src/oidc/vanilla/checkSession.ts +55 -0
  55. package/src/oidc/vanilla/events.ts +29 -0
  56. package/src/oidc/vanilla/index.ts +1 -1
  57. package/src/oidc/vanilla/initWorker.ts +3 -3
  58. package/src/oidc/vanilla/login.ts +118 -0
  59. package/src/oidc/vanilla/oidc.ts +23 -372
  60. package/src/oidc/vanilla/requests.ts +24 -0
  61. package/src/oidc/vanilla/silentLogin.ts +102 -0
  62. package/src/oidc/vanilla/types.ts +35 -0
  63. package/src/oidc/vanilla/user.ts +39 -0
  64. package/src/oidc/vanilla/vanillaOidc.ts +2 -1
@@ -14,24 +14,19 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
14
14
  Object.defineProperty(exports, "__esModule", { value: true });
15
15
  exports.Oidc = exports.OidcAuthorizationServiceConfiguration = void 0;
16
16
  const appauth_1 = require("@openid/appauth");
17
- const cache_1 = require("./cache");
18
- const checkSessionIFrame_1 = require("./checkSessionIFrame");
17
+ const checkSession_1 = require("./checkSession");
18
+ const events_1 = require("./events");
19
19
  const initSession_1 = require("./initSession");
20
20
  const initWorker_1 = require("./initWorker");
21
+ const login_1 = require("./login");
21
22
  const memoryStorageBackend_1 = require("./memoryStorageBackend");
22
23
  const noHashQueryStringUtils_1 = require("./noHashQueryStringUtils");
23
24
  const parseTokens_1 = require("./parseTokens");
24
25
  const requests_1 = require("./requests");
25
26
  const route_utils_1 = require("./route-utils");
27
+ const silentLogin_1 = __importDefault(require("./silentLogin"));
26
28
  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
- };
29
+ const user_1 = require("./user");
35
30
  class OidcAuthorizationServiceConfiguration extends appauth_1.AuthorizationServiceConfiguration {
36
31
  constructor(request) {
37
32
  super(request);
@@ -84,85 +79,9 @@ const autoRenewTokens = (oidc, refreshToken, expiresAt, extras = null) => {
84
79
  yield renewTokensAndStartTimerAsync(oidc, refreshToken, false, extras);
85
80
  }), 1000);
86
81
  };
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
82
  const getRandomInt = (max) => {
148
83
  return Math.floor(Math.random() * max);
149
84
  };
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
85
  class Oidc {
167
86
  constructor(configuration, configurationName = 'default') {
168
87
  var _a, _b, _c, _d;
@@ -246,94 +165,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
246
165
  }
247
166
  silentLoginAsync(extras = null, state = null, scope = null) {
248
167
  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
- }
168
+ return (0, silentLogin_1.default)(this.configurationName, this.configuration, this.publishEvent.bind(this))(extras, state, scope);
337
169
  });
338
170
  }
339
171
  initAsync(authority, authorityConfiguration) {
@@ -356,7 +188,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
356
188
  }
357
189
  const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(this.configuration.service_worker_relative_url, this.configurationName);
358
190
  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);
191
+ 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
192
  });
361
193
  this.initPromise = localFuncAsync();
362
194
  return this.initPromise.then((result) => {
@@ -376,7 +208,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
376
208
  if (this.tokens != null) {
377
209
  return false;
378
210
  }
379
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_begin, {});
211
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_begin, {});
380
212
  try {
381
213
  const configuration = this.configuration;
382
214
  const oidcServerConfiguration = yield this.initAsync(configuration.authority, configuration.authority_configuration);
@@ -392,20 +224,20 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
392
224
  const sessionState = yield serviceWorker.getSessionStateAsync();
393
225
  // @ts-ignore
394
226
  yield this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
395
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
227
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
396
228
  success: true,
397
229
  message: 'tokens inside ServiceWorker are valid',
398
230
  });
399
231
  return true;
400
232
  }
401
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
233
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
402
234
  success: false,
403
235
  message: 'no exiting session found',
404
236
  });
405
237
  }
406
238
  else {
407
239
  if (configuration.service_worker_relative_url) {
408
- this.publishEvent(eventNames.service_worker_not_supported_by_browser, {
240
+ this.publishEvent(events_1.eventNames.service_worker_not_supported_by_browser, {
409
241
  message: 'service worker is not supported by this browser',
410
242
  });
411
243
  }
@@ -419,14 +251,14 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
419
251
  const sessionState = session.getSessionState();
420
252
  // @ts-ignore
421
253
  yield this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
422
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
254
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
423
255
  success: true,
424
256
  message: 'tokens inside storage are valid',
425
257
  });
426
258
  return true;
427
259
  }
428
260
  }
429
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
261
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_end, {
430
262
  success: false,
431
263
  message: serviceWorker ? 'service worker sessions not retrieved' : 'session storage sessions not retrieved',
432
264
  });
@@ -437,7 +269,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
437
269
  if (serviceWorker) {
438
270
  yield serviceWorker.clearAsync();
439
271
  }
440
- this.publishEvent(eventNames.tryKeepExistingSessionAsync_error, 'tokens inside ServiceWorker are invalid');
272
+ this.publishEvent(events_1.eventNames.tryKeepExistingSessionAsync_error, 'tokens inside ServiceWorker are invalid');
441
273
  return false;
442
274
  }
443
275
  });
@@ -448,156 +280,27 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
448
280
  });
449
281
  });
450
282
  }
283
+ startCheckSessionAsync(checkSessionIFrameUri, clientId, sessionState, isSilentSignin = false) {
284
+ return __awaiter(this, void 0, void 0, function* () {
285
+ const getCurrentTokens = () => this.tokens;
286
+ this.checkSessionIFrame = yield (0, checkSession_1.startCheckSessionAsync)(oidcDatabase, this.configuration, this.checkSessionIFrame, this.silentLoginAsync.bind(this), getCurrentTokens)(checkSessionIFrameUri, clientId, sessionState, isSilentSignin);
287
+ });
288
+ }
451
289
  loginAsync(callbackPath = undefined, extras = null, isSilentSignin = false, scope = undefined, silentLoginOnly = false) {
452
290
  return __awaiter(this, void 0, void 0, function* () {
453
291
  if (this.loginPromise !== null) {
454
292
  return this.loginPromise;
455
293
  }
456
- const originExtras = extras;
457
- extras = Object.assign({}, extras);
458
- const loginLocalAsync = () => __awaiter(this, void 0, void 0, function* () {
459
- var _a, _b, _c;
460
- const location = window.location;
461
- const url = callbackPath || location.pathname + (location.search || '') + (location.hash || '');
462
- const configuration = this.configuration;
463
- let state;
464
- if (extras && 'state' in extras) {
465
- state = extras.state;
466
- delete extras.state;
467
- }
468
- if (silentLoginOnly) {
469
- try {
470
- const extraFinal = (_a = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _a !== void 0 ? _a : {};
471
- const silentResult = yield this.silentLoginAsync(Object.assign(Object.assign({}, extraFinal), { prompt: 'none' }), state, scope);
472
- if (silentResult) {
473
- this.tokens = silentResult.tokens;
474
- this.publishEvent(eventNames.token_aquired, {});
475
- // @ts-ignore
476
- this.timeoutId = autoRenewTokens(this, this.tokens.refreshToken, this.tokens.expiresAt, extras);
477
- return {};
478
- }
479
- }
480
- catch (e) {
481
- return e;
482
- }
483
- }
484
- this.publishEvent(eventNames.loginAsync_begin, {});
485
- console.log('extras', extras);
486
- if (extras) {
487
- for (const key of Object.keys(extras)) {
488
- if (key.endsWith(':authorize_request')) {
489
- delete extras[key];
490
- }
491
- }
492
- }
493
- try {
494
- const redirectUri = isSilentSignin ? configuration.silent_redirect_uri : configuration.redirect_uri;
495
- if (!scope) {
496
- scope = configuration.scope;
497
- }
498
- const extraFinal = (_b = extras !== null && extras !== void 0 ? extras : configuration.extras) !== null && _b !== void 0 ? _b : {};
499
- if (!extraFinal.nonce) {
500
- extraFinal.nonce = randomString(12);
501
- }
502
- const nonce = { nonce: extraFinal.nonce };
503
- const serviceWorker = yield (0, initWorker_1.initWorkerAsync)(configuration.service_worker_relative_url, this.configurationName);
504
- const oidcServerConfiguration = yield this.initAsync(configuration.authority, configuration.authority_configuration);
505
- let storage;
506
- if (serviceWorker) {
507
- serviceWorker.setLoginParams(this.configurationName, { callbackPath: url, extras: originExtras, state });
508
- serviceWorker.startKeepAliveServiceWorker();
509
- yield serviceWorker.initAsync(oidcServerConfiguration, 'loginAsync', configuration);
510
- yield serviceWorker.setNonceAsync(nonce);
511
- storage = new memoryStorageBackend_1.MemoryStorageBackend(serviceWorker.saveItemsAsync, {});
512
- yield storage.setItem('dummy', {});
513
- }
514
- else {
515
- let session = (0, initSession_1.initSession)(this.configurationName, (_c = configuration.storage) !== null && _c !== void 0 ? _c : sessionStorage);
516
- session.setLoginParams(this.configurationName, { callbackPath: url, extras: originExtras, state });
517
- session = (0, initSession_1.initSession)(this.configurationName);
518
- yield session.setNonceAsync(nonce);
519
- storage = new memoryStorageBackend_1.MemoryStorageBackend(session.saveItemsAsync, {});
520
- }
521
- // @ts-ignore
522
- const queryStringUtil = redirectUri.includes('#') ? new noHashQueryStringUtils_1.HashQueryStringUtils() : new noHashQueryStringUtils_1.NoHashQueryStringUtils();
523
- const authorizationHandler = new appauth_1.RedirectRequestHandler(storage, queryStringUtil, window.location, new appauth_1.DefaultCrypto());
524
- const authRequest = new appauth_1.AuthorizationRequest({
525
- client_id: configuration.client_id,
526
- redirect_uri: redirectUri,
527
- scope,
528
- response_type: appauth_1.AuthorizationRequest.RESPONSE_TYPE_CODE,
529
- state,
530
- extras: extraFinal,
531
- });
532
- authorizationHandler.performAuthorizationRequest(oidcServerConfiguration, authRequest);
533
- }
534
- catch (exception) {
535
- this.publishEvent(eventNames.loginAsync_error, exception);
536
- throw exception;
537
- }
538
- });
539
- this.loginPromise = loginLocalAsync();
294
+ if (silentLoginOnly) {
295
+ return (0, login_1.defaultSilentLoginAsync2)(window, this.configurationName, this.configuration, this.publishEvent.bind(this), this)(extras, scope);
296
+ }
297
+ this.loginPromise = (0, login_1.defaultLoginAsync)(window, this.configurationName, this.configuration, this.silentLoginAsync.bind(this), this.publishEvent.bind(this), this.initAsync.bind(this))(callbackPath, extras, isSilentSignin, scope);
540
298
  return this.loginPromise.then(result => {
541
299
  this.loginPromise = null;
542
300
  return result;
543
301
  });
544
302
  });
545
303
  }
546
- startCheckSessionAsync(checkSessionIFrameUri, clientId, sessionState, isSilentSignin = false) {
547
- return __awaiter(this, void 0, void 0, function* () {
548
- return new Promise((resolve, reject) => {
549
- if (this.configuration.silent_login_uri && this.configuration.silent_redirect_uri && this.configuration.monitor_session && checkSessionIFrameUri && sessionState && !isSilentSignin) {
550
- const checkSessionCallback = () => {
551
- this.checkSessionIFrame.stop();
552
- if (this.tokens === null) {
553
- return;
554
- }
555
- // @ts-ignore
556
- const idToken = this.tokens.idToken;
557
- // @ts-ignore
558
- const idTokenPayload = this.tokens.idTokenPayload;
559
- this.silentLoginAsync({
560
- prompt: 'none',
561
- id_token_hint: idToken,
562
- scope: 'openid',
563
- }).then((silentSigninResponse) => {
564
- const iFrameIdTokenPayload = silentSigninResponse.tokens.idTokenPayload;
565
- if (idTokenPayload.sub === iFrameIdTokenPayload.sub) {
566
- const sessionState = silentSigninResponse.sessionState;
567
- this.checkSessionIFrame.start(silentSigninResponse.sessionState);
568
- if (idTokenPayload.sid === iFrameIdTokenPayload.sid) {
569
- console.debug('SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:', sessionState);
570
- }
571
- else {
572
- console.debug('SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:', sessionState);
573
- }
574
- }
575
- else {
576
- console.debug('SessionMonitor._callback: Different subject signed into OP:', iFrameIdTokenPayload.sub);
577
- }
578
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
579
- }).catch((e) => __awaiter(this, void 0, void 0, function* () {
580
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
581
- for (const [key, oidc] of Object.entries(oidcDatabase)) {
582
- // @ts-ignore
583
- yield oidc.logoutOtherTabAsync(this.configuration.client_id, idTokenPayload.sub);
584
- }
585
- }));
586
- };
587
- this.checkSessionIFrame = new checkSessionIFrame_1.CheckSessionIFrame(checkSessionCallback, clientId, checkSessionIFrameUri);
588
- this.checkSessionIFrame.load().then(() => {
589
- this.checkSessionIFrame.start(sessionState);
590
- resolve();
591
- }).catch((e) => {
592
- reject(e);
593
- });
594
- }
595
- else {
596
- resolve();
597
- }
598
- });
599
- });
600
- }
601
304
  loginCallbackAsync(isSilenSignin = false) {
602
305
  return __awaiter(this, void 0, void 0, function* () {
603
306
  if (this.loginCallbackPromise !== null) {
@@ -628,7 +331,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
628
331
  _loginCallbackAsync(isSilentSignin = false) {
629
332
  return __awaiter(this, void 0, void 0, function* () {
630
333
  try {
631
- this.publishEvent(eventNames.loginCallbackAsync_begin, {});
334
+ this.publishEvent(events_1.eventNames.loginCallbackAsync_begin, {});
632
335
  const configuration = this.configuration;
633
336
  const clientId = configuration.client_id;
634
337
  const redirectUri = isSilentSignin ? configuration.silent_redirect_uri : configuration.redirect_uri;
@@ -675,6 +378,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
675
378
  const notifier = new appauth_1.AuthorizationNotifier();
676
379
  authorizationHandler.setAuthorizationNotifier(notifier);
677
380
  notifier.setAuthorizationListener((request, response, error) => {
381
+ var _a;
678
382
  if (error) {
679
383
  reject(error);
680
384
  return;
@@ -683,9 +387,9 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
683
387
  reject(new Error('no response'));
684
388
  return;
685
389
  }
686
- let extras = null;
390
+ const extras = {};
687
391
  if (request && request.internal) {
688
- extras = {};
392
+ // @ts-ignore
689
393
  extras.code_verifier = request.internal.code_verifier;
690
394
  if (configuration.token_request_extras) {
691
395
  for (const [key, value] of Object.entries(configuration.token_request_extras)) {
@@ -694,7 +398,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
694
398
  }
695
399
  if (getLoginParams && getLoginParams.extras) {
696
400
  for (const [key, value] of Object.entries(getLoginParams.extras)) {
697
- if (key.endsWith(':authorize_request')) {
401
+ if (key.endsWith(':token_request')) {
698
402
  extras[key.replace(':token_request', '')] = value;
699
403
  }
700
404
  }
@@ -703,7 +407,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
703
407
  const tokenRequest = new appauth_1.TokenRequest({
704
408
  client_id: clientId,
705
409
  redirect_uri: redirectUri,
706
- grant_type: appauth_1.GRANT_TYPE_AUTHORIZATION_CODE,
410
+ grant_type: (_a = extras.grant_type) !== null && _a !== void 0 ? _a : appauth_1.GRANT_TYPE_AUTHORIZATION_CODE,
707
411
  code: response.code,
708
412
  refresh_token: undefined,
709
413
  extras,
@@ -735,13 +439,13 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
735
439
  if (timeoutId) {
736
440
  clearTimeout(timeoutId);
737
441
  this.timeoutId = null;
738
- this.publishEvent(eventNames.loginCallbackAsync_error, exception);
442
+ this.publishEvent(events_1.eventNames.loginCallbackAsync_error, exception);
739
443
  console.error(exception);
740
444
  reject(exception);
741
445
  }
742
446
  }
743
447
  this.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, clientId, sessionState, isSilentSignin).then(() => {
744
- this.publishEvent(eventNames.loginCallbackAsync_end, {});
448
+ this.publishEvent(events_1.eventNames.loginCallbackAsync_end, {});
745
449
  resolve({
746
450
  tokens: formattedTokens,
747
451
  state: request.state,
@@ -755,7 +459,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
755
459
  if (timeoutId) {
756
460
  clearTimeout(timeoutId);
757
461
  this.timeoutId = null;
758
- this.publishEvent(eventNames.loginCallbackAsync_error, exception);
462
+ this.publishEvent(events_1.eventNames.loginCallbackAsync_error, exception);
759
463
  console.error(exception);
760
464
  reject(exception);
761
465
  }
@@ -766,7 +470,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
766
470
  }
767
471
  catch (exception) {
768
472
  console.error(exception);
769
- this.publishEvent(eventNames.loginCallbackAsync_error, exception);
473
+ this.publishEvent(events_1.eventNames.loginCallbackAsync_error, exception);
770
474
  throw exception;
771
475
  }
772
476
  });
@@ -775,19 +479,19 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
775
479
  return __awaiter(this, void 0, void 0, function* () {
776
480
  while (!navigator.onLine && document.hidden) {
777
481
  yield (0, initWorker_1.sleepAsync)(1000);
778
- this.publishEvent(eventNames.refreshTokensAsync, { message: 'wait because navigator is offline and hidden' });
482
+ this.publishEvent(events_1.eventNames.refreshTokensAsync, { message: 'wait because navigator is offline and hidden' });
779
483
  }
780
484
  let numberTryOnline = 6;
781
485
  while (!navigator.onLine && numberTryOnline > 0) {
782
486
  yield (0, initWorker_1.sleepAsync)(1000);
783
487
  numberTryOnline--;
784
- this.publishEvent(eventNames.refreshTokensAsync, { message: `wait because navigator is offline try ${numberTryOnline}` });
488
+ this.publishEvent(events_1.eventNames.refreshTokensAsync, { message: `wait because navigator is offline try ${numberTryOnline}` });
785
489
  }
786
490
  let numberTryHidden = Math.floor(Math.random() * 15) + 10;
787
491
  while (document.hidden && numberTryHidden > 0) {
788
492
  yield (0, initWorker_1.sleepAsync)(1000);
789
493
  numberTryHidden--;
790
- this.publishEvent(eventNames.refreshTokensAsync, { message: `wait because navigator is hidden try ${numberTryHidden}` });
494
+ this.publishEvent(events_1.eventNames.refreshTokensAsync, { message: `wait because navigator is hidden try ${numberTryHidden}` });
791
495
  }
792
496
  const isDocumentHidden = document.hidden;
793
497
  const nextIndex = isDocumentHidden ? index : index + 1;
@@ -815,18 +519,18 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
815
519
  }
816
520
  catch (exceptionSilent) {
817
521
  console.error(exceptionSilent);
818
- this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: 'exceptionSilent', exception: exceptionSilent.message });
522
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_silent_error, { message: 'exceptionSilent', exception: exceptionSilent.message });
819
523
  if (exceptionSilent && exceptionSilent.message && exceptionSilent.message.startsWith('oidc')) {
820
524
  updateTokens(null);
821
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token silent' });
525
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token silent' });
822
526
  return { tokens: null, status: 'SESSION_LOST' };
823
527
  }
824
528
  }
825
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token silent return' });
529
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token silent return' });
826
530
  return yield this.synchroniseTokensAsync(null, nextIndex, forceRefresh, extras, updateTokens);
827
531
  });
828
532
  if (index > 4) {
829
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token' });
533
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token' });
830
534
  return { tokens: null, status: 'SESSION_LOST' };
831
535
  }
832
536
  try {
@@ -834,7 +538,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
834
538
  switch (status) {
835
539
  case 'SESSION_LOST':
836
540
  updateTokens(null);
837
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token session lost' });
541
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token session lost' });
838
542
  return { tokens: null, status: 'SESSION_LOST' };
839
543
  case 'NOT_CONNECTED':
840
544
  updateTokens(null);
@@ -848,13 +552,13 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
848
552
  return { tokens, status: 'LOGGED_IN' };
849
553
  case 'LOGOUT_FROM_ANOTHER_TAB':
850
554
  updateTokens(null);
851
- this.publishEvent(eventNames.logout_from_another_tab, { status: 'session syncTokensAsync' });
555
+ this.publishEvent(events_1.eventNames.logout_from_another_tab, { status: 'session syncTokensAsync' });
852
556
  return { tokens: null, status: 'LOGGED_OUT' };
853
557
  case 'REQUIRE_SYNC_TOKENS':
854
- this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
558
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
855
559
  return yield localsilentLoginAsync();
856
560
  default: {
857
- this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
561
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
858
562
  if (!refreshToken) {
859
563
  return yield localsilentLoginAsync();
860
564
  }
@@ -876,16 +580,16 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
876
580
  if (tokenResponse.success) {
877
581
  if (!(0, parseTokens_1.isTokensOidcValid)(tokenResponse.data, nonce.nonce, oidcServerConfiguration)) {
878
582
  updateTokens(null);
879
- this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token return not valid tokens' });
583
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_error, { message: 'refresh token return not valid tokens' });
880
584
  return { tokens: null, status: 'SESSION_LOST' };
881
585
  }
882
586
  updateTokens(tokenResponse.data);
883
- this.publishEvent(eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
587
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
884
588
  this.publishEvent(Oidc.eventNames.token_renewed, { reason: 'REFRESH_TOKEN' });
885
589
  return { tokens: tokenResponse.data, status: 'LOGGED_IN' };
886
590
  }
887
591
  else {
888
- this.publishEvent(eventNames.refreshTokensAsync_silent_error, {
592
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_silent_error, {
889
593
  message: 'bad request',
890
594
  tokenResponse,
891
595
  });
@@ -899,7 +603,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
899
603
  }
900
604
  catch (exception) {
901
605
  console.error(exception);
902
- this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: 'exception', exception: exception.message });
606
+ this.publishEvent(events_1.eventNames.refreshTokensAsync_silent_error, { message: 'exception', exception: exception.message });
903
607
  return this.synchroniseTokensAsync(refreshToken, nextIndex, forceRefresh, extras, updateTokens);
904
608
  }
905
609
  });
@@ -974,7 +678,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
974
678
  if (this.userInfoPromise !== null) {
975
679
  return this.userInfoPromise;
976
680
  }
977
- this.userInfoPromise = userInfoAsync(this);
681
+ this.userInfoPromise = (0, user_1.userInfoAsync)(this);
978
682
  return this.userInfoPromise.then(result => {
979
683
  this.userInfoPromise = null;
980
684
  return result;
@@ -1014,7 +718,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1014
718
  return __awaiter(this, void 0, void 0, function* () {
1015
719
  // @ts-ignore
1016
720
  if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
1017
- this.publishEvent(eventNames.logout_from_same_tab, { message: sub });
721
+ this.publishEvent(events_1.eventNames.logout_from_same_tab, { message: sub });
1018
722
  yield this.destroyAsync('LOGGED_OUT');
1019
723
  }
1020
724
  });
@@ -1024,7 +728,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1024
728
  // @ts-ignore
1025
729
  if (this.configuration.monitor_session && this.configuration.client_id === clientId && sub && this.tokens && this.tokens.idTokenPayload && this.tokens.idTokenPayload.sub === sub) {
1026
730
  yield this.destroyAsync('LOGGED_OUT');
1027
- this.publishEvent(eventNames.logout_from_another_tab, { message: 'SessionMonitor', sub });
731
+ this.publishEvent(events_1.eventNames.logout_from_another_tab, { message: 'SessionMonitor', sub });
1028
732
  }
1029
733
  });
1030
734
  }
@@ -1104,6 +808,6 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
1104
808
  }
1105
809
  }
1106
810
  exports.Oidc = Oidc;
1107
- Oidc.eventNames = eventNames;
811
+ Oidc.eventNames = events_1.eventNames;
1108
812
  exports.default = Oidc;
1109
813
  //# sourceMappingURL=oidc.js.map