@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.
- package/README.md +31 -39
- package/bin/copy-service-worker-files.mjs +24 -17
- package/dist/OidcTrustedDomains.js +14 -12
- package/dist/cache.d.ts.map +1 -1
- package/dist/checkSession.d.ts +1 -1
- package/dist/checkSession.d.ts.map +1 -1
- package/dist/checkSessionIFrame.d.ts.map +1 -1
- package/dist/crypto.d.ts.map +1 -1
- package/dist/fetch.d.ts +2 -1
- package/dist/fetch.d.ts.map +1 -1
- package/dist/index.d.ts +5 -5
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +935 -601
- package/dist/index.umd.cjs +2 -2
- package/dist/initSession.d.ts +1 -1
- package/dist/initSession.d.ts.map +1 -1
- package/dist/initWorker.d.ts +2 -2
- package/dist/initWorker.d.ts.map +1 -1
- package/dist/initWorkerOption.d.ts.map +1 -1
- package/dist/jwt.d.ts +2 -2
- package/dist/jwt.d.ts.map +1 -1
- package/dist/keepSession.d.ts.map +1 -1
- package/dist/location.d.ts.map +1 -1
- package/dist/login.d.ts +1 -1
- package/dist/login.d.ts.map +1 -1
- package/dist/logout.d.ts +1 -1
- package/dist/logout.d.ts.map +1 -1
- package/dist/oidc.d.ts +1 -1
- package/dist/oidc.d.ts.map +1 -1
- package/dist/oidcClient.d.ts +2 -2
- package/dist/oidcClient.d.ts.map +1 -1
- package/dist/parseTokens.d.ts.map +1 -1
- package/dist/renewTokens.d.ts.map +1 -1
- package/dist/requests.d.ts +1 -1
- package/dist/requests.d.ts.map +1 -1
- package/dist/silentLogin.d.ts.map +1 -1
- package/dist/timer.d.ts.map +1 -1
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/user.d.ts.map +1 -1
- package/dist/version.d.ts +1 -1
- package/package.json +2 -2
- package/src/cache.ts +21 -18
- package/src/checkSession.ts +89 -54
- package/src/checkSessionIFrame.ts +70 -69
- package/src/crypto.ts +27 -25
- package/src/events.ts +28 -28
- package/src/fetch.ts +40 -21
- package/src/index.ts +6 -17
- package/src/iniWorker.spec.ts +26 -16
- package/src/initSession.ts +115 -113
- package/src/initWorker.ts +299 -212
- package/src/initWorkerOption.ts +121 -114
- package/src/jwt.ts +150 -136
- package/src/keepSession.ts +100 -81
- package/src/location.ts +24 -26
- package/src/login.ts +246 -189
- package/src/logout.spec.ts +131 -76
- package/src/logout.ts +130 -115
- package/src/oidc.ts +426 -337
- package/src/oidcClient.ts +129 -105
- package/src/parseTokens.spec.ts +198 -179
- package/src/parseTokens.ts +221 -186
- package/src/renewTokens.ts +397 -284
- package/src/requests.spec.ts +5 -7
- package/src/requests.ts +142 -114
- package/src/route-utils.spec.ts +17 -19
- package/src/route-utils.ts +29 -26
- package/src/silentLogin.ts +145 -127
- package/src/timer.ts +10 -11
- package/src/types.ts +56 -46
- package/src/user.ts +17 -12
- 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
|
-
|
|
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
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
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
|
-
|
|
25
|
-
|
|
26
|
-
|
|
31
|
+
if (keepAliveController) {
|
|
32
|
+
keepAliveController.abort();
|
|
33
|
+
}
|
|
27
34
|
};
|
|
28
35
|
|
|
29
|
-
const isServiceWorkerProxyActiveAsync = (service_worker_keep_alive_path='/') => {
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
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 =
|
|
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
|
|
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
|
|
51
|
-
|
|
52
|
-
|
|
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
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
registration.active.postMessage(data, [messageChannel.port2]);
|
|
64
|
-
});
|
|
65
|
-
};
|
|
83
|
+
if (tabId) {
|
|
84
|
+
return tabId;
|
|
85
|
+
}
|
|
66
86
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
87
|
+
const newTabId = globalThis.crypto.randomUUID();
|
|
88
|
+
sessionStorage.setItem(`oidc.tabId.${configurationName}`, newTabId);
|
|
89
|
+
return newTabId;
|
|
90
|
+
};
|
|
70
91
|
|
|
71
|
-
|
|
72
|
-
|
|
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
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
}
|
|
102
|
+
if (configuration.service_worker_activate() === false) {
|
|
103
|
+
return null;
|
|
104
|
+
}
|
|
79
105
|
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
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
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
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
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
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
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
167
|
+
const setSessionStateAsync = (sessionState: string) => {
|
|
168
|
+
return sendMessageAsync(registration)({
|
|
169
|
+
type: 'setSessionState',
|
|
170
|
+
data: { sessionState },
|
|
171
|
+
configurationName,
|
|
172
|
+
});
|
|
173
|
+
};
|
|
143
174
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
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
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
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
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
213
|
+
const getLoginParamsCache = {};
|
|
214
|
+
const setLoginParams = data => {
|
|
215
|
+
getLoginParamsCache[configurationName] = data;
|
|
216
|
+
localStorage[`oidc.login.${configurationName}`] = JSON.stringify(data);
|
|
217
|
+
};
|
|
173
218
|
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
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
|
-
|
|
183
|
-
|
|
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
|
-
|
|
187
|
-
|
|
188
|
-
|
|
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
|
-
|
|
192
|
-
|
|
193
|
-
|
|
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
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
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
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
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
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
258
|
-
|
|
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
|
};
|