@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
@@ -1,84 +1,103 @@
1
- import {initWorkerAsync} from "./initWorker";
2
- import {autoRenewTokens} from "./renewTokens";
3
- import {initSession} from "./initSession";
4
- import {setTokens} from "./parseTokens";
5
- import {eventNames} from "./events";
6
- import Oidc from "./oidc";
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
- let serviceWorker;
11
- if (oidc.tokens != null) {
12
- return false;
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.tryKeepExistingSessionAsync_begin, {});
15
- try {
16
- const configuration = oidc.configuration;
17
- const oidcServerConfiguration = await oidc.initAsync(configuration.authority, configuration.authority_configuration);
18
- serviceWorker = await initWorkerAsync(configuration, oidc.configurationName);
19
- if (serviceWorker) {
20
- const { tokens } = await serviceWorker.initAsync(oidcServerConfiguration, 'tryKeepExistingSessionAsync', configuration);
21
- if (tokens) {
22
- serviceWorker.startKeepAliveServiceWorker();
23
- // @ts-ignore
24
- oidc.tokens = tokens;
25
- const getLoginParams = serviceWorker.getLoginParams(oidc.configurationName);
26
- // @ts-ignore
27
- oidc.timeoutId = autoRenewTokens(oidc, oidc.tokens.expiresAt, getLoginParams.extras);
28
- const sessionState = await serviceWorker.getSessionStateAsync();
29
- // @ts-ignore
30
- await oidc.startCheckSessionAsync(oidcServerConfiguration.check_session_iframe, configuration.client_id, sessionState);
31
- if(configuration.preload_user_info){
32
- await oidc.userInfoAsync();
33
- }
34
- oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
35
- success: true,
36
- message: 'tokens inside ServiceWorker are valid',
37
- });
38
- return true;
39
- }
40
- oidc.publishEvent(eventNames.tryKeepExistingSessionAsync_end, {
41
- success: false,
42
- message: 'no exiting session found',
43
- });
44
- } else {
45
- if (configuration.service_worker_relative_url) {
46
- oidc.publishEvent(eventNames.service_worker_not_supported_by_browser, {
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
- export interface ILOidcLocation {
3
- open(url:string):void;
4
- reload():void;
5
- getCurrentHref():string;
6
- getPath():string;
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
- open(url:string) {
12
- window.location.href = url;
13
- }
10
+ open(url: string) {
11
+ window.location.href = url;
12
+ }
14
13
 
15
- reload() {
16
- window.location.reload();
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
- getOrigin(): string {
29
- return window.origin;
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
  }