@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,115 +1,117 @@
1
1
  export const initSession = (configurationName, storage = sessionStorage) => {
2
- const clearAsync = (status) => {
3
- storage[`oidc.${configurationName}`] = JSON.stringify({ tokens: null, status });
4
- return Promise.resolve();
5
- };
6
-
7
- const initAsync = async () => {
8
- if (!storage[`oidc.${configurationName}`]) {
9
- storage[`oidc.${configurationName}`] = JSON.stringify({ tokens: null, status: null });
10
- return { tokens: null, status: null };
11
- }
12
- const data = JSON.parse(storage[`oidc.${configurationName}`]);
13
- return Promise.resolve({ tokens: data.tokens, status: data.status });
14
- };
15
-
16
- const setTokens = (tokens) => {
17
- storage[`oidc.${configurationName}`] = JSON.stringify({ tokens });
18
- };
19
-
20
- const setSessionStateAsync = async (sessionState) => {
21
- storage[`oidc.session_state.${configurationName}`] = sessionState;
22
- };
23
-
24
- const getSessionStateAsync = async () => {
25
- return storage[`oidc.session_state.${configurationName}`];
26
- };
27
-
28
- const setNonceAsync = (nonce) => {
29
- storage[`oidc.nonce.${configurationName}`] = nonce.nonce;
30
- };
31
-
32
- const setDemonstratingProofOfPossessionJwkAsync = (jwk:JsonWebKey) => {
33
- storage[`oidc.jwk.${configurationName}`] = JSON.stringify(jwk);
34
- };
35
-
36
- const getDemonstratingProofOfPossessionJwkAsync = () => {
37
- return JSON.parse(storage[`oidc.jwk.${configurationName}`]);
38
- };
39
-
40
- const getNonceAsync = async () => {
41
- // @ts-ignore
42
- return { nonce: storage[`oidc.nonce.${configurationName}`] };
43
- };
44
-
45
- const setDemonstratingProofOfPossessionNonce = async (dpopNonce:string) => {
46
- storage[`oidc.dpop_nonce.${configurationName}`] = dpopNonce;
47
- };
48
-
49
- const getDemonstratingProofOfPossessionNonce = () => {
50
- return storage[`oidc.dpop_nonce.${configurationName}`];
51
- };
52
-
53
- const getTokens = () => {
54
- if (!storage[`oidc.${configurationName}`]) {
55
- return null;
56
- }
57
- return JSON.stringify({ tokens: JSON.parse(storage[`oidc.${configurationName}`]).tokens });
58
- };
59
-
60
- let getLoginParamsCache = {};
61
- const setLoginParams = (data) => {
62
- getLoginParamsCache[configurationName] = data;
63
- storage[`oidc.login.${configurationName}`] = JSON.stringify(data);
64
- };
65
- const getLoginParams = () => {
66
- const dataString = storage[`oidc.login.${configurationName}`];
67
-
68
- if(!dataString){
69
- console.warn(`storage[oidc.login.${configurationName}] is empty, you should have an bad OIDC or code configuration somewhere.`);
70
- return null;
71
- }
72
-
73
- if (!getLoginParamsCache[configurationName]) {
74
- getLoginParamsCache[configurationName] = JSON.parse(dataString);
75
- }
76
- return getLoginParamsCache[configurationName];
77
- };
78
-
79
- const getStateAsync = async () => {
80
- return storage[`oidc.state.${configurationName}`];
81
- };
82
-
83
- const setStateAsync = async (state:string) => {
84
- storage[`oidc.state.${configurationName}`] = state;
85
- };
86
-
87
- const getCodeVerifierAsync = async () => {
88
- return storage[`oidc.code_verifier.${configurationName}`];
89
- };
90
-
91
- const setCodeVerifierAsync = async (codeVerifier) => {
92
- storage[`oidc.code_verifier.${configurationName}`] = codeVerifier;
93
- };
94
-
95
- return {
96
- clearAsync,
97
- initAsync,
98
- setTokens,
99
- getTokens,
100
- setSessionStateAsync,
101
- getSessionStateAsync,
102
- setNonceAsync,
103
- getNonceAsync,
104
- setLoginParams,
105
- getLoginParams,
106
- getStateAsync,
107
- setStateAsync,
108
- getCodeVerifierAsync,
109
- setCodeVerifierAsync,
110
- setDemonstratingProofOfPossessionNonce,
111
- getDemonstratingProofOfPossessionNonce,
112
- setDemonstratingProofOfPossessionJwkAsync,
113
- getDemonstratingProofOfPossessionJwkAsync,
114
- };
2
+ const clearAsync = status => {
3
+ storage[`oidc.${configurationName}`] = JSON.stringify({ tokens: null, status });
4
+ return Promise.resolve();
5
+ };
6
+
7
+ const initAsync = async () => {
8
+ if (!storage[`oidc.${configurationName}`]) {
9
+ storage[`oidc.${configurationName}`] = JSON.stringify({ tokens: null, status: null });
10
+ return { tokens: null, status: null };
11
+ }
12
+ const data = JSON.parse(storage[`oidc.${configurationName}`]);
13
+ return Promise.resolve({ tokens: data.tokens, status: data.status });
14
+ };
15
+
16
+ const setTokens = tokens => {
17
+ storage[`oidc.${configurationName}`] = JSON.stringify({ tokens });
18
+ };
19
+
20
+ const setSessionStateAsync = async sessionState => {
21
+ storage[`oidc.session_state.${configurationName}`] = sessionState;
22
+ };
23
+
24
+ const getSessionStateAsync = async () => {
25
+ return storage[`oidc.session_state.${configurationName}`];
26
+ };
27
+
28
+ const setNonceAsync = nonce => {
29
+ storage[`oidc.nonce.${configurationName}`] = nonce.nonce;
30
+ };
31
+
32
+ const setDemonstratingProofOfPossessionJwkAsync = (jwk: JsonWebKey) => {
33
+ storage[`oidc.jwk.${configurationName}`] = JSON.stringify(jwk);
34
+ };
35
+
36
+ const getDemonstratingProofOfPossessionJwkAsync = () => {
37
+ return JSON.parse(storage[`oidc.jwk.${configurationName}`]);
38
+ };
39
+
40
+ const getNonceAsync = async () => {
41
+ // @ts-ignore
42
+ return { nonce: storage[`oidc.nonce.${configurationName}`] };
43
+ };
44
+
45
+ const setDemonstratingProofOfPossessionNonce = async (dpopNonce: string) => {
46
+ storage[`oidc.dpop_nonce.${configurationName}`] = dpopNonce;
47
+ };
48
+
49
+ const getDemonstratingProofOfPossessionNonce = (): string => {
50
+ return storage[`oidc.dpop_nonce.${configurationName}`];
51
+ };
52
+
53
+ const getTokens = () => {
54
+ if (!storage[`oidc.${configurationName}`]) {
55
+ return null;
56
+ }
57
+ return JSON.stringify({ tokens: JSON.parse(storage[`oidc.${configurationName}`]).tokens });
58
+ };
59
+
60
+ const getLoginParamsCache = {};
61
+ const setLoginParams = data => {
62
+ getLoginParamsCache[configurationName] = data;
63
+ storage[`oidc.login.${configurationName}`] = JSON.stringify(data);
64
+ };
65
+ const getLoginParams = () => {
66
+ const dataString = storage[`oidc.login.${configurationName}`];
67
+
68
+ if (!dataString) {
69
+ console.warn(
70
+ `storage[oidc.login.${configurationName}] is empty, you should have an bad OIDC or code configuration somewhere.`,
71
+ );
72
+ return null;
73
+ }
74
+
75
+ if (!getLoginParamsCache[configurationName]) {
76
+ getLoginParamsCache[configurationName] = JSON.parse(dataString);
77
+ }
78
+ return getLoginParamsCache[configurationName];
79
+ };
80
+
81
+ const getStateAsync = async () => {
82
+ return storage[`oidc.state.${configurationName}`];
83
+ };
84
+
85
+ const setStateAsync = async (state: string) => {
86
+ storage[`oidc.state.${configurationName}`] = state;
87
+ };
88
+
89
+ const getCodeVerifierAsync = async () => {
90
+ return storage[`oidc.code_verifier.${configurationName}`];
91
+ };
92
+
93
+ const setCodeVerifierAsync = async codeVerifier => {
94
+ storage[`oidc.code_verifier.${configurationName}`] = codeVerifier;
95
+ };
96
+
97
+ return {
98
+ clearAsync,
99
+ initAsync,
100
+ setTokens,
101
+ getTokens,
102
+ setSessionStateAsync,
103
+ getSessionStateAsync,
104
+ setNonceAsync,
105
+ getNonceAsync,
106
+ setLoginParams,
107
+ getLoginParams,
108
+ getStateAsync,
109
+ setStateAsync,
110
+ getCodeVerifierAsync,
111
+ setCodeVerifierAsync,
112
+ setDemonstratingProofOfPossessionNonce,
113
+ getDemonstratingProofOfPossessionNonce,
114
+ setDemonstratingProofOfPossessionJwkAsync,
115
+ getDemonstratingProofOfPossessionJwkAsync,
116
+ };
115
117
  };