@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/keepSession.ts
CHANGED
|
@@ -1,84 +1,103 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import
|
|
5
|
-
import {
|
|
6
|
-
import
|
|
1
|
+
import { eventNames } from './events';
|
|
2
|
+
import { initSession } from './initSession';
|
|
3
|
+
import { initWorkerAsync } from './initWorker';
|
|
4
|
+
import Oidc from './oidc';
|
|
5
|
+
import { setTokens } from './parseTokens';
|
|
6
|
+
import { autoRenewTokens } from './renewTokens';
|
|
7
7
|
|
|
8
|
-
export const tryKeepSessionAsync = async (oidc: Oidc) =>{
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
8
|
+
export const tryKeepSessionAsync = async (oidc: Oidc) => {
|
|
9
|
+
let serviceWorker;
|
|
10
|
+
if (oidc.tokens != null) {
|
|
11
|
+
return false;
|
|
12
|
+
}
|
|
13
|
+
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_begin, {});
|
|
14
|
+
try {
|
|
15
|
+
const configuration = oidc.configuration;
|
|
16
|
+
const oidcServerConfiguration = await oidc.initAsync(
|
|
17
|
+
configuration.authority,
|
|
18
|
+
configuration.authority_configuration,
|
|
19
|
+
);
|
|
20
|
+
serviceWorker = await initWorkerAsync(configuration, oidc.configurationName);
|
|
21
|
+
if (serviceWorker) {
|
|
22
|
+
const { tokens } = await serviceWorker.initAsync(
|
|
23
|
+
oidcServerConfiguration,
|
|
24
|
+
'tryKeepExistingSessionAsync',
|
|
25
|
+
configuration,
|
|
26
|
+
);
|
|
27
|
+
if (tokens) {
|
|
28
|
+
serviceWorker.startKeepAliveServiceWorker();
|
|
29
|
+
// @ts-ignore
|
|
30
|
+
oidc.tokens = tokens;
|
|
31
|
+
const getLoginParams = serviceWorker.getLoginParams(oidc.configurationName);
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, getLoginParams.extras);
|
|
34
|
+
const sessionState = await serviceWorker.getSessionStateAsync();
|
|
35
|
+
// @ts-ignore
|
|
36
|
+
await oidc.startCheckSessionAsync(
|
|
37
|
+
oidcServerConfiguration.check_session_iframe,
|
|
38
|
+
configuration.client_id,
|
|
39
|
+
sessionState,
|
|
40
|
+
);
|
|
41
|
+
if (configuration.preload_user_info) {
|
|
42
|
+
await oidc.userInfoAsync();
|
|
13
43
|
}
|
|
14
|
-
oidc.publishEvent(eventNames.
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
message: 'service worker is not supported by this browser',
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
const session = initSession(oidc.configurationName, configuration.storage ?? sessionStorage);
|
|
51
|
-
const { tokens } = await session.initAsync();
|
|
52
|
-
if (tokens) {
|
|
53
|
-
// @ts-ignore
|
|
54
|
-
oidc.tokens = setTokens(tokens, null, configuration.token_renew_mode);
|
|
55
|
-
const getLoginParams = session.getLoginParams();
|
|
56
|
-
// @ts-ignore
|
|
57
|
-
oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, getLoginParams.extras);
|
|
58
|
-
const sessionState = await session.getSessionStateAsync();
|
|
59
|
-
// @ts-ignore
|
|
60
|
-
await oidc.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
|
|
61
|
-
if(configuration.preload_user_info){
|
|
62
|
-
await oidc.userInfoAsync();
|
|
63
|
-
}
|
|
64
|
-
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
65
|
-
success: true,
|
|
66
|
-
message: 'tokens inside storage are valid',
|
|
67
|
-
});
|
|
68
|
-
return true;
|
|
69
|
-
}
|
|
70
|
-
}
|
|
71
|
-
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
72
|
-
success: false,
|
|
73
|
-
message: serviceWorker ? 'service worker sessions not retrieved' : 'session storage sessions not retrieved',
|
|
74
|
-
});
|
|
75
|
-
return false;
|
|
76
|
-
} catch (exception) {
|
|
77
|
-
console.error(exception);
|
|
78
|
-
if (serviceWorker) {
|
|
79
|
-
await serviceWorker.clearAsync();
|
|
80
|
-
}
|
|
81
|
-
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_error, 'tokens inside ServiceWorker are invalid');
|
|
82
|
-
return false;
|
|
44
|
+
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
45
|
+
success: true,
|
|
46
|
+
message: 'tokens inside ServiceWorker are valid',
|
|
47
|
+
});
|
|
48
|
+
return true;
|
|
49
|
+
}
|
|
50
|
+
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
51
|
+
success: false,
|
|
52
|
+
message: 'no exiting session found',
|
|
53
|
+
});
|
|
54
|
+
} else {
|
|
55
|
+
if (configuration.service_worker_relative_url) {
|
|
56
|
+
oidc.publishEvent(eventNames.service_worker_not_supported_by_browser, {
|
|
57
|
+
message: 'service worker is not supported by this browser',
|
|
58
|
+
});
|
|
59
|
+
}
|
|
60
|
+
const session = initSession(oidc.configurationName, configuration.storage ?? sessionStorage);
|
|
61
|
+
const { tokens } = await session.initAsync();
|
|
62
|
+
if (tokens) {
|
|
63
|
+
// @ts-ignore
|
|
64
|
+
oidc.tokens = setTokens(tokens, null, configuration.token_renew_mode);
|
|
65
|
+
const getLoginParams = session.getLoginParams();
|
|
66
|
+
// @ts-ignore
|
|
67
|
+
oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, getLoginParams.extras);
|
|
68
|
+
const sessionState = await session.getSessionStateAsync();
|
|
69
|
+
// @ts-ignore
|
|
70
|
+
await oidc.startCheckSessionAsync(
|
|
71
|
+
oidcServerConfiguration.check_session_iframe,
|
|
72
|
+
configuration.client_id,
|
|
73
|
+
sessionState,
|
|
74
|
+
);
|
|
75
|
+
if (configuration.preload_user_info) {
|
|
76
|
+
await oidc.userInfoAsync();
|
|
83
77
|
}
|
|
84
|
-
|
|
78
|
+
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
79
|
+
success: true,
|
|
80
|
+
message: 'tokens inside storage are valid',
|
|
81
|
+
});
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
|
|
86
|
+
success: false,
|
|
87
|
+
message: serviceWorker
|
|
88
|
+
? 'service worker sessions not retrieved'
|
|
89
|
+
: 'session storage sessions not retrieved',
|
|
90
|
+
});
|
|
91
|
+
return false;
|
|
92
|
+
} catch (exception) {
|
|
93
|
+
console.error(exception);
|
|
94
|
+
if (serviceWorker) {
|
|
95
|
+
await serviceWorker.clearAsync();
|
|
96
|
+
}
|
|
97
|
+
oidc.publishEvent(
|
|
98
|
+
eventNames.tryKeepExistingSessionAsync_error,
|
|
99
|
+
'tokens inside ServiceWorker are invalid',
|
|
100
|
+
);
|
|
101
|
+
return false;
|
|
102
|
+
}
|
|
103
|
+
};
|
package/src/location.ts
CHANGED
|
@@ -1,32 +1,30 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
getOrigin():string;
|
|
1
|
+
export interface ILOidcLocation {
|
|
2
|
+
open(url: string): void;
|
|
3
|
+
reload(): void;
|
|
4
|
+
getCurrentHref(): string;
|
|
5
|
+
getPath(): string;
|
|
6
|
+
getOrigin(): string;
|
|
8
7
|
}
|
|
9
8
|
|
|
10
9
|
export class OidcLocation implements ILOidcLocation {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
10
|
+
open(url: string) {
|
|
11
|
+
window.location.href = url;
|
|
12
|
+
}
|
|
14
13
|
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
getCurrentHref() {
|
|
20
|
-
return window.location.href;
|
|
21
|
-
}
|
|
22
|
-
|
|
23
|
-
getPath() {
|
|
24
|
-
const location = window.location;
|
|
25
|
-
return location.pathname + (location.search || '') + (location.hash || '');
|
|
26
|
-
}
|
|
14
|
+
reload() {
|
|
15
|
+
window.location.reload();
|
|
16
|
+
}
|
|
27
17
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
18
|
+
getCurrentHref() {
|
|
19
|
+
return window.location.href;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
getPath() {
|
|
23
|
+
const location = window.location;
|
|
24
|
+
return location.pathname + (location.search || '') + (location.hash || '');
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
getOrigin(): string {
|
|
28
|
+
return window.origin;
|
|
29
|
+
}
|
|
32
30
|
}
|