@axa-fr/oidc-client 7.22.18 → 7.22.19

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 (73) hide show
  1. package/README.md +31 -39
  2. package/bin/copy-service-worker-files.mjs +24 -17
  3. package/dist/OidcTrustedDomains.js +14 -12
  4. package/dist/cache.d.ts.map +1 -1
  5. package/dist/checkSession.d.ts +1 -1
  6. package/dist/checkSession.d.ts.map +1 -1
  7. package/dist/checkSessionIFrame.d.ts.map +1 -1
  8. package/dist/crypto.d.ts.map +1 -1
  9. package/dist/fetch.d.ts +2 -1
  10. package/dist/fetch.d.ts.map +1 -1
  11. package/dist/index.d.ts +5 -5
  12. package/dist/index.d.ts.map +1 -1
  13. package/dist/index.js +935 -601
  14. package/dist/index.umd.cjs +2 -2
  15. package/dist/initSession.d.ts +1 -1
  16. package/dist/initSession.d.ts.map +1 -1
  17. package/dist/initWorker.d.ts +2 -2
  18. package/dist/initWorker.d.ts.map +1 -1
  19. package/dist/initWorkerOption.d.ts.map +1 -1
  20. package/dist/jwt.d.ts +2 -2
  21. package/dist/jwt.d.ts.map +1 -1
  22. package/dist/keepSession.d.ts.map +1 -1
  23. package/dist/location.d.ts.map +1 -1
  24. package/dist/login.d.ts +1 -1
  25. package/dist/login.d.ts.map +1 -1
  26. package/dist/logout.d.ts +1 -1
  27. package/dist/logout.d.ts.map +1 -1
  28. package/dist/oidc.d.ts +1 -1
  29. package/dist/oidc.d.ts.map +1 -1
  30. package/dist/oidcClient.d.ts +2 -2
  31. package/dist/oidcClient.d.ts.map +1 -1
  32. package/dist/parseTokens.d.ts.map +1 -1
  33. package/dist/renewTokens.d.ts.map +1 -1
  34. package/dist/requests.d.ts +1 -1
  35. package/dist/requests.d.ts.map +1 -1
  36. package/dist/silentLogin.d.ts.map +1 -1
  37. package/dist/timer.d.ts.map +1 -1
  38. package/dist/types.d.ts +1 -1
  39. package/dist/types.d.ts.map +1 -1
  40. package/dist/user.d.ts.map +1 -1
  41. package/dist/version.d.ts +1 -1
  42. package/package.json +2 -2
  43. package/src/cache.ts +21 -18
  44. package/src/checkSession.ts +89 -54
  45. package/src/checkSessionIFrame.ts +70 -69
  46. package/src/crypto.ts +27 -25
  47. package/src/events.ts +28 -28
  48. package/src/fetch.ts +40 -21
  49. package/src/index.ts +6 -17
  50. package/src/iniWorker.spec.ts +26 -16
  51. package/src/initSession.ts +115 -113
  52. package/src/initWorker.ts +299 -212
  53. package/src/initWorkerOption.ts +121 -114
  54. package/src/jwt.ts +150 -136
  55. package/src/keepSession.ts +100 -81
  56. package/src/location.ts +24 -26
  57. package/src/login.ts +246 -189
  58. package/src/logout.spec.ts +131 -76
  59. package/src/logout.ts +130 -115
  60. package/src/oidc.ts +426 -337
  61. package/src/oidcClient.ts +129 -105
  62. package/src/parseTokens.spec.ts +198 -179
  63. package/src/parseTokens.ts +221 -186
  64. package/src/renewTokens.ts +397 -284
  65. package/src/requests.spec.ts +5 -7
  66. package/src/requests.ts +142 -114
  67. package/src/route-utils.spec.ts +17 -19
  68. package/src/route-utils.ts +29 -26
  69. package/src/silentLogin.ts +145 -127
  70. package/src/timer.ts +10 -11
  71. package/src/types.ts +56 -46
  72. package/src/user.ts +17 -12
  73. package/src/version.ts +1 -1
package/src/initWorker.ts CHANGED
@@ -1,260 +1,347 @@
1
+ import { ILOidcLocation } from './location';
1
2
  import { parseOriginalTokens } from './parseTokens.js';
2
3
  import timer from './timer.js';
3
4
  import { OidcConfiguration } from './types.js';
4
5
  import codeVersion from './version.js';
5
- import {ILOidcLocation} from "./location";
6
6
 
7
7
  let keepAliveServiceWorkerTimeoutId = null;
8
8
  let keepAliveController;
9
- export const sleepAsync = ({milliseconds}: { milliseconds: any }) => {
10
- return new Promise(resolve => timer.setTimeout(resolve, milliseconds));
9
+ export const sleepAsync = ({ milliseconds }: { milliseconds: any }) => {
10
+ return new Promise(resolve => timer.setTimeout(resolve, milliseconds));
11
11
  };
12
12
 
13
- const keepAlive = (service_worker_keep_alive_path='/') => {
14
- try {
15
- const minSleepSeconds = 150;
16
- keepAliveController = new AbortController();
17
- const promise = fetch(`${service_worker_keep_alive_path}OidcKeepAliveServiceWorker.json?minSleepSeconds=${minSleepSeconds}`, { signal: keepAliveController.signal });
18
- promise.catch(error => { console.log(error); });
19
- sleepAsync({milliseconds: minSleepSeconds * 1000}).then(keepAlive);
20
- } catch (error) { console.log(error); }
13
+ const keepAlive = (service_worker_keep_alive_path = '/') => {
14
+ try {
15
+ const minSleepSeconds = 150;
16
+ keepAliveController = new AbortController();
17
+ const promise = fetch(
18
+ `${service_worker_keep_alive_path}OidcKeepAliveServiceWorker.json?minSleepSeconds=${minSleepSeconds}`,
19
+ { signal: keepAliveController.signal },
20
+ );
21
+ promise.catch(error => {
22
+ console.log(error);
23
+ });
24
+ sleepAsync({ milliseconds: minSleepSeconds * 1000 }).then(keepAlive);
25
+ } catch (error) {
26
+ console.log(error);
27
+ }
21
28
  };
22
29
 
23
30
  const stopKeepAlive = () => {
24
- if(keepAliveController) {
25
- keepAliveController.abort();
26
- }
31
+ if (keepAliveController) {
32
+ keepAliveController.abort();
33
+ }
27
34
  };
28
35
 
29
- const isServiceWorkerProxyActiveAsync = (service_worker_keep_alive_path='/') => {
30
- return fetch(`${service_worker_keep_alive_path}OidcKeepAliveServiceWorker.json`, {
31
- headers: {
32
- 'oidc-vanilla': 'true',
33
- },
34
- }).then((response) => {
35
- return response.statusText === 'oidc-service-worker';
36
- }).catch(error => { console.log(error); });
36
+ const isServiceWorkerProxyActiveAsync = (service_worker_keep_alive_path = '/') => {
37
+ return fetch(`${service_worker_keep_alive_path}OidcKeepAliveServiceWorker.json`, {
38
+ headers: {
39
+ 'oidc-vanilla': 'true',
40
+ },
41
+ })
42
+ .then(response => {
43
+ return response.statusText === 'oidc-service-worker';
44
+ })
45
+ .catch(error => {
46
+ console.log(error);
47
+ });
37
48
  };
38
49
 
39
- export const defaultServiceWorkerUpdateRequireCallback = (location:ILOidcLocation) => async (registration: any, stopKeepAlive: Function) => {
50
+ export const defaultServiceWorkerUpdateRequireCallback =
51
+ (location: ILOidcLocation) => async (registration: any, stopKeepAlive: () => void) => {
40
52
  stopKeepAlive();
41
53
  await registration.update();
42
54
  const isSuccess = await registration.unregister();
43
- console.log(`Service worker unregistering ${isSuccess}`)
44
- await sleepAsync({milliseconds: 2000});
55
+ console.log(`Service worker unregistration ${isSuccess ? 'successful' : 'failed'}`);
56
+ await sleepAsync({ milliseconds: 2000 });
45
57
  location.reload();
46
- }
58
+ };
47
59
 
60
+ const sendMessageAsync =
61
+ registration =>
62
+ (data): Promise<any> => {
63
+ return new Promise(function (resolve, reject) {
64
+ const messageChannel = new MessageChannel();
65
+ messageChannel.port1.onmessage = function (event) {
66
+ if (event.data && event.data.error) {
67
+ reject(event.data.error);
68
+ } else {
69
+ resolve(event.data);
70
+ }
48
71
 
72
+ messageChannel.port1.close();
73
+ messageChannel.port2.close();
74
+ };
75
+ registration.active.postMessage(data, [messageChannel.port2]);
76
+ });
77
+ };
49
78
 
50
- const sendMessageAsync = (registration) => (data) : Promise<any> => {
51
- return new Promise(function(resolve, reject) {
52
- const messageChannel = new MessageChannel();
53
- messageChannel.port1.onmessage = function (event) {
54
- if (event.data && event.data.error) {
55
- reject(event.data.error);
56
- } else {
57
- resolve(event.data);
58
- }
79
+ export const initWorkerAsync = async (configuration, configurationName) => {
80
+ const getTabId = () => {
81
+ const tabId = sessionStorage.getItem(`oidc.tabId.${configurationName}`);
59
82
 
60
- messageChannel.port1.close();
61
- messageChannel.port2.close();
62
- };
63
- registration.active.postMessage(data, [messageChannel.port2]);
64
- });
65
- };
83
+ if (tabId) {
84
+ return tabId;
85
+ }
66
86
 
67
- export const initWorkerAsync = async(configuration, configurationName) => {
68
- const getTabId = () => {
69
- const tabId = sessionStorage.getItem(`oidc.tabId.${configurationName}`);
87
+ const newTabId = globalThis.crypto.randomUUID();
88
+ sessionStorage.setItem(`oidc.tabId.${configurationName}`, newTabId);
89
+ return newTabId;
90
+ };
70
91
 
71
- if (tabId) {
72
- return tabId;
73
- }
92
+ const serviceWorkerRelativeUrl = configuration.service_worker_relative_url;
93
+ if (
94
+ typeof window === 'undefined' ||
95
+ typeof navigator === 'undefined' ||
96
+ !navigator.serviceWorker ||
97
+ !serviceWorkerRelativeUrl
98
+ ) {
99
+ return null;
100
+ }
74
101
 
75
- const newTabId = globalThis.crypto.randomUUID();
76
- sessionStorage.setItem(`oidc.tabId.${configurationName}`, newTabId);
77
- return newTabId;
78
- }
102
+ if (configuration.service_worker_activate() === false) {
103
+ return null;
104
+ }
79
105
 
80
- const serviceWorkerRelativeUrl = configuration.service_worker_relative_url;
81
- if (typeof window === 'undefined' || typeof navigator === 'undefined' || !navigator.serviceWorker || !serviceWorkerRelativeUrl) {
82
- return null;
83
- }
84
-
85
- if(configuration.service_worker_activate() === false) {
86
- return null;
87
- }
106
+ let registration = null;
107
+ if (configuration.register) {
108
+ registration = await configuration.service_worker_register(serviceWorkerRelativeUrl);
109
+ } else {
110
+ registration = await navigator.serviceWorker.register(serviceWorkerRelativeUrl);
111
+ }
88
112
 
89
- let registration = null;
90
- if(configuration.register) {
91
- registration = await configuration.service_worker_register(serviceWorkerRelativeUrl);
92
- } else {
93
- registration = await navigator.serviceWorker.register(serviceWorkerRelativeUrl);
94
- }
113
+ try {
114
+ await navigator.serviceWorker.ready;
115
+ if (!navigator.serviceWorker.controller)
116
+ await sendMessageAsync(registration)({ type: 'claim' });
117
+ } catch (err) {
118
+ return null;
119
+ }
95
120
 
96
- try {
97
- await navigator.serviceWorker.ready;
98
- if (!navigator.serviceWorker.controller)
99
- await sendMessageAsync(registration)({ type: 'claim' });
100
- } catch (err) {
101
- return null;
121
+ const clearAsync = async status => {
122
+ return sendMessageAsync(registration)({ type: 'clear', data: { status }, configurationName });
123
+ };
124
+ const initAsync = async (
125
+ oidcServerConfiguration,
126
+ where,
127
+ oidcConfiguration: OidcConfiguration,
128
+ ) => {
129
+ const result = await sendMessageAsync(registration)({
130
+ type: 'init',
131
+ data: {
132
+ oidcServerConfiguration,
133
+ where,
134
+ oidcConfiguration: {
135
+ token_renew_mode: oidcConfiguration.token_renew_mode,
136
+ service_worker_convert_all_requests_to_cors:
137
+ oidcConfiguration.service_worker_convert_all_requests_to_cors,
138
+ },
139
+ },
140
+ configurationName,
141
+ tabId: getTabId(),
142
+ });
143
+
144
+ // @ts-ignore
145
+ const serviceWorkerVersion = result.version;
146
+ if (serviceWorkerVersion !== codeVersion) {
147
+ console.warn(
148
+ `Service worker ${serviceWorkerVersion} version mismatch with js client version ${codeVersion}, unregistering and reloading`,
149
+ );
150
+ await oidcConfiguration.service_worker_update_require_callback(registration, stopKeepAlive);
102
151
  }
103
152
 
104
- const clearAsync = async (status) => {
105
- return sendMessageAsync(registration)({ type: 'clear', data: { status }, configurationName });
106
- };
107
- const initAsync = async (oidcServerConfiguration, where, oidcConfiguration:OidcConfiguration) => {
108
- const result = await sendMessageAsync(registration)({
109
- type: 'init',
110
- data: {
111
- oidcServerConfiguration,
112
- where,
113
- oidcConfiguration: {
114
- token_renew_mode: oidcConfiguration.token_renew_mode,
115
- service_worker_convert_all_requests_to_cors: oidcConfiguration.service_worker_convert_all_requests_to_cors,
116
- },
117
- },
118
- configurationName,
119
- tabId: getTabId()
120
- });
121
-
122
- // @ts-ignore
123
- const serviceWorkerVersion = result.version;
124
- if(serviceWorkerVersion !== codeVersion) {
125
- console.warn(`Service worker ${serviceWorkerVersion} version mismatch with js client version ${codeVersion}, unregistering and reloading`);
126
- await oidcConfiguration.service_worker_update_require_callback(registration, stopKeepAlive);
127
- }
128
-
129
- // @ts-ignore
130
- return { tokens: parseOriginalTokens(result.tokens, null, oidcConfiguration.token_renew_mode), status: result.status };
153
+ // @ts-ignore
154
+ return {
155
+ tokens: parseOriginalTokens(result.tokens, null, oidcConfiguration.token_renew_mode),
156
+ status: result.status,
131
157
  };
158
+ };
132
159
 
133
- const startKeepAliveServiceWorker = (service_worker_keep_alive_path='/') => {
134
- if (keepAliveServiceWorkerTimeoutId == null) {
135
- keepAliveServiceWorkerTimeoutId = 'not_null';
136
- keepAlive(service_worker_keep_alive_path);
137
- }
138
- };
160
+ const startKeepAliveServiceWorker = (service_worker_keep_alive_path = '/') => {
161
+ if (keepAliveServiceWorkerTimeoutId == null) {
162
+ keepAliveServiceWorkerTimeoutId = 'not_null';
163
+ keepAlive(service_worker_keep_alive_path);
164
+ }
165
+ };
139
166
 
140
- const setSessionStateAsync = (sessionState:string) => {
141
- return sendMessageAsync(registration)({ type: 'setSessionState', data: { sessionState }, configurationName });
142
- };
167
+ const setSessionStateAsync = (sessionState: string) => {
168
+ return sendMessageAsync(registration)({
169
+ type: 'setSessionState',
170
+ data: { sessionState },
171
+ configurationName,
172
+ });
173
+ };
143
174
 
144
- const getSessionStateAsync = async () => {
145
- const result = await sendMessageAsync(registration)({ type: 'getSessionState', data: null, configurationName });
146
- // @ts-ignore
147
- return result.sessionState;
148
- };
175
+ const getSessionStateAsync = async () => {
176
+ const result = await sendMessageAsync(registration)({
177
+ type: 'getSessionState',
178
+ data: null,
179
+ configurationName,
180
+ });
181
+ // @ts-ignore
182
+ return result.sessionState;
183
+ };
149
184
 
150
- const setNonceAsync = (nonce) => {
151
- const tabId = getTabId();
152
- sessionStorage[`oidc.nonce.${configurationName}`] = nonce.nonce;
153
- return sendMessageAsync(registration)({ type: 'setNonce', data: { nonce }, configurationName, tabId });
154
- };
155
- const getNonceAsync = async () => {
156
- const tabId = getTabId();
157
- // @ts-ignore
158
- const result = await sendMessageAsync(registration)({ type: 'getNonce', data: null, configurationName, tabId });
159
- // @ts-ignore
160
- let nonce = result.nonce;
161
- if (!nonce) {
162
- nonce = sessionStorage[`oidc.nonce.${configurationName}`];
163
- console.warn('nonce not found in service worker, using sessionStorage');
164
- }
165
- return { nonce };
166
- };
185
+ const setNonceAsync = nonce => {
186
+ const tabId = getTabId();
187
+ sessionStorage[`oidc.nonce.${configurationName}`] = nonce.nonce;
188
+ return sendMessageAsync(registration)({
189
+ type: 'setNonce',
190
+ data: { nonce },
191
+ configurationName,
192
+ tabId,
193
+ });
194
+ };
195
+ const getNonceAsync = async () => {
196
+ const tabId = getTabId();
197
+ // @ts-ignore
198
+ const result = await sendMessageAsync(registration)({
199
+ type: 'getNonce',
200
+ data: null,
201
+ configurationName,
202
+ tabId,
203
+ });
204
+ // @ts-ignore
205
+ let nonce = result.nonce;
206
+ if (!nonce) {
207
+ nonce = sessionStorage[`oidc.nonce.${configurationName}`];
208
+ console.warn('nonce not found in service worker, using sessionStorage');
209
+ }
210
+ return { nonce };
211
+ };
167
212
 
168
- let getLoginParamsCache = {};
169
- const setLoginParams = (data) => {
170
- getLoginParamsCache[configurationName] = data;
171
- localStorage[`oidc.login.${configurationName}`] = JSON.stringify(data);
172
- };
213
+ const getLoginParamsCache = {};
214
+ const setLoginParams = data => {
215
+ getLoginParamsCache[configurationName] = data;
216
+ localStorage[`oidc.login.${configurationName}`] = JSON.stringify(data);
217
+ };
173
218
 
174
- const getLoginParams = () => {
175
- const dataString = localStorage[`oidc.login.${configurationName}`];
176
- if (!getLoginParamsCache[configurationName]) {
177
- getLoginParamsCache[configurationName] = JSON.parse(dataString);
178
- }
179
- return getLoginParamsCache[configurationName];
180
- };
219
+ const getLoginParams = () => {
220
+ const dataString = localStorage[`oidc.login.${configurationName}`];
221
+ if (!getLoginParamsCache[configurationName]) {
222
+ getLoginParamsCache[configurationName] = JSON.parse(dataString);
223
+ }
224
+ return getLoginParamsCache[configurationName];
225
+ };
181
226
 
182
- const setDemonstratingProofOfPossessionNonce = async (demonstratingProofOfPossessionNonce: string) => {
183
- await sendMessageAsync(registration)({ type: 'setDemonstratingProofOfPossessionNonce', data: { demonstratingProofOfPossessionNonce }, configurationName });
184
- };
227
+ const setDemonstratingProofOfPossessionNonce = async (
228
+ demonstratingProofOfPossessionNonce: string,
229
+ ) => {
230
+ await sendMessageAsync(registration)({
231
+ type: 'setDemonstratingProofOfPossessionNonce',
232
+ data: { demonstratingProofOfPossessionNonce },
233
+ configurationName,
234
+ });
235
+ };
185
236
 
186
- const getDemonstratingProofOfPossessionNonce = async () => {
187
- const result = await sendMessageAsync(registration)({type: 'getDemonstratingProofOfPossessionNonce', data: null, configurationName});
188
- return result.demonstratingProofOfPossessionNonce;
189
- };
237
+ const getDemonstratingProofOfPossessionNonce = async () => {
238
+ const result = await sendMessageAsync(registration)({
239
+ type: 'getDemonstratingProofOfPossessionNonce',
240
+ data: null,
241
+ configurationName,
242
+ });
243
+ return result.demonstratingProofOfPossessionNonce;
244
+ };
190
245
 
191
- const setDemonstratingProofOfPossessionJwkAsync = async (demonstratingProofOfPossessionJwk:JsonWebKey) => {
192
- const demonstratingProofOfPossessionJwkJson = JSON.stringify(demonstratingProofOfPossessionJwk);
193
- await sendMessageAsync(registration)({ type: 'setDemonstratingProofOfPossessionJwk', data: { demonstratingProofOfPossessionJwkJson }, configurationName });
194
- };
246
+ const setDemonstratingProofOfPossessionJwkAsync = async (
247
+ demonstratingProofOfPossessionJwk: JsonWebKey,
248
+ ) => {
249
+ const demonstratingProofOfPossessionJwkJson = JSON.stringify(demonstratingProofOfPossessionJwk);
250
+ await sendMessageAsync(registration)({
251
+ type: 'setDemonstratingProofOfPossessionJwk',
252
+ data: { demonstratingProofOfPossessionJwkJson },
253
+ configurationName,
254
+ });
255
+ };
195
256
 
196
- const getDemonstratingProofOfPossessionJwkAsync = async () => {
197
- const result = await sendMessageAsync(registration)({type: 'getDemonstratingProofOfPossessionJwk', data: null, configurationName});
198
- if(!result.demonstratingProofOfPossessionJwkJson) {
199
- return null;
200
- }
201
- return JSON.parse(result.demonstratingProofOfPossessionJwkJson);
202
- };
203
-
204
- const getStateAsync = async () => {
205
- const tabId = getTabId();
206
- const result = await sendMessageAsync(registration)({ type: 'getState', data: null, configurationName, tabId });
207
- // @ts-ignore
208
- let state = result.state;
209
- if (!state) {
210
- state = sessionStorage[`oidc.state.${configurationName}`];
211
- console.warn('state not found in service worker, using sessionStorage');
212
- }
213
- return state;
214
- };
257
+ const getDemonstratingProofOfPossessionJwkAsync = async () => {
258
+ const result = await sendMessageAsync(registration)({
259
+ type: 'getDemonstratingProofOfPossessionJwk',
260
+ data: null,
261
+ configurationName,
262
+ });
263
+ if (!result.demonstratingProofOfPossessionJwkJson) {
264
+ return null;
265
+ }
266
+ return JSON.parse(result.demonstratingProofOfPossessionJwkJson);
267
+ };
215
268
 
216
- const setStateAsync = async (state:string) => {
217
- const tabId = getTabId();
218
- sessionStorage[`oidc.state.${configurationName}`] = state;
219
- return sendMessageAsync(registration)({ type: 'setState', data: { state }, configurationName, tabId });
220
- };
269
+ const getStateAsync = async () => {
270
+ const tabId = getTabId();
271
+ const result = await sendMessageAsync(registration)({
272
+ type: 'getState',
273
+ data: null,
274
+ configurationName,
275
+ tabId,
276
+ });
277
+ // @ts-ignore
278
+ let state = result.state;
279
+ if (!state) {
280
+ state = sessionStorage[`oidc.state.${configurationName}`];
281
+ console.warn('state not found in service worker, using sessionStorage');
282
+ }
283
+ return state;
284
+ };
221
285
 
222
- const getCodeVerifierAsync = async () => {
223
- const tabId = getTabId();
224
- const result = await sendMessageAsync(registration)({ type: 'getCodeVerifier', data: null, configurationName, tabId });
225
- // @ts-ignore
226
- let codeVerifier = result.codeVerifier;
227
- if (!codeVerifier) {
228
- codeVerifier = sessionStorage[`oidc.code_verifier.${configurationName}`];
229
- console.warn('codeVerifier not found in service worker, using sessionStorage');
230
- }
231
- return codeVerifier;
232
- };
286
+ const setStateAsync = async (state: string) => {
287
+ const tabId = getTabId();
288
+ sessionStorage[`oidc.state.${configurationName}`] = state;
289
+ return sendMessageAsync(registration)({
290
+ type: 'setState',
291
+ data: { state },
292
+ configurationName,
293
+ tabId,
294
+ });
295
+ };
233
296
 
234
- const setCodeVerifierAsync = async (codeVerifier:string) => {
235
- const tabId = getTabId();
236
- sessionStorage[`oidc.code_verifier.${configurationName}`] = codeVerifier;
237
- return sendMessageAsync(registration)({ type: 'setCodeVerifier', data: { codeVerifier }, configurationName, tabId });
238
- };
297
+ const getCodeVerifierAsync = async () => {
298
+ const tabId = getTabId();
299
+ const result = await sendMessageAsync(registration)({
300
+ type: 'getCodeVerifier',
301
+ data: null,
302
+ configurationName,
303
+ tabId,
304
+ });
305
+ // @ts-ignore
306
+ let codeVerifier = result.codeVerifier;
307
+ if (!codeVerifier) {
308
+ codeVerifier = sessionStorage[`oidc.code_verifier.${configurationName}`];
309
+ console.warn('codeVerifier not found in service worker, using sessionStorage');
310
+ }
311
+ return codeVerifier;
312
+ };
239
313
 
240
- return {
241
- clearAsync,
242
- initAsync,
243
- startKeepAliveServiceWorker : () => startKeepAliveServiceWorker(configuration.service_worker_keep_alive_path),
244
- isServiceWorkerProxyActiveAsync : () => isServiceWorkerProxyActiveAsync(configuration.service_worker_keep_alive_path),
245
- setSessionStateAsync,
246
- getSessionStateAsync,
247
- setNonceAsync,
248
- getNonceAsync,
249
- setLoginParams,
250
- getLoginParams,
251
- getStateAsync,
252
- setStateAsync,
253
- getCodeVerifierAsync,
254
- setCodeVerifierAsync,
255
- setDemonstratingProofOfPossessionNonce,
256
- getDemonstratingProofOfPossessionNonce,
257
- setDemonstratingProofOfPossessionJwkAsync,
258
- getDemonstratingProofOfPossessionJwkAsync,
259
- };
314
+ const setCodeVerifierAsync = async (codeVerifier: string) => {
315
+ const tabId = getTabId();
316
+ sessionStorage[`oidc.code_verifier.${configurationName}`] = codeVerifier;
317
+ return sendMessageAsync(registration)({
318
+ type: 'setCodeVerifier',
319
+ data: { codeVerifier },
320
+ configurationName,
321
+ tabId,
322
+ });
323
+ };
324
+
325
+ return {
326
+ clearAsync,
327
+ initAsync,
328
+ startKeepAliveServiceWorker: () =>
329
+ startKeepAliveServiceWorker(configuration.service_worker_keep_alive_path),
330
+ isServiceWorkerProxyActiveAsync: () =>
331
+ isServiceWorkerProxyActiveAsync(configuration.service_worker_keep_alive_path),
332
+ setSessionStateAsync,
333
+ getSessionStateAsync,
334
+ setNonceAsync,
335
+ getNonceAsync,
336
+ setLoginParams,
337
+ getLoginParams,
338
+ getStateAsync,
339
+ setStateAsync,
340
+ getCodeVerifierAsync,
341
+ setCodeVerifierAsync,
342
+ setDemonstratingProofOfPossessionNonce,
343
+ getDemonstratingProofOfPossessionNonce,
344
+ setDemonstratingProofOfPossessionJwkAsync,
345
+ getDemonstratingProofOfPossessionJwkAsync,
346
+ };
260
347
  };