@axa-fr/oidc-client 7.30.2 → 7.30.4

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.
@@ -1,5 +1,5 @@
1
1
  (function() {
2
- //#region src/constants.ts
2
+ // src/constants.ts
3
3
  var scriptFilename = "OidcTrustedDomains.js";
4
4
  var TOKEN = {
5
5
  REFRESH_TOKEN: "REFRESH_TOKEN_SECURED_BY_OIDC_SERVICE_WORKER",
@@ -12,8 +12,7 @@
12
12
  access_token_invalid: "access_token_invalid",
13
13
  id_token_invalid: "id_token_invalid"
14
14
  };
15
- //#endregion
16
- //#region src/jwt.ts
15
+ // src/jwt.ts
17
16
  function strToUint8(str) {
18
17
  return new TextEncoder().encode(str);
19
18
  }
@@ -135,8 +134,7 @@
135
134
  const kid = await JWK.thumbprint(w)(jwk, demonstratingProofOfPossessionConfiguration.digestAlgorithm);
136
135
  return await JWT.sign(w)(jwk, { kid }, claims, demonstratingProofOfPossessionConfiguration);
137
136
  };
138
- //#endregion
139
- //#region src/crypto.ts
137
+ // src/crypto.ts
140
138
  function textEncodeLite(str) {
141
139
  const buf = new ArrayBuffer(str.length);
142
140
  const bufView = new Uint8Array(buf);
@@ -150,8 +148,7 @@
150
148
  }, (error) => reject(error));
151
149
  });
152
150
  }
153
- //#endregion
154
- //#region src/dpop.ts
151
+ // src/dpop.ts
155
152
  var isDpop = (trustedDomain) => {
156
153
  if (Array.isArray(trustedDomain)) return false;
157
154
  return trustedDomain.demonstratingProofOfPossession ?? false;
@@ -166,8 +163,7 @@
166
163
  if (Array.isArray(trustedDomain)) return null;
167
164
  return trustedDomain.demonstratingProofOfPossessionOnlyWhenDpopHeaderPresent ?? true;
168
165
  };
169
- //#endregion
170
- //#region src/resource.ts
166
+ // src/resource.ts
171
167
  /** Worker-only resource refresh routing hint, removed before the provider request. */
172
168
  var RESOURCE_TOKEN_REQUEST_HEADER = "x-oidc-resource";
173
169
  /** Builds an isolated storage/worker context without creating another OIDC client. */
@@ -214,8 +210,7 @@
214
210
  for (const prefix of matches[0].allowedUrlPrefixes) isResourceUrlAllowed(matches[0], prefix);
215
211
  return matches[0];
216
212
  };
217
- //#endregion
218
- //#region src/tokenContexts.ts
213
+ // src/tokenContexts.ts
219
214
  var getTokenContextEntries = (database) => Object.entries(database).flatMap(([key, configuration]) => [[key, configuration], ...Object.entries(configuration.resourceEntries ?? {})]);
220
215
  var getTokenContexts = (database) => getTokenContextEntries(database).map(([, configuration]) => configuration);
221
216
  var getOrCreateResourceContext = (configuration, resource) => {
@@ -242,8 +237,7 @@
242
237
  };
243
238
  return configuration.resourceEntries[name];
244
239
  };
245
- //#endregion
246
- //#region src/utils/normalizeUrl.ts
240
+ // src/utils/normalizeUrl.ts
247
241
  function normalizeUrl(url) {
248
242
  try {
249
243
  return new URL(url).toString();
@@ -252,8 +246,7 @@
252
246
  return url;
253
247
  }
254
248
  }
255
- //#endregion
256
- //#region src/utils/domains.ts
249
+ // src/utils/domains.ts
257
250
  function checkDomain(domains, endpoint) {
258
251
  if (!endpoint) return;
259
252
  if (!domains.find((domain) => {
@@ -297,8 +290,7 @@
297
290
  }
298
291
  return datatases;
299
292
  };
300
- //#endregion
301
- //#region src/utils/serializeHeaders.ts
293
+ // src/utils/serializeHeaders.ts
302
294
  function serializeHeaders(headers) {
303
295
  const headersObj = {};
304
296
  for (const key of headers.keys()) {
@@ -307,8 +299,7 @@
307
299
  }
308
300
  return headersObj;
309
301
  }
310
- //#endregion
311
- //#region src/utils/shouldBypassDestination.ts
302
+ // src/utils/shouldBypassDestination.ts
312
303
  var bypassedDestinations = [
313
304
  "image",
314
305
  "font",
@@ -325,11 +316,9 @@
325
316
  var shouldBypassDestination = (destination, mode) => {
326
317
  return bypassedDestinations.includes(destination) && mode !== "navigate";
327
318
  };
328
- //#endregion
329
- //#region src/utils/sleep.ts
319
+ // src/utils/sleep.ts
330
320
  var sleep = (ms) => new Promise((resolve) => setTimeout(resolve, ms));
331
- //#endregion
332
- //#region src/utils/tokens.ts
321
+ // src/utils/tokens.ts
333
322
  var parseJwt = (payload) => {
334
323
  return JSON.parse(b64DecodeUnicode(payload.replaceAll(/-/g, "+").replaceAll(/_/g, "/")));
335
324
  };
@@ -499,8 +488,7 @@
499
488
  });
500
489
  };
501
490
  }
502
- //#endregion
503
- //#region src/utils/waitForValidTokens.ts
491
+ // src/utils/waitForValidTokens.ts
504
492
  var TOKEN_RENEWAL_TIMEOUT_MS = 5e3;
505
493
  /**
506
494
  * Polls until the tokens in the given config are valid, or until a timeout elapses.
@@ -523,8 +511,7 @@
523
511
  });
524
512
  return null;
525
513
  }
526
- //#endregion
527
- //#region src/oidcConfig.ts
514
+ // src/oidcConfig.ts
528
515
  var getOidcServerUrls = (oidcServerConfiguration) => {
529
516
  return [
530
517
  oidcServerConfiguration.issuer,
@@ -568,8 +555,7 @@
568
555
  return tokenEndpoint && normalizedUrl.startsWith(normalizeUrl(tokenEndpoint)) || revocationEndpoint && normalizedUrl.startsWith(normalizeUrl(revocationEndpoint));
569
556
  });
570
557
  };
571
- //#endregion
572
- //#region src/utils/codeVerifier.ts
558
+ // src/utils/codeVerifier.ts
573
559
  function replaceCodeVerifier(codeVerifier, newCodeVerifier) {
574
560
  return codeVerifier.replace(/[?&]code_verifier=([^&]+)/i, `&code_verifier=${newCodeVerifier}`);
575
561
  }
@@ -577,11 +563,9 @@
577
563
  const match = body.match(/[?&]code_verifier=CODE_VERIFIER_SECURED_BY_OIDC_SERVICE_WORKER_([^&]+)/);
578
564
  return match ? decodeURIComponent(match[1]) : "";
579
565
  };
580
- //#endregion
581
- //#region src/version.ts
582
- var version_default = "7.30.2";
583
- //#endregion
584
- //#region src/OidcServiceWorker.ts
566
+ // src/version.ts
567
+ var version_default = "7.30.4";
568
+ // src/OidcServiceWorker.ts
585
569
  if (typeof trustedTypes !== "undefined" && typeof trustedTypes.createPolicy === "function") trustedTypes.createPolicy("default", { createScriptURL: function(url) {
586
570
  if (url === "OidcTrustedDomains.js") return url;
587
571
  else throw new Error("Untrusted script URL blocked: " + url);
@@ -1043,7 +1027,6 @@
1043
1027
  };
1044
1028
  _self.addEventListener("fetch", handleFetch);
1045
1029
  _self.addEventListener("message", handleMessage);
1046
- //#endregion
1047
1030
  })();
1048
1031
 
1049
1032
  //# sourceMappingURL=OidcServiceWorker.js.map
package/dist/version.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- declare const _default: "7.30.2";
1
+ declare const _default: "7.30.4";
2
2
  export default _default;
3
3
  //# sourceMappingURL=version.d.ts.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@axa-fr/oidc-client",
3
- "version": "7.30.2",
3
+ "version": "7.30.4",
4
4
  "private": false,
5
5
  "type": "module",
6
6
  "main": "./dist/index.umd.cjs",
@@ -20,21 +20,21 @@
20
20
  "url": "https://github.com/AxaFrance/oidc-client.git"
21
21
  },
22
22
  "dependencies": {
23
- "@axa-fr/oidc-client-service-worker": "7.30.2"
23
+ "@axa-fr/oidc-client-service-worker": "7.30.4"
24
24
  },
25
25
  "devDependencies": {
26
26
  "@testing-library/dom": "10.4.2",
27
27
  "@testing-library/jest-dom": "7.0.1",
28
28
  "@testing-library/react": "16.3.3",
29
- "@types/node": "^26.6.5",
30
- "@vitest/coverage-v8": "5.0.3",
29
+ "@types/node": "^26.6.6",
30
+ "@vitest/coverage-v8": "5.1.0",
31
31
  "cpy": "13.2.3",
32
32
  "cpy-cli": "^7.0.0",
33
- "rimraf": "6.1.3",
33
+ "rimraf": "6.1.4",
34
34
  "typescript": "npm:@typescript/typescript6@6.0.2",
35
- "vite": "8.3.4",
35
+ "vite": "8.3.8",
36
36
  "vite-plugin-dts": "5.1.2",
37
- "vitest": "5.0.3"
37
+ "vitest": "5.1.0"
38
38
  },
39
39
  "keywords": [
40
40
  "oidc",
package/src/initWorker.ts CHANGED
@@ -179,6 +179,11 @@ let controllerChangeReloading = false;
179
179
  // regardless of how many times initWorkerAsync is invoked.
180
180
  export const registrationCache = new Map<string, Promise<ServiceWorkerRegistration>>();
181
181
 
182
+ const registrationUpdateTimes = new WeakMap<ServiceWorkerRegistration, number>();
183
+ const observedRegistrations = new WeakSet<ServiceWorkerRegistration>();
184
+ const observedInstallingWorkers = new WeakSet<ServiceWorker>();
185
+ const SW_UPDATE_INTERVAL_MS = 60 * 60 * 1000;
186
+
182
187
  // AbortError surfaces during transient lifecycle events (e.g. iOS Safari tab shutdown or
183
188
  // backgrounding) and does not represent a genuine configuration problem. We treat it as
184
189
  // non-fatal, clear the cache entry so future calls can retry, and fall back to the
@@ -356,6 +361,8 @@ export const initWorkerAsync = async (
356
361
  };
357
362
 
358
363
  const trackInstallingWorker = (newSW: ServiceWorker) => {
364
+ if (observedInstallingWorkers.has(newSW)) return;
365
+ observedInstallingWorkers.add(newSW);
359
366
  stopKeepAlive();
360
367
  newSW.addEventListener('statechange', async () => {
361
368
  if (newSW.state === 'installed' && navigator.serviceWorker.controller) {
@@ -373,13 +380,16 @@ export const initWorkerAsync = async (
373
380
  });
374
381
  };
375
382
 
376
- // 1) Détection updatefound – registered BEFORE update() to avoid missing the event
377
- registration.addEventListener('updatefound', () => {
378
- const newSW = registration.installing;
379
- if (newSW) {
380
- trackInstallingWorker(newSW);
381
- }
382
- });
383
+ // Observe each registration once, before update() can emit updatefound.
384
+ if (!observedRegistrations.has(registration)) {
385
+ observedRegistrations.add(registration);
386
+ registration.addEventListener('updatefound', () => {
387
+ const newSW = registration.installing;
388
+ if (newSW) {
389
+ trackInstallingWorker(newSW);
390
+ }
391
+ });
392
+ }
383
393
 
384
394
  // Handle a SW that is already installing or waiting (e.g. when the listener above was
385
395
  // registered after the updatefound event already fired in a previous call)
@@ -396,10 +406,16 @@ export const initWorkerAsync = async (
396
406
  }
397
407
  }
398
408
 
399
- // (Optional but useful on Safari) ask for update early – non-blocking to avoid slowing init
400
- registration.update().catch(ex => {
401
- console.error(ex);
402
- });
409
+ // Keep cold-start checks without refetching scripts on every token timer tick.
410
+ // Record the attempt before starting it so concurrent calls and failures are bounded.
411
+ const now = Date.now();
412
+ const lastUpdate = registrationUpdateTimes.get(registration);
413
+ if (lastUpdate === undefined || now - lastUpdate >= SW_UPDATE_INTERVAL_MS) {
414
+ registrationUpdateTimes.set(registration, now);
415
+ registration.update().catch(ex => {
416
+ console.error(ex);
417
+ });
418
+ }
403
419
 
404
420
  // 2) Claim + init classique (Safari-safe)
405
421
  // IMPORTANT: claim() is done BEFORE registering the controllerchange listener,
@@ -0,0 +1,136 @@
1
+ import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
2
+
3
+ import { initWorkerAsync, registrationCache } from './initWorker';
4
+ import type { OidcConfiguration } from './types';
5
+
6
+ const configuration = {
7
+ service_worker_relative_url: '/OidcServiceWorker.js',
8
+ service_worker_activate: () => true,
9
+ } as OidcConfiguration;
10
+
11
+ const createRegistration = () => ({
12
+ update: vi.fn().mockResolvedValue(undefined),
13
+ addEventListener: vi.fn(),
14
+ installing: null as ServiceWorker | null,
15
+ waiting: null,
16
+ });
17
+
18
+ describe('service worker update checks', () => {
19
+ let registration: ReturnType<typeof createRegistration>;
20
+ let register: ReturnType<typeof vi.fn>;
21
+
22
+ beforeEach(() => {
23
+ registrationCache.clear();
24
+ registration = createRegistration();
25
+ register = vi.fn().mockResolvedValue(registration);
26
+ vi.stubGlobal('window', {});
27
+ vi.stubGlobal('navigator', {
28
+ serviceWorker: {
29
+ register,
30
+ controller: {},
31
+ ready: Promise.resolve(registration),
32
+ addEventListener: vi.fn(),
33
+ },
34
+ });
35
+ vi.spyOn(Date, 'now').mockReturnValue(0);
36
+ });
37
+
38
+ afterEach(() => {
39
+ registrationCache.clear();
40
+ vi.restoreAllMocks();
41
+ vi.unstubAllGlobals();
42
+ });
43
+
44
+ it('bounds checks and listeners across repeated token synchronization and configurations', async () => {
45
+ for (let tick = 0; tick < 30; tick++) {
46
+ await initWorkerAsync(configuration, tick % 2 ? 'default' : 'another');
47
+ vi.mocked(Date.now).mockReturnValue((tick + 1) * 1000);
48
+ }
49
+ expect(register).toHaveBeenCalledOnce();
50
+ expect(registration.update).toHaveBeenCalledOnce();
51
+ expect(registration.addEventListener).toHaveBeenCalledOnce();
52
+ expect(registration.addEventListener).toHaveBeenCalledWith('updatefound', expect.any(Function));
53
+ });
54
+
55
+ it('bounds concurrent initialization while an update is pending', async () => {
56
+ registration.update.mockReturnValue(new Promise(() => {}));
57
+ const workers = await Promise.all(
58
+ Array.from({ length: 10 }, () => initWorkerAsync(configuration, 'default')),
59
+ );
60
+ expect(workers.every(Boolean)).toBe(true);
61
+ expect(registration.update).toHaveBeenCalledOnce();
62
+ });
63
+
64
+ it('checks again after an hour', async () => {
65
+ await initWorkerAsync(configuration, 'default');
66
+ vi.mocked(Date.now).mockReturnValue(60 * 60 * 1000 - 1);
67
+ await initWorkerAsync(configuration, 'default');
68
+ expect(registration.update).toHaveBeenCalledOnce();
69
+ vi.mocked(Date.now).mockReturnValue(60 * 60 * 1000);
70
+ await initWorkerAsync(configuration, 'default');
71
+ expect(registration.update).toHaveBeenCalledTimes(2);
72
+ });
73
+
74
+ it('bounds failed checks and retries after the interval without blocking initialization', async () => {
75
+ vi.spyOn(console, 'error').mockImplementation(() => {});
76
+ registration.update.mockRejectedValue(new Error('offline'));
77
+ await expect(initWorkerAsync(configuration, 'default')).resolves.toBeTruthy();
78
+ await initWorkerAsync(configuration, 'default');
79
+ expect(registration.update).toHaveBeenCalledOnce();
80
+ vi.mocked(Date.now).mockReturnValue(60 * 60 * 1000);
81
+ await initWorkerAsync(configuration, 'default');
82
+ expect(registration.update).toHaveBeenCalledTimes(2);
83
+ });
84
+
85
+ it('checks and observes a replacement registration immediately', async () => {
86
+ await initWorkerAsync(configuration, 'default');
87
+ const replacement = createRegistration();
88
+ registrationCache.clear();
89
+ register.mockResolvedValue(replacement);
90
+ await initWorkerAsync(configuration, 'default');
91
+ expect(replacement.update).toHaveBeenCalledOnce();
92
+ expect(replacement.addEventListener).toHaveBeenCalledOnce();
93
+ });
94
+
95
+ it('still claims a callback page without a controller', async () => {
96
+ const values = new Map<string, string>();
97
+ vi.stubGlobal('sessionStorage', {
98
+ getItem: (key: string) => values.get(key) ?? null,
99
+ setItem: (key: string, value: string) => values.set(key, value),
100
+ });
101
+ const postMessage = vi.fn((_data, ports) => {
102
+ Object.defineProperty(navigator.serviceWorker, 'controller', {
103
+ value: {},
104
+ configurable: true,
105
+ });
106
+ ports[0].postMessage({});
107
+ });
108
+ Object.assign(registration, { active: { postMessage } });
109
+ Object.defineProperty(navigator.serviceWorker, 'controller', {
110
+ value: null,
111
+ configurable: true,
112
+ });
113
+
114
+ await expect(initWorkerAsync(configuration, 'default')).resolves.toBeTruthy();
115
+
116
+ expect(postMessage).toHaveBeenCalledWith(
117
+ expect.objectContaining({ type: 'claim' }),
118
+ expect.any(Array),
119
+ );
120
+ expect(registration.update).toHaveBeenCalledOnce();
121
+ });
122
+
123
+ it('observes installing workers once and still discovers replacements during the interval', async () => {
124
+ const installing = { addEventListener: vi.fn() };
125
+ registration.installing = installing as unknown as ServiceWorker;
126
+ await initWorkerAsync(configuration, 'default');
127
+ await initWorkerAsync(configuration, 'default');
128
+ expect(installing.addEventListener).toHaveBeenCalledOnce();
129
+ const replacement = { addEventListener: vi.fn() };
130
+ registration.installing = replacement as unknown as ServiceWorker;
131
+ const onUpdateFound = registration.addEventListener.mock.calls[0][1];
132
+ onUpdateFound();
133
+ expect(replacement.addEventListener).toHaveBeenCalledWith('statechange', expect.any(Function));
134
+ expect(registration.update).toHaveBeenCalledOnce();
135
+ });
136
+ });
@@ -156,6 +156,104 @@ describe.each(['service worker', 'browser storage'])('session restoration with %
156
156
  expect(clearWorker).not.toHaveBeenCalled();
157
157
  });
158
158
 
159
+ it('does not renew unexpired stored tokens during restoration', async () => {
160
+ const renew = vi.spyOn(renewal, 'renewTokensAndStartTimerAsync');
161
+ await expect(restore()).resolves.toBe(true);
162
+ expect(renew).not.toHaveBeenCalled();
163
+ });
164
+
165
+ it.each([false, true])(
166
+ 'awaits expired-token renewal before readiness (saved metadata: %s)',
167
+ async saved => {
168
+ vi.setSystemTime((tokens.expiresAt + 1) * 1000);
169
+ if (saved) loginStateStorage['oidc.login.default'] = JSON.stringify(loginParams);
170
+ const renewed = {
171
+ ...tokens,
172
+ accessToken: 'renewed-access-token',
173
+ expiresAt: tokens.expiresAt + 3600,
174
+ };
175
+ let finishRenewal: () => void;
176
+ const renew = vi.spyOn(renewal, 'renewTokensAndStartTimerAsync').mockImplementation(
177
+ () =>
178
+ new Promise(resolve => {
179
+ finishRenewal = () => {
180
+ oidc.tokens = renewed;
181
+ resolve(renewed);
182
+ };
183
+ }),
184
+ );
185
+
186
+ const restoring = restore();
187
+ await vi.waitFor(() => expect(renew).toHaveBeenCalledOnce());
188
+ expect(renew).toHaveBeenCalledWith(
189
+ oidc,
190
+ true,
191
+ saved ? loginParams.extras : undefined,
192
+ saved ? loginParams.scope : undefined,
193
+ );
194
+ expect(renewal.autoRenewTokens).not.toHaveBeenCalled();
195
+ expect(getSessionState).not.toHaveBeenCalled();
196
+ expect(oidc.userInfoAsync).not.toHaveBeenCalled();
197
+ expect(oidc.publishEvent).not.toHaveBeenCalledWith(
198
+ eventNames.tryKeepExistingSessionAsync_end,
199
+ expect.objectContaining({ success: true }),
200
+ );
201
+
202
+ finishRenewal();
203
+ await expect(restoring).resolves.toBe(true);
204
+ expect(oidc.tokens).toEqual(renewed);
205
+ expect(renewal.autoRenewTokens).toHaveBeenCalledWith(
206
+ oidc,
207
+ renewed.expiresAt,
208
+ saved ? loginParams.extras : undefined,
209
+ saved ? loginParams.scope : undefined,
210
+ );
211
+ expect(oidc.userInfoAsync).toHaveBeenCalledOnce();
212
+ expect(vi.getTimerCount()).toBe(1);
213
+ },
214
+ );
215
+
216
+ it.each([null, { ...tokens, expiresAt: 1 }])(
217
+ 'returns false when renewal produces no valid tokens: %j',
218
+ async result => {
219
+ vi.setSystemTime((tokens.expiresAt + 1) * 1000);
220
+ vi.spyOn(renewal, 'renewTokensAndStartTimerAsync').mockResolvedValue(result);
221
+
222
+ await expect(restore()).resolves.toBe(false);
223
+
224
+ expect(oidc.tokens).toBeNull();
225
+ expect(oidc.userInfo).toBeNull();
226
+ expect(renewal.autoRenewTokens).not.toHaveBeenCalled();
227
+ expect(getSessionState).not.toHaveBeenCalled();
228
+ expect(oidc.userInfoAsync).not.toHaveBeenCalled();
229
+ expect(vi.getTimerCount()).toBe(0);
230
+ expect(oidc.publishEvent).toHaveBeenCalledWith(
231
+ eventNames.tryKeepExistingSessionAsync_end,
232
+ expect.objectContaining({ success: false }),
233
+ );
234
+ },
235
+ );
236
+
237
+ it('cleans up a rejected initial renewal and allows restoration to be retried', async () => {
238
+ vi.setSystemTime((tokens.expiresAt + 1) * 1000);
239
+ const renew = vi
240
+ .spyOn(renewal, 'renewTokensAndStartTimerAsync')
241
+ .mockRejectedValueOnce(new Error('renewal failed'));
242
+ await expect(restore()).resolves.toBe(false);
243
+ expect(oidc.tokens).toBeNull();
244
+ expect(oidc.timeoutId).toBeNull();
245
+ expect(oidc.userInfoAsync).not.toHaveBeenCalled();
246
+ expect(vi.getTimerCount()).toBe(0);
247
+
248
+ renew.mockImplementationOnce(async () => {
249
+ const renewed = { ...tokens, expiresAt: tokens.expiresAt + 3600 };
250
+ oidc.tokens = renewed;
251
+ return renewed;
252
+ });
253
+ await expect(restore()).resolves.toBe(true);
254
+ expect(renew).toHaveBeenCalledTimes(2);
255
+ });
256
+
159
257
  it.each(['session state', 'session monitoring', 'user info'])(
160
258
  'clears page state on a %s failure and allows a successful retry',
161
259
  async stage => {
@@ -2,10 +2,30 @@ import { eventNames } from './events';
2
2
  import { initSession } from './initSession';
3
3
  import { initWorkerAsync } from './initWorker';
4
4
  import Oidc from './oidc';
5
- import { setTokens } from './parseTokens';
6
- import { autoRenewTokens } from './renewTokens';
5
+ import { isTokensValid, setTokens } from './parseTokens';
6
+ import { autoRenewTokens, renewTokensAndStartTimerAsync } from './renewTokens';
7
7
  import timer from './timer';
8
8
 
9
+ const renewExpiredSessionAsync = async (oidc: Oidc, loginParams) => {
10
+ if (isTokensValid(oidc.tokens)) return true;
11
+
12
+ const tokens = await renewTokensAndStartTimerAsync(
13
+ oidc,
14
+ true,
15
+ loginParams?.extras,
16
+ loginParams?.scope,
17
+ );
18
+ if (isTokensValid(tokens)) return true;
19
+
20
+ oidc.tokens = null;
21
+ oidc.userInfo = null;
22
+ oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
23
+ success: false,
24
+ message: 'stored tokens could not be renewed',
25
+ });
26
+ return false;
27
+ };
28
+
9
29
  export const tryKeepSessionAsync = async (oidc: Oidc) => {
10
30
  let serviceWorker;
11
31
  if (oidc.tokens != null) {
@@ -30,6 +50,7 @@ export const tryKeepSessionAsync = async (oidc: Oidc) => {
30
50
  // @ts-ignore
31
51
  oidc.tokens = tokens;
32
52
  const getLoginParams = serviceWorker.getLoginParams(oidc.configurationName);
53
+ if (!(await renewExpiredSessionAsync(oidc, getLoginParams))) return false;
33
54
  // @ts-ignore
34
55
  oidc.timeoutId = autoRenewTokens(
35
56
  oidc,
@@ -73,6 +94,7 @@ export const tryKeepSessionAsync = async (oidc: Oidc) => {
73
94
  // @ts-ignore
74
95
  oidc.tokens = setTokens(tokens, null, configuration.token_renew_mode);
75
96
  const getLoginParams = session.getLoginParams();
97
+ if (!(await renewExpiredSessionAsync(oidc, getLoginParams))) return false;
76
98
  // @ts-ignore
77
99
  oidc.timeoutId = autoRenewTokens(
78
100
  oidc,
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export default '7.30.2';
1
+ export default '7.30.4';