@axa-fr/react-oidc 6.10.15 → 6.10.17
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/dist/OidcServiceWorker.js +17 -24
- package/dist/vanilla/initSession.d.ts.map +1 -1
- package/dist/vanilla/initSession.js +1 -2
- package/dist/vanilla/initSession.js.map +1 -1
- package/dist/vanilla/initWorker.d.ts +8 -4
- package/dist/vanilla/initWorker.d.ts.map +1 -1
- package/dist/vanilla/initWorker.js +101 -9
- package/dist/vanilla/initWorker.js.map +1 -1
- package/dist/vanilla/oidc.d.ts.map +1 -1
- package/dist/vanilla/oidc.js +86 -74
- package/dist/vanilla/oidc.js.map +1 -1
- package/package.json +1 -1
- package/src/oidc/vanilla/OidcServiceWorker.js +17 -24
- package/src/oidc/vanilla/initSession.ts +1 -2
- package/src/oidc/vanilla/initWorker.ts +107 -11
- package/src/oidc/vanilla/oidc.ts +89 -79
|
@@ -1,8 +1,78 @@
|
|
|
1
|
+
import { initSession } from './initSession';
|
|
1
2
|
import { OidcConfiguration } from './oidc';
|
|
2
3
|
import { parseOriginalTokens } from './parseTokens';
|
|
3
4
|
import timer from './timer';
|
|
4
5
|
|
|
5
|
-
|
|
6
|
+
export const getOperatingSystem = () => {
|
|
7
|
+
const nVer = navigator.appVersion;
|
|
8
|
+
const nAgt = navigator.userAgent;
|
|
9
|
+
const unknown = '-';
|
|
10
|
+
// system
|
|
11
|
+
let os = unknown;
|
|
12
|
+
const clientStrings = [
|
|
13
|
+
{ s: 'Windows 10', r: /(Windows 10.0|Windows NT 10.0)/ },
|
|
14
|
+
{ s: 'Windows 8.1', r: /(Windows 8.1|Windows NT 6.3)/ },
|
|
15
|
+
{ s: 'Windows 8', r: /(Windows 8|Windows NT 6.2)/ },
|
|
16
|
+
{ s: 'Windows 7', r: /(Windows 7|Windows NT 6.1)/ },
|
|
17
|
+
{ s: 'Windows Vista', r: /Windows NT 6.0/ },
|
|
18
|
+
{ s: 'Windows Server 2003', r: /Windows NT 5.2/ },
|
|
19
|
+
{ s: 'Windows XP', r: /(Windows NT 5.1|Windows XP)/ },
|
|
20
|
+
{ s: 'Windows 2000', r: /(Windows NT 5.0|Windows 2000)/ },
|
|
21
|
+
{ s: 'Windows ME', r: /(Win 9x 4.90|Windows ME)/ },
|
|
22
|
+
{ s: 'Windows 98', r: /(Windows 98|Win98)/ },
|
|
23
|
+
{ s: 'Windows 95', r: /(Windows 95|Win95|Windows_95)/ },
|
|
24
|
+
{ s: 'Windows NT 4.0', r: /(Windows NT 4.0|WinNT4.0|WinNT|Windows NT)/ },
|
|
25
|
+
{ s: 'Windows CE', r: /Windows CE/ },
|
|
26
|
+
{ s: 'Windows 3.11', r: /Win16/ },
|
|
27
|
+
{ s: 'Android', r: /Android/ },
|
|
28
|
+
{ s: 'Open BSD', r: /OpenBSD/ },
|
|
29
|
+
{ s: 'Sun OS', r: /SunOS/ },
|
|
30
|
+
{ s: 'Chrome OS', r: /CrOS/ },
|
|
31
|
+
{ s: 'Linux', r: /(Linux|X11(?!.*CrOS))/ },
|
|
32
|
+
{ s: 'iOS', r: /(iPhone|iPad|iPod)/ },
|
|
33
|
+
{ s: 'Mac OS X', r: /Mac OS X/ },
|
|
34
|
+
{ s: 'Mac OS', r: /(Mac OS|MacPPC|MacIntel|Mac_PowerPC|Macintosh)/ },
|
|
35
|
+
{ s: 'QNX', r: /QNX/ },
|
|
36
|
+
{ s: 'UNIX', r: /UNIX/ },
|
|
37
|
+
{ s: 'BeOS', r: /BeOS/ },
|
|
38
|
+
{ s: 'OS/2', r: /OS\/2/ },
|
|
39
|
+
{ s: 'Search Bot', r: /(nuhk|Googlebot|Yammybot|Openbot|Slurp|MSNBot|Ask Jeeves\/Teoma|ia_archiver)/ },
|
|
40
|
+
];
|
|
41
|
+
for (const id in clientStrings) {
|
|
42
|
+
const cs = clientStrings[id];
|
|
43
|
+
if (cs.r.test(nAgt)) {
|
|
44
|
+
os = cs.s;
|
|
45
|
+
break;
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
let osVersion = unknown;
|
|
50
|
+
|
|
51
|
+
if (/Windows/.test(os)) {
|
|
52
|
+
osVersion = /Windows (.*)/.exec(os)[1];
|
|
53
|
+
os = 'Windows';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
switch (os) {
|
|
57
|
+
case 'Mac OS':
|
|
58
|
+
case 'Mac OS X':
|
|
59
|
+
case 'Android':
|
|
60
|
+
osVersion = /(?:Android|Mac OS|Mac OS X|MacPPC|MacIntel|Mac_PowerPC|Macintosh) ([._\d]+)/.exec(nAgt)[1];
|
|
61
|
+
break;
|
|
62
|
+
|
|
63
|
+
case 'iOS': {
|
|
64
|
+
const osVersionArray = /OS (\d+)_(\d+)_?(\d+)?/.exec(nVer);
|
|
65
|
+
osVersion = osVersionArray[1] + '.' + osVersionArray[2] + '.' + (parseInt(osVersionArray[3]) | 0);
|
|
66
|
+
break;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
return {
|
|
70
|
+
os,
|
|
71
|
+
osVersion,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
function getBrowser() {
|
|
6
76
|
const ua = navigator.userAgent; let tem;
|
|
7
77
|
let M = ua.match(/(opera|chrome|safari|firefox|msie|trident(?=\/))\/?\s*(\d+)/i) || [];
|
|
8
78
|
if (/trident/i.test(M[1])) {
|
|
@@ -70,11 +140,11 @@ const sendMessageAsync = (registration) => (data) => {
|
|
|
70
140
|
});
|
|
71
141
|
};
|
|
72
142
|
|
|
73
|
-
export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName) => {
|
|
143
|
+
export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName, redirectUri) => {
|
|
74
144
|
if (typeof window === 'undefined' || typeof navigator === 'undefined' || !navigator.serviceWorker || !serviceWorkerRelativeUrl) {
|
|
75
145
|
return null;
|
|
76
146
|
}
|
|
77
|
-
const { name, version } =
|
|
147
|
+
const { name, version } = getBrowser();
|
|
78
148
|
if (name === 'chrome' && parseInt(version) < 90) {
|
|
79
149
|
return null;
|
|
80
150
|
}
|
|
@@ -90,6 +160,8 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
|
|
|
90
160
|
return null;
|
|
91
161
|
}
|
|
92
162
|
|
|
163
|
+
const operatingSystem = getOperatingSystem();
|
|
164
|
+
|
|
93
165
|
const registration = await navigator.serviceWorker.register(serviceWorkerRelativeUrl);
|
|
94
166
|
|
|
95
167
|
try {
|
|
@@ -98,19 +170,32 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
|
|
|
98
170
|
return null;
|
|
99
171
|
}
|
|
100
172
|
|
|
101
|
-
const
|
|
102
|
-
|
|
173
|
+
const unregisterAsync = async () => {
|
|
174
|
+
return await registration.unregister();
|
|
103
175
|
};
|
|
104
176
|
|
|
177
|
+
const saveItemsAsync = (items) => {
|
|
178
|
+
// iOS kill Service Worker when domain we leave domain
|
|
179
|
+
if (operatingSystem.os === 'iOS') {
|
|
180
|
+
const session = initSession(configurationName, redirectUri);
|
|
181
|
+
return session.saveItemsAsync(items);
|
|
182
|
+
}
|
|
183
|
+
return sendMessageAsync(registration)({ type: 'saveItems', data: items, configurationName });
|
|
184
|
+
};
|
|
105
185
|
const loadItemsAsync = () => {
|
|
186
|
+
// iOS kill Service Worker when domain we leave domain
|
|
187
|
+
if (operatingSystem.os === 'iOS') {
|
|
188
|
+
const session = initSession(configurationName, redirectUri);
|
|
189
|
+
return session.loadItemsAsync();
|
|
190
|
+
}
|
|
106
191
|
return sendMessageAsync(registration)({ type: 'loadItems', data: null, configurationName });
|
|
107
192
|
};
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
193
|
+
const clearAsync = async (status) => {
|
|
194
|
+
// iOS kill Service Worker when domain we leave domain
|
|
195
|
+
if (operatingSystem.os === 'iOS') {
|
|
196
|
+
const session = initSession(configurationName, redirectUri);
|
|
197
|
+
await session.clearAsync(status);
|
|
198
|
+
}
|
|
114
199
|
return sendMessageAsync(registration)({ type: 'clear', data: { status }, configurationName });
|
|
115
200
|
};
|
|
116
201
|
const initAsync = async (oidcServerConfiguration, where, oidcConfiguration:OidcConfiguration) => {
|
|
@@ -141,10 +226,21 @@ export const initWorkerAsync = async(serviceWorkerRelativeUrl, configurationName
|
|
|
141
226
|
};
|
|
142
227
|
|
|
143
228
|
const setNonceAsync = (nonce) => {
|
|
229
|
+
// iOS kill Service Worker when domain we leave domain
|
|
230
|
+
if (operatingSystem.os === 'iOS') {
|
|
231
|
+
const session = initSession(configurationName, redirectUri);
|
|
232
|
+
return session.setNonceAsync(nonce);
|
|
233
|
+
}
|
|
144
234
|
return sendMessageAsync(registration)({ type: 'setNonce', data: { nonce }, configurationName });
|
|
145
235
|
};
|
|
236
|
+
|
|
146
237
|
const NONCE_TOKEN = 'NONCE_SECURED_BY_OIDC_SERVICE_WORKER';
|
|
147
238
|
const getNonceAsync = async () => {
|
|
239
|
+
// iOS kill Service Worker when domain we leave domain
|
|
240
|
+
if (operatingSystem.os === 'iOS') {
|
|
241
|
+
const session = initSession(configurationName, redirectUri);
|
|
242
|
+
return session.getNonceAsync();
|
|
243
|
+
}
|
|
148
244
|
// @ts-ignore
|
|
149
245
|
const keyNonce = NONCE_TOKEN + '_' + configurationName;
|
|
150
246
|
return { nonce: keyNonce };
|
package/src/oidc/vanilla/oidc.ts
CHANGED
|
@@ -33,7 +33,7 @@ const TOKEN_TYPE = {
|
|
|
33
33
|
access_token: 'access_token',
|
|
34
34
|
};
|
|
35
35
|
|
|
36
|
-
const performRevocationRequestAsync = async (url, token, token_type = TOKEN_TYPE.refresh_token, client_id) => {
|
|
36
|
+
const performRevocationRequestAsync = async (url, token, token_type = TOKEN_TYPE.refresh_token, client_id, timeoutMs = 10000) => {
|
|
37
37
|
const details = {
|
|
38
38
|
token,
|
|
39
39
|
token_type_hint: token_type,
|
|
@@ -54,7 +54,7 @@ const performRevocationRequestAsync = async (url, token, token_type = TOKEN_TYPE
|
|
|
54
54
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
55
55
|
},
|
|
56
56
|
body: formBodyString,
|
|
57
|
-
});
|
|
57
|
+
}, timeoutMs);
|
|
58
58
|
if (response.status !== 200) {
|
|
59
59
|
return { success: false };
|
|
60
60
|
}
|
|
@@ -63,7 +63,7 @@ const performRevocationRequestAsync = async (url, token, token_type = TOKEN_TYPE
|
|
|
63
63
|
};
|
|
64
64
|
};
|
|
65
65
|
|
|
66
|
-
const performTokenRequestAsync = async (url, details, extras, oldTokens, tokenRenewMode: string) => {
|
|
66
|
+
const performTokenRequestAsync = async (url, details, extras, oldTokens, tokenRenewMode: string, timeoutMs = 10000) => {
|
|
67
67
|
for (const [key, value] of Object.entries(extras)) {
|
|
68
68
|
if (details[key] === undefined) {
|
|
69
69
|
details[key] = value;
|
|
@@ -84,7 +84,7 @@ const performTokenRequestAsync = async (url, details, extras, oldTokens, tokenRe
|
|
|
84
84
|
'Content-Type': 'application/x-www-form-urlencoded;charset=UTF-8',
|
|
85
85
|
},
|
|
86
86
|
body: formBodyString,
|
|
87
|
-
});
|
|
87
|
+
}, timeoutMs);
|
|
88
88
|
if (response.status !== 200) {
|
|
89
89
|
return { success: false, status: response.status };
|
|
90
90
|
}
|
|
@@ -95,17 +95,17 @@ const performTokenRequestAsync = async (url, details, extras, oldTokens, tokenRe
|
|
|
95
95
|
};
|
|
96
96
|
};
|
|
97
97
|
|
|
98
|
-
const internalFetch = async (url, headers, numberRetry = 0) => {
|
|
98
|
+
const internalFetch = async (url, headers, numberRetry = 0, timeoutMs = 10000) => {
|
|
99
99
|
let response;
|
|
100
100
|
try {
|
|
101
101
|
const controller = new AbortController();
|
|
102
|
-
setTimeout(() => controller.abort(),
|
|
102
|
+
setTimeout(() => controller.abort(), timeoutMs);
|
|
103
103
|
response = await fetch(url, { ...headers, signal: controller.signal });
|
|
104
104
|
} catch (e) {
|
|
105
105
|
if (e.message === 'AbortError' ||
|
|
106
106
|
e.message === 'Network request failed') {
|
|
107
107
|
if (numberRetry <= 1) {
|
|
108
|
-
return await internalFetch(url, headers, numberRetry + 1);
|
|
108
|
+
return await internalFetch(url, headers, numberRetry + 1, timeoutMs);
|
|
109
109
|
} else {
|
|
110
110
|
throw e;
|
|
111
111
|
}
|
|
@@ -208,7 +208,7 @@ async function renewTokensAndStartTimerAsync(oidc, refreshToken, forceRefresh =
|
|
|
208
208
|
const updateTokens = (tokens) => { oidc.tokens = tokens; };
|
|
209
209
|
const { tokens, status } = await oidc.synchroniseTokensAsync(refreshToken, 0, forceRefresh, extras, updateTokens);
|
|
210
210
|
|
|
211
|
-
const serviceWorker = await initWorkerAsync(oidc.configuration.service_worker_relative_url, oidc.configurationName);
|
|
211
|
+
const serviceWorker = await initWorkerAsync(oidc.configuration.service_worker_relative_url, oidc.configurationName, oidc.configuration.redirect_uri);
|
|
212
212
|
if (!serviceWorker) {
|
|
213
213
|
const session = initSession(oidc.configurationName, oidc.configuration.redirect_uri, oidc.configuration.storage);
|
|
214
214
|
await session.setTokens(oidc.tokens);
|
|
@@ -565,7 +565,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
565
565
|
});
|
|
566
566
|
}
|
|
567
567
|
|
|
568
|
-
const serviceWorker = await initWorkerAsync(this.configuration.service_worker_relative_url, this.configurationName);
|
|
568
|
+
const serviceWorker = await initWorkerAsync(this.configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
|
|
569
569
|
const storage = serviceWorker ? window.localStorage : null;
|
|
570
570
|
return await fetchFromIssuer(authority, this.configuration.authority_time_cache_wellknowurl_in_second ?? 60 * 60, storage);
|
|
571
571
|
};
|
|
@@ -590,7 +590,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
590
590
|
try {
|
|
591
591
|
const configuration = this.configuration;
|
|
592
592
|
const oidcServerConfiguration = await this.initAsync(configuration.authority, configuration.authority_configuration);
|
|
593
|
-
serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, this.configurationName);
|
|
593
|
+
serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, this.configurationName, configuration.redirect_uri);
|
|
594
594
|
if (serviceWorker) {
|
|
595
595
|
const { tokens } = await serviceWorker.initAsync(oidcServerConfiguration, 'tryKeepExistingSessionAsync', configuration);
|
|
596
596
|
if (tokens) {
|
|
@@ -704,7 +704,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
704
704
|
extraFinal.nonce = randomString(12);
|
|
705
705
|
}
|
|
706
706
|
const nonce = { nonce: extraFinal.nonce };
|
|
707
|
-
const serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, this.configurationName);
|
|
707
|
+
const serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
|
|
708
708
|
const oidcServerConfiguration = await this.initAsync(configuration.authority, configuration.authority_configuration);
|
|
709
709
|
let storage;
|
|
710
710
|
if (serviceWorker) {
|
|
@@ -777,13 +777,9 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
777
777
|
}).catch(async (e) => {
|
|
778
778
|
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
779
779
|
for (const [key, oidc] of Object.entries(oidcDatabase)) {
|
|
780
|
-
//
|
|
781
|
-
|
|
782
|
-
await oidc.logoutOtherTabAsync(this.configuration.client_id, idTokenPayload.sub);
|
|
783
|
-
// }
|
|
780
|
+
// @ts-ignore
|
|
781
|
+
await oidc.logoutOtherTabAsync(this.configuration.client_id, idTokenPayload.sub);
|
|
784
782
|
}
|
|
785
|
-
// await this.destroyAsync();
|
|
786
|
-
// this.publishEvent(eventNames.logout_from_another_tab, {message : "SessionMonitor"});
|
|
787
783
|
});
|
|
788
784
|
};
|
|
789
785
|
|
|
@@ -812,7 +808,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
812
808
|
const parsedTokens = response.tokens;
|
|
813
809
|
// @ts-ignore
|
|
814
810
|
this.tokens = response.tokens;
|
|
815
|
-
const serviceWorker = await initWorkerAsync(this.configuration.service_worker_relative_url, this.configurationName);
|
|
811
|
+
const serviceWorker = await initWorkerAsync(this.configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
|
|
816
812
|
if (!serviceWorker) {
|
|
817
813
|
const session = initSession(this.configurationName, this.configuration.redirect_uri, this.configuration.storage);
|
|
818
814
|
session.setTokens(parsedTokens);
|
|
@@ -839,7 +835,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
839
835
|
const oidcServerConfiguration = await this.initAsync(authority, configuration.authority_configuration);
|
|
840
836
|
const queryParams = getParseQueryStringFromLocation(window.location.href);
|
|
841
837
|
const sessionState = queryParams.session_state;
|
|
842
|
-
const serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, this.configurationName);
|
|
838
|
+
const serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, this.configurationName, configuration.redirect_uri);
|
|
843
839
|
let storage = null;
|
|
844
840
|
let nonceData = null;
|
|
845
841
|
if (serviceWorker) {
|
|
@@ -963,6 +959,10 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
963
959
|
}
|
|
964
960
|
|
|
965
961
|
async synchroniseTokensAsync(refreshToken, index = 0, forceRefresh = false, extras:StringMap = null, updateTokens) {
|
|
962
|
+
while (!navigator.onLine && document.hidden) {
|
|
963
|
+
await sleepAsync(1000);
|
|
964
|
+
this.publishEvent(eventNames.refreshTokensAsync, { message: 'wait because navigator is offline and hidden' });
|
|
965
|
+
}
|
|
966
966
|
let numberTryOnline = 6;
|
|
967
967
|
while (!navigator.onLine && numberTryOnline > 0) {
|
|
968
968
|
await sleepAsync(1000);
|
|
@@ -1012,68 +1012,78 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1012
1012
|
this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token' });
|
|
1013
1013
|
return { tokens: null, status: 'SESSION_LOST' };
|
|
1014
1014
|
}
|
|
1015
|
-
|
|
1016
|
-
|
|
1017
|
-
|
|
1018
|
-
|
|
1019
|
-
|
|
1020
|
-
|
|
1021
|
-
|
|
1022
|
-
|
|
1023
|
-
|
|
1024
|
-
|
|
1025
|
-
|
|
1026
|
-
|
|
1027
|
-
|
|
1028
|
-
|
|
1029
|
-
|
|
1030
|
-
|
|
1031
|
-
|
|
1032
|
-
|
|
1033
|
-
|
|
1034
|
-
|
|
1035
|
-
|
|
1036
|
-
|
|
1037
|
-
|
|
1038
|
-
default: {
|
|
1039
|
-
if (!refreshToken) {
|
|
1015
|
+
try {
|
|
1016
|
+
const { status, tokens, nonce } = await this.syncTokensInfoAsync(configuration, this.configurationName, this.tokens, forceRefresh);
|
|
1017
|
+
switch (status) {
|
|
1018
|
+
case 'SESSION_LOST':
|
|
1019
|
+
updateTokens(null);
|
|
1020
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token session lost' });
|
|
1021
|
+
return { tokens: null, status: 'SESSION_LOST' };
|
|
1022
|
+
case 'NOT_CONNECTED':
|
|
1023
|
+
updateTokens(null);
|
|
1024
|
+
return { tokens: null, status: null };
|
|
1025
|
+
case 'TOKENS_VALID':
|
|
1026
|
+
updateTokens(tokens);
|
|
1027
|
+
return { tokens, status: 'LOGGED_IN' };
|
|
1028
|
+
case 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID':
|
|
1029
|
+
updateTokens(tokens);
|
|
1030
|
+
this.publishEvent(Oidc.eventNames.token_renewed, { reason: 'TOKEN_UPDATED_BY_ANOTHER_TAB_TOKENS_VALID' });
|
|
1031
|
+
return { tokens, status: 'LOGGED_IN' };
|
|
1032
|
+
case 'LOGOUT_FROM_ANOTHER_TAB':
|
|
1033
|
+
updateTokens(null);
|
|
1034
|
+
this.publishEvent(eventNames.logout_from_another_tab, { status: 'session syncTokensAsync' });
|
|
1035
|
+
return { tokens: null, status: 'LOGGED_OUT' };
|
|
1036
|
+
case 'REQUIRE_SYNC_TOKENS':
|
|
1037
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
|
|
1040
1038
|
return await localsilentLoginAsync();
|
|
1041
|
-
|
|
1042
|
-
|
|
1043
|
-
|
|
1044
|
-
|
|
1045
|
-
const redirectUri = configuration.redirect_uri;
|
|
1046
|
-
const authority = configuration.authority;
|
|
1047
|
-
const tokenExtras = configuration.token_request_extras ? configuration.token_request_extras : {};
|
|
1048
|
-
const finalExtras = { ...tokenExtras, ...extras };
|
|
1049
|
-
|
|
1050
|
-
const details = {
|
|
1051
|
-
client_id: clientId,
|
|
1052
|
-
redirect_uri: redirectUri,
|
|
1053
|
-
grant_type: GRANT_TYPE_REFRESH_TOKEN,
|
|
1054
|
-
refresh_token: tokens.refreshToken,
|
|
1055
|
-
};
|
|
1056
|
-
const oidcServerConfiguration = await this.initAsync(authority, configuration.authority_configuration);
|
|
1057
|
-
const tokenResponse = await performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens, configuration.token_renew_mode);
|
|
1058
|
-
if (tokenResponse.success) {
|
|
1059
|
-
if (!isTokensOidcValid(tokenResponse.data, nonce.nonce, oidcServerConfiguration)) {
|
|
1060
|
-
updateTokens(null);
|
|
1061
|
-
this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token return not valid tokens' });
|
|
1062
|
-
return { tokens: null, status: 'SESSION_LOST' };
|
|
1039
|
+
default: {
|
|
1040
|
+
this.publishEvent(eventNames.refreshTokensAsync_begin, { refreshToken, status, tryNumber: index });
|
|
1041
|
+
if (!refreshToken) {
|
|
1042
|
+
return await localsilentLoginAsync();
|
|
1063
1043
|
}
|
|
1064
|
-
|
|
1065
|
-
|
|
1066
|
-
|
|
1067
|
-
|
|
1068
|
-
|
|
1069
|
-
|
|
1070
|
-
|
|
1071
|
-
|
|
1072
|
-
|
|
1073
|
-
|
|
1044
|
+
|
|
1045
|
+
const clientId = configuration.client_id;
|
|
1046
|
+
const redirectUri = configuration.redirect_uri;
|
|
1047
|
+
const authority = configuration.authority;
|
|
1048
|
+
const tokenExtras = configuration.token_request_extras ? configuration.token_request_extras : {};
|
|
1049
|
+
const finalExtras = { ...tokenExtras, ...extras };
|
|
1050
|
+
const localFunctionAsync = async () => {
|
|
1051
|
+
const details = {
|
|
1052
|
+
client_id: clientId,
|
|
1053
|
+
redirect_uri: redirectUri,
|
|
1054
|
+
grant_type: GRANT_TYPE_REFRESH_TOKEN,
|
|
1055
|
+
refresh_token: tokens.refreshToken,
|
|
1056
|
+
};
|
|
1057
|
+
const oidcServerConfiguration = await this.initAsync(authority, configuration.authority_configuration);
|
|
1058
|
+
const timeoutMs = document.hidden ? 10000 : 30000 * 10;
|
|
1059
|
+
const tokenResponse = await performTokenRequestAsync(oidcServerConfiguration.tokenEndpoint, details, finalExtras, tokens, configuration.token_renew_mode, timeoutMs);
|
|
1060
|
+
if (tokenResponse.success) {
|
|
1061
|
+
if (!isTokensOidcValid(tokenResponse.data, nonce.nonce, oidcServerConfiguration)) {
|
|
1062
|
+
updateTokens(null);
|
|
1063
|
+
this.publishEvent(eventNames.refreshTokensAsync_error, { message: 'refresh token return not valid tokens' });
|
|
1064
|
+
return { tokens: null, status: 'SESSION_LOST' };
|
|
1065
|
+
}
|
|
1066
|
+
updateTokens(tokenResponse.data);
|
|
1067
|
+
this.publishEvent(eventNames.refreshTokensAsync_end, { success: tokenResponse.success });
|
|
1068
|
+
this.publishEvent(Oidc.eventNames.token_renewed, { reason: 'REFRESH_TOKEN' });
|
|
1069
|
+
return { tokens: tokenResponse.data, status: 'LOGGED_IN' };
|
|
1070
|
+
} else {
|
|
1071
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, {
|
|
1072
|
+
message: 'bad request',
|
|
1073
|
+
tokenResponse,
|
|
1074
|
+
});
|
|
1075
|
+
return await this.synchroniseTokensAsync(refreshToken, nextIndex, forceRefresh, extras, updateTokens);
|
|
1076
|
+
}
|
|
1077
|
+
};
|
|
1078
|
+
// const promise =
|
|
1079
|
+
return await localFunctionAsync(); // executeWithTimeoutAsync(promise, 30000);
|
|
1074
1080
|
}
|
|
1075
1081
|
}
|
|
1076
|
-
}
|
|
1082
|
+
} catch (exception) {
|
|
1083
|
+
console.error(exception);
|
|
1084
|
+
this.publishEvent(eventNames.refreshTokensAsync_silent_error, { message: 'exception', exception: exception.message });
|
|
1085
|
+
return this.synchroniseTokensAsync(refreshToken, nextIndex, forceRefresh, extras, updateTokens);
|
|
1086
|
+
}
|
|
1077
1087
|
}
|
|
1078
1088
|
|
|
1079
1089
|
async syncTokensInfoAsync(configuration, configurationName, currentTokens, forceRefresh = false) {
|
|
@@ -1085,7 +1095,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1085
1095
|
}
|
|
1086
1096
|
let nonce = nullNonce;
|
|
1087
1097
|
const oidcServerConfiguration = await this.initAsync(configuration.authority, configuration.authority_configuration);
|
|
1088
|
-
const serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, configurationName);
|
|
1098
|
+
const serviceWorker = await initWorkerAsync(configuration.service_worker_relative_url, configurationName, configuration.redirect_uri);
|
|
1089
1099
|
if (serviceWorker) {
|
|
1090
1100
|
const { status, tokens } = await serviceWorker.initAsync(oidcServerConfiguration, 'syncTokensAsync', configuration);
|
|
1091
1101
|
if (status === 'LOGGED_OUT') {
|
|
@@ -1164,7 +1174,7 @@ Please checkout that you are using OIDC hook inside a <OidcProvider configuratio
|
|
|
1164
1174
|
if (this.checkSessionIFrame) {
|
|
1165
1175
|
this.checkSessionIFrame.stop();
|
|
1166
1176
|
}
|
|
1167
|
-
const serviceWorker = await initWorkerAsync(this.configuration.service_worker_relative_url, this.configurationName);
|
|
1177
|
+
const serviceWorker = await initWorkerAsync(this.configuration.service_worker_relative_url, this.configurationName, this.configuration.redirect_uri);
|
|
1168
1178
|
if (!serviceWorker) {
|
|
1169
1179
|
const session = initSession(this.configurationName, this.configuration.redirect_uri, this.configuration.storage);
|
|
1170
1180
|
await session.clearAsync(status);
|