@axa-fr/react-oidc 6.24.27-alpha928 → 6.25.0-alpha939

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 (264) hide show
  1. package/bin/post-install.js +35 -0
  2. package/dist/FetchToken.d.ts +2 -3
  3. package/dist/FetchToken.d.ts.map +1 -1
  4. package/dist/OidcProvider.d.ts +4 -5
  5. package/dist/OidcProvider.d.ts.map +1 -1
  6. package/dist/OidcSecure.d.ts +3 -3
  7. package/dist/OidcSecure.d.ts.map +1 -1
  8. package/dist/OidcServiceWorker.js +559 -0
  9. package/{service_worker → dist}/OidcTrustedDomains.js +4 -5
  10. package/dist/ReactOidc.d.ts +4 -4
  11. package/dist/ReactOidc.d.ts.map +1 -1
  12. package/dist/User.d.ts +2 -2
  13. package/dist/User.d.ts.map +1 -1
  14. package/dist/core/default-component/AuthenticateError.component.d.ts.map +1 -1
  15. package/dist/core/default-component/Authenticating.component.d.ts.map +1 -1
  16. package/dist/core/default-component/Callback.component.d.ts.map +1 -1
  17. package/dist/core/default-component/Loading.component.d.ts.map +1 -1
  18. package/dist/core/default-component/ServiceWorkerNotSupported.component.d.ts.map +1 -1
  19. package/dist/core/default-component/SessionLost.component.d.ts.map +1 -1
  20. package/dist/core/default-component/SilentCallback.component.d.ts.map +1 -1
  21. package/dist/core/default-component/SilentLogin.component.d.ts.map +1 -1
  22. package/dist/core/default-component/index.d.ts.map +1 -1
  23. package/dist/core/routes/OidcRoutes.d.ts +1 -1
  24. package/dist/core/routes/OidcRoutes.d.ts.map +1 -1
  25. package/dist/core/routes/index.d.ts +3 -0
  26. package/dist/core/routes/index.d.ts.map +1 -0
  27. package/dist/core/routes/withRouter.d.ts +4 -4
  28. package/dist/core/routes/withRouter.d.ts.map +1 -1
  29. package/dist/index.d.ts +2 -2
  30. package/dist/index.d.ts.map +1 -1
  31. package/dist/index.js +964 -21
  32. package/dist/index.umd.cjs +27 -0
  33. package/package.json +37 -43
  34. package/src/{oidc/FetchToken.tsx → FetchToken.tsx} +14 -16
  35. package/src/{oidc/OidcProvider.tsx → OidcProvider.tsx} +40 -42
  36. package/src/{oidc/OidcSecure.tsx → OidcSecure.tsx} +1 -3
  37. package/src/{oidc/ReactOidc.tsx → ReactOidc.tsx} +1 -3
  38. package/src/{oidc/User.ts → User.ts} +1 -2
  39. package/src/{oidc/core → core}/default-component/AuthenticateError.component.tsx +0 -1
  40. package/src/{oidc/core → core}/default-component/Authenticating.component.tsx +0 -1
  41. package/src/{oidc/core → core}/default-component/Callback.component.tsx +2 -2
  42. package/src/{oidc/core → core}/default-component/Loading.component.tsx +0 -1
  43. package/src/{oidc/core → core}/default-component/ServiceWorkerNotSupported.component.tsx +0 -1
  44. package/src/{oidc/core → core}/default-component/SessionLost.component.tsx +1 -1
  45. package/src/{oidc/core → core}/default-component/SilentCallback.component.tsx +1 -2
  46. package/src/{oidc/core → core}/default-component/SilentLogin.component.tsx +1 -3
  47. package/src/{oidc/core → core}/routes/OidcRoutes.spec.tsx +3 -2
  48. package/src/{oidc/core → core}/routes/OidcRoutes.tsx +6 -6
  49. package/src/{oidc/core → core}/routes/withRouter.spec.tsx +3 -5
  50. package/src/{oidc/index.ts → index.ts} +7 -2
  51. package/bin/copy.cjs +0 -43
  52. package/dist/FetchToken.js +0 -59
  53. package/dist/FetchToken.js.map +0 -1
  54. package/dist/OidcProvider.js +0 -134
  55. package/dist/OidcProvider.js.map +0 -1
  56. package/dist/OidcSecure.js +0 -25
  57. package/dist/OidcSecure.js.map +0 -1
  58. package/dist/ReactOidc.js +0 -156
  59. package/dist/ReactOidc.js.map +0 -1
  60. package/dist/User.js +0 -42
  61. package/dist/User.js.map +0 -1
  62. package/dist/core/default-component/AuthenticateError.component.js +0 -6
  63. package/dist/core/default-component/AuthenticateError.component.js.map +0 -1
  64. package/dist/core/default-component/Authenticating.component.js +0 -6
  65. package/dist/core/default-component/Authenticating.component.js.map +0 -1
  66. package/dist/core/default-component/Callback.component.js +0 -54
  67. package/dist/core/default-component/Callback.component.js.map +0 -1
  68. package/dist/core/default-component/Loading.component.js +0 -6
  69. package/dist/core/default-component/Loading.component.js.map +0 -1
  70. package/dist/core/default-component/ServiceWorkerNotSupported.component.js +0 -6
  71. package/dist/core/default-component/ServiceWorkerNotSupported.component.js.map +0 -1
  72. package/dist/core/default-component/SessionLost.component.js +0 -8
  73. package/dist/core/default-component/SessionLost.component.js.map +0 -1
  74. package/dist/core/default-component/SilentCallback.component.js +0 -27
  75. package/dist/core/default-component/SilentCallback.component.js.map +0 -1
  76. package/dist/core/default-component/SilentLogin.component.js +0 -29
  77. package/dist/core/default-component/SilentLogin.component.js.map +0 -1
  78. package/dist/core/default-component/index.js +0 -20
  79. package/dist/core/default-component/index.js.map +0 -1
  80. package/dist/core/routes/OidcRoutes.js +0 -64
  81. package/dist/core/routes/OidcRoutes.js.map +0 -1
  82. package/dist/core/routes/withRouter.js +0 -31
  83. package/dist/core/routes/withRouter.js.map +0 -1
  84. package/dist/index.js.map +0 -1
  85. package/dist/service_worker/OidcServiceWorker.d.ts +0 -2
  86. package/dist/service_worker/OidcServiceWorker.d.ts.map +0 -1
  87. package/dist/service_worker/OidcServiceWorker.js +0 -2
  88. package/dist/service_worker/OidcServiceWorker.js.map +0 -1
  89. package/dist/service_worker/constants.d.ts +0 -18
  90. package/dist/service_worker/constants.d.ts.map +0 -1
  91. package/dist/service_worker/types.d.ts +0 -87
  92. package/dist/service_worker/types.d.ts.map +0 -1
  93. package/dist/service_worker/utils/codeVerifier.d.ts +0 -2
  94. package/dist/service_worker/utils/codeVerifier.d.ts.map +0 -1
  95. package/dist/service_worker/utils/domains.d.ts +0 -7
  96. package/dist/service_worker/utils/domains.d.ts.map +0 -1
  97. package/dist/service_worker/utils/index.d.ts +0 -6
  98. package/dist/service_worker/utils/index.d.ts.map +0 -1
  99. package/dist/service_worker/utils/serializeHeaders.d.ts +0 -3
  100. package/dist/service_worker/utils/serializeHeaders.d.ts.map +0 -1
  101. package/dist/service_worker/utils/sleep.d.ts +0 -3
  102. package/dist/service_worker/utils/sleep.d.ts.map +0 -1
  103. package/dist/service_worker/utils/strings.d.ts +0 -8
  104. package/dist/service_worker/utils/strings.d.ts.map +0 -1
  105. package/dist/service_worker/utils/tokens.d.ts +0 -22
  106. package/dist/service_worker/utils/tokens.d.ts.map +0 -1
  107. package/dist/tsconfig.tsbuildinfo +0 -1
  108. package/dist/vanilla/cache.d.ts +0 -3
  109. package/dist/vanilla/cache.d.ts.map +0 -1
  110. package/dist/vanilla/cache.js +0 -30
  111. package/dist/vanilla/cache.js.map +0 -1
  112. package/dist/vanilla/checkSession.d.ts +0 -4
  113. package/dist/vanilla/checkSession.d.ts.map +0 -1
  114. package/dist/vanilla/checkSession.js +0 -73
  115. package/dist/vanilla/checkSession.js.map +0 -1
  116. package/dist/vanilla/checkSessionIFrame.d.ts +0 -17
  117. package/dist/vanilla/checkSessionIFrame.d.ts.map +0 -1
  118. package/dist/vanilla/checkSessionIFrame.js +0 -73
  119. package/dist/vanilla/checkSessionIFrame.js.map +0 -1
  120. package/dist/vanilla/crypto.d.ts +0 -4
  121. package/dist/vanilla/crypto.d.ts.map +0 -1
  122. package/dist/vanilla/crypto.js +0 -85
  123. package/dist/vanilla/crypto.js.map +0 -1
  124. package/dist/vanilla/events.d.ts +0 -29
  125. package/dist/vanilla/events.d.ts.map +0 -1
  126. package/dist/vanilla/events.js +0 -32
  127. package/dist/vanilla/events.js.map +0 -1
  128. package/dist/vanilla/index.d.ts +0 -3
  129. package/dist/vanilla/index.d.ts.map +0 -1
  130. package/dist/vanilla/index.js +0 -6
  131. package/dist/vanilla/index.js.map +0 -1
  132. package/dist/vanilla/initSession.d.ts +0 -22
  133. package/dist/vanilla/initSession.d.ts.map +0 -1
  134. package/dist/vanilla/initSession.js +0 -90
  135. package/dist/vanilla/initSession.js.map +0 -1
  136. package/dist/vanilla/initWorker.d.ts +0 -30
  137. package/dist/vanilla/initWorker.d.ts.map +0 -1
  138. package/dist/vanilla/initWorker.js +0 -317
  139. package/dist/vanilla/initWorker.js.map +0 -1
  140. package/dist/vanilla/login.d.ts +0 -8
  141. package/dist/vanilla/login.d.ts.map +0 -1
  142. package/dist/vanilla/login.js +0 -175
  143. package/dist/vanilla/login.js.map +0 -1
  144. package/dist/vanilla/logout.d.ts +0 -8
  145. package/dist/vanilla/logout.d.ts.map +0 -1
  146. package/dist/vanilla/logout.js +0 -118
  147. package/dist/vanilla/logout.js.map +0 -1
  148. package/dist/vanilla/oidc.d.ts +0 -101
  149. package/dist/vanilla/oidc.d.ts.map +0 -1
  150. package/dist/vanilla/oidc.js +0 -612
  151. package/dist/vanilla/oidc.js.map +0 -1
  152. package/dist/vanilla/parseTokens.d.ts +0 -37
  153. package/dist/vanilla/parseTokens.d.ts.map +0 -1
  154. package/dist/vanilla/parseTokens.js +0 -167
  155. package/dist/vanilla/parseTokens.js.map +0 -1
  156. package/dist/vanilla/renewTokens.d.ts +0 -4
  157. package/dist/vanilla/renewTokens.d.ts.map +0 -1
  158. package/dist/vanilla/renewTokens.js +0 -51
  159. package/dist/vanilla/renewTokens.js.map +0 -1
  160. package/dist/vanilla/requests.d.ts +0 -33
  161. package/dist/vanilla/requests.d.ts.map +0 -1
  162. package/dist/vanilla/requests.js +0 -174
  163. package/dist/vanilla/requests.js.map +0 -1
  164. package/dist/vanilla/route-utils.d.ts +0 -13
  165. package/dist/vanilla/route-utils.d.ts.map +0 -1
  166. package/dist/vanilla/route-utils.js +0 -71
  167. package/dist/vanilla/route-utils.js.map +0 -1
  168. package/dist/vanilla/silentLogin.d.ts +0 -10
  169. package/dist/vanilla/silentLogin.d.ts.map +0 -1
  170. package/dist/vanilla/silentLogin.js +0 -144
  171. package/dist/vanilla/silentLogin.js.map +0 -1
  172. package/dist/vanilla/timer.d.ts +0 -8
  173. package/dist/vanilla/timer.d.ts.map +0 -1
  174. package/dist/vanilla/timer.js +0 -143
  175. package/dist/vanilla/timer.js.map +0 -1
  176. package/dist/vanilla/types.d.ts +0 -38
  177. package/dist/vanilla/types.d.ts.map +0 -1
  178. package/dist/vanilla/types.js +0 -3
  179. package/dist/vanilla/types.js.map +0 -1
  180. package/dist/vanilla/user.d.ts +0 -2
  181. package/dist/vanilla/user.d.ts.map +0 -1
  182. package/dist/vanilla/user.js +0 -48
  183. package/dist/vanilla/user.js.map +0 -1
  184. package/dist/vanilla/vanillaOidc.d.ts +0 -85
  185. package/dist/vanilla/vanillaOidc.d.ts.map +0 -1
  186. package/dist/vanilla/vanillaOidc.js +0 -71
  187. package/dist/vanilla/vanillaOidc.js.map +0 -1
  188. package/service_worker/.eslintrc.cjs +0 -18
  189. package/service_worker/OidcServiceWorker.ts +0 -424
  190. package/service_worker/constants.ts +0 -32
  191. package/service_worker/dist/OidcServiceWorker.d.ts +0 -2
  192. package/service_worker/dist/OidcServiceWorker.d.ts.map +0 -1
  193. package/service_worker/dist/OidcServiceWorker.js +0 -2
  194. package/service_worker/dist/OidcServiceWorker.js.map +0 -1
  195. package/service_worker/dist/constants.d.ts +0 -18
  196. package/service_worker/dist/constants.d.ts.map +0 -1
  197. package/service_worker/dist/types.d.ts +0 -87
  198. package/service_worker/dist/types.d.ts.map +0 -1
  199. package/service_worker/dist/utils/codeVerifier.d.ts +0 -2
  200. package/service_worker/dist/utils/codeVerifier.d.ts.map +0 -1
  201. package/service_worker/dist/utils/domains.d.ts +0 -7
  202. package/service_worker/dist/utils/domains.d.ts.map +0 -1
  203. package/service_worker/dist/utils/index.d.ts +0 -6
  204. package/service_worker/dist/utils/index.d.ts.map +0 -1
  205. package/service_worker/dist/utils/serializeHeaders.d.ts +0 -3
  206. package/service_worker/dist/utils/serializeHeaders.d.ts.map +0 -1
  207. package/service_worker/dist/utils/sleep.d.ts +0 -3
  208. package/service_worker/dist/utils/sleep.d.ts.map +0 -1
  209. package/service_worker/dist/utils/strings.d.ts +0 -8
  210. package/service_worker/dist/utils/strings.d.ts.map +0 -1
  211. package/service_worker/dist/utils/tokens.d.ts +0 -22
  212. package/service_worker/dist/utils/tokens.d.ts.map +0 -1
  213. package/service_worker/tsconfig.json +0 -26
  214. package/service_worker/types.ts +0 -103
  215. package/service_worker/utils/__tests__/codeVerifier.spec.ts +0 -14
  216. package/service_worker/utils/__tests__/domains.spec.ts +0 -90
  217. package/service_worker/utils/__tests__/serializeHeaders.spec.ts +0 -11
  218. package/service_worker/utils/__tests__/strings.spec.ts +0 -9
  219. package/service_worker/utils/__tests__/testHelper.ts +0 -352
  220. package/service_worker/utils/__tests__/tokens.spec.ts +0 -92
  221. package/service_worker/utils/codeVerifier.ts +0 -6
  222. package/service_worker/utils/domains.ts +0 -105
  223. package/service_worker/utils/index.ts +0 -5
  224. package/service_worker/utils/serializeHeaders.ts +0 -12
  225. package/service_worker/utils/sleep.ts +0 -2
  226. package/service_worker/utils/strings.ts +0 -9
  227. package/service_worker/utils/tokens.ts +0 -206
  228. package/src/oidc/vanilla/cache.ts +0 -27
  229. package/src/oidc/vanilla/checkSession.ts +0 -60
  230. package/src/oidc/vanilla/checkSessionIFrame.ts +0 -83
  231. package/src/oidc/vanilla/crypto.ts +0 -61
  232. package/src/oidc/vanilla/events.ts +0 -29
  233. package/src/oidc/vanilla/index.ts +0 -2
  234. package/src/oidc/vanilla/iniWorker.spec.ts +0 -21
  235. package/src/oidc/vanilla/initSession.ts +0 -90
  236. package/src/oidc/vanilla/initWorker.ts +0 -321
  237. package/src/oidc/vanilla/login.ts +0 -174
  238. package/src/oidc/vanilla/logout.spec.ts +0 -66
  239. package/src/oidc/vanilla/logout.spec.tsx +0 -64
  240. package/src/oidc/vanilla/logout.ts +0 -101
  241. package/src/oidc/vanilla/oidc.ts +0 -614
  242. package/src/oidc/vanilla/parseTokens.spec.ts +0 -49
  243. package/src/oidc/vanilla/parseTokens.ts +0 -194
  244. package/src/oidc/vanilla/renewTokens.ts +0 -37
  245. package/src/oidc/vanilla/requests.spec.ts +0 -9
  246. package/src/oidc/vanilla/requests.ts +0 -169
  247. package/src/oidc/vanilla/route-utils.spec.ts +0 -23
  248. package/src/oidc/vanilla/route-utils.ts +0 -79
  249. package/src/oidc/vanilla/silentLogin.ts +0 -144
  250. package/src/oidc/vanilla/timer.ts +0 -163
  251. package/src/oidc/vanilla/types.ts +0 -42
  252. package/src/oidc/vanilla/user.ts +0 -40
  253. package/src/oidc/vanilla/vanillaOidc.ts +0 -109
  254. package/src/override/AuthenticateError.component.tsx +0 -15
  255. package/src/override/Authenticating.component.tsx +0 -15
  256. package/src/override/Callback.component.tsx +0 -14
  257. package/src/override/Loading.component.tsx +0 -11
  258. package/src/override/ServiceWorkerNotSupported.component.tsx +0 -15
  259. package/src/override/SessionLost.component.tsx +0 -22
  260. package/src/override/style.ts +0 -12
  261. /package/src/{oidc/core → core}/default-component/index.ts +0 -0
  262. /package/src/{oidc/core → core}/routes/__snapshots__/OidcRoutes.spec.tsx.snap +0 -0
  263. /package/src/{oidc/core → core}/routes/index.ts +0 -0
  264. /package/src/{oidc/core → core}/routes/withRouter.tsx +0 -0
@@ -1,206 +0,0 @@
1
- import { TOKEN, TokenRenewMode } from '../constants';
2
- import { OidcConfig, OidcConfiguration, OidcServerConfiguration, Tokens } from '../types';
3
- import { countLetter } from './strings';
4
-
5
- function parseJwt(token: string) {
6
- return JSON.parse(
7
- b64DecodeUnicode(token.split('.')[1].replace('-', '+').replace('_', '/'))
8
- );
9
- }
10
- function b64DecodeUnicode(str: string) {
11
- return decodeURIComponent(
12
- Array.prototype.map
13
- .call(
14
- atob(str),
15
- (c) => '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2)
16
- )
17
- .join('')
18
- );
19
- }
20
-
21
- function computeTimeLeft(
22
- refreshTimeBeforeTokensExpirationInSecond: number,
23
- expiresAt: number
24
- ) {
25
- const currentTimeUnixSecond = new Date().getTime() / 1000;
26
- return Math.round(
27
- expiresAt -
28
- refreshTimeBeforeTokensExpirationInSecond -
29
- currentTimeUnixSecond
30
- );
31
- }
32
-
33
- function isTokensValid(tokens: Tokens | null) {
34
- if (!tokens) {
35
- return false;
36
- }
37
- return computeTimeLeft(0, tokens.expiresAt) > 0;
38
- }
39
-
40
- const extractTokenPayload = (token?: string) => {
41
- try {
42
- if (!token) {
43
- return null;
44
- }
45
- if (countLetter(token, '.') === 2) {
46
- return parseJwt(token);
47
- } else {
48
- return null;
49
- }
50
- } catch (e) {
51
- console.warn(e);
52
- }
53
- return null;
54
- };
55
-
56
- // https://openid.net/specs/openid-connect-core-1_0.html#IDTokenValidation (excluding rules #1, #4, #5, #7, #8, #12, and #13 which did not apply).
57
- // https://github.com/openid/AppAuth-JS/issues/65
58
- const isTokensOidcValid = (
59
- tokens: Tokens,
60
- nonce: string | null,
61
- oidcServerConfiguration: OidcServerConfiguration
62
- ): { isValid: boolean; reason: string } => {
63
- if (tokens.idTokenPayload) {
64
- const idTokenPayload = tokens.idTokenPayload;
65
- // 2: The Issuer Identifier for the OpenID Provider (which is typically obtained during Discovery) MUST exactly match the value of the iss (issuer) Claim.
66
- if (oidcServerConfiguration.issuer !== idTokenPayload.iss) {
67
- return { isValid: false, reason: 'Issuer does not match' };
68
- }
69
- // 3: The Client MUST validate that the aud (audience) Claim contains its client_id value registered at the Issuer identified by the iss (issuer) Claim as an audience. The aud (audience) Claim MAY contain an array with more than one element. The ID Token MUST be rejected if the ID Token does not list the Client as a valid audience, or if it contains additional audiences not trusted by the Client.
70
-
71
- // 6: If the ID Token is received via direct communication between the Client and the Token Endpoint (which it is in this flow), the TLS server validation MAY be used to validate the issuer in place of checking the token signature. The Client MUST validate the signature of all other ID Tokens according to JWS [JWS] using the algorithm specified in the JWT alg Header Parameter. The Client MUST use the keys provided by the Issuer.
72
-
73
- // 9: The current time MUST be before the time represented by the exp Claim.
74
- const currentTimeUnixSecond = new Date().getTime() / 1000;
75
- if (idTokenPayload.exp && idTokenPayload.exp < currentTimeUnixSecond) {
76
- return { isValid: false, reason: 'Token expired' };
77
- }
78
- // 10: The iat Claim can be used to reject tokens that were issued too far away from the current time, limiting the amount of time that nonces need to be stored to prevent attacks. The acceptable range is Client specific.
79
- const timeInSevenDays = 60 * 60 * 24 * 7;
80
- if (
81
- idTokenPayload.iat &&
82
- idTokenPayload.iat + timeInSevenDays < currentTimeUnixSecond
83
- ) {
84
- return { isValid: false, reason: 'Token is used from too long time' };
85
- }
86
- // 11: If a nonce value was sent in the Authentication Request, a nonce Claim MUST be present and its value checked to verify that it is the same value as the one that was sent in the Authentication Request. The Client SHOULD check the nonce value for replay attacks. The precise method for detecting replay attacks is Client specific.
87
- if (nonce && idTokenPayload.nonce && idTokenPayload.nonce !== nonce) {
88
- return { isValid: false, reason: 'Nonce does not match' };
89
- }
90
- }
91
- return { isValid: true, reason: '' };
92
- };
93
-
94
- function _hideTokens(tokens: Tokens, currentDatabaseElement: OidcConfig, configurationName: string) {
95
- if (!tokens.issued_at) {
96
- const currentTimeUnixSecond = new Date().getTime() / 1000;
97
- tokens.issued_at = currentTimeUnixSecond;
98
- }
99
-
100
- const accessTokenPayload = extractTokenPayload(tokens.access_token);
101
- const secureTokens = {
102
- ...tokens,
103
- accessTokenPayload,
104
- };
105
- if (currentDatabaseElement.hideAccessToken) {
106
- secureTokens.access_token = TOKEN.ACCESS_TOKEN + '_' + configurationName;
107
- }
108
- tokens.accessTokenPayload = accessTokenPayload;
109
-
110
- let _idTokenPayload = null;
111
- if (tokens.id_token) {
112
- _idTokenPayload = extractTokenPayload(tokens.id_token);
113
- tokens.idTokenPayload = {..._idTokenPayload};
114
- if (_idTokenPayload.nonce && currentDatabaseElement.nonce != null) {
115
- const keyNonce =
116
- TOKEN.NONCE_TOKEN + '_' + currentDatabaseElement.configurationName;
117
- _idTokenPayload.nonce = keyNonce;
118
- }
119
- secureTokens.idTokenPayload = _idTokenPayload;
120
- }
121
- if (tokens.refresh_token) {
122
- secureTokens.refresh_token =
123
- TOKEN.REFRESH_TOKEN + '_' + configurationName;
124
- }
125
-
126
- const idTokenExpiresAt =
127
- _idTokenPayload && _idTokenPayload.exp
128
- ? _idTokenPayload.exp
129
- : Number.MAX_VALUE;
130
- const accessTokenExpiresAt =
131
- accessTokenPayload && accessTokenPayload.exp
132
- ? accessTokenPayload.exp
133
- : tokens.issued_at + tokens.expires_in;
134
-
135
- let expiresAt: number;
136
- const tokenRenewMode = (
137
- currentDatabaseElement.oidcConfiguration as OidcConfiguration
138
- ).token_renew_mode;
139
- if (tokenRenewMode === TokenRenewMode.access_token_invalid) {
140
- expiresAt = accessTokenExpiresAt;
141
- } else if (tokenRenewMode === TokenRenewMode.id_token_invalid) {
142
- expiresAt = idTokenExpiresAt;
143
- } else {
144
- expiresAt =
145
- idTokenExpiresAt < accessTokenExpiresAt
146
- ? idTokenExpiresAt
147
- : accessTokenExpiresAt;
148
- }
149
- secureTokens.expiresAt = expiresAt;
150
-
151
- tokens.expiresAt = expiresAt;
152
- const nonce = currentDatabaseElement.nonce
153
- ? currentDatabaseElement.nonce.nonce
154
- : null;
155
- const {isValid, reason} = isTokensOidcValid(
156
- tokens,
157
- nonce,
158
- currentDatabaseElement.oidcServerConfiguration as OidcServerConfiguration
159
- ); //TODO: Type assertion, could be null.
160
- if (!isValid) {
161
- throw Error(`Tokens are not OpenID valid, reason: ${reason}`);
162
- }
163
-
164
- // When refresh_token is not rotated we reuse ald refresh_token
165
- if (
166
- currentDatabaseElement.tokens != null &&
167
- 'refresh_token' in currentDatabaseElement.tokens &&
168
- !('refresh_token' in tokens)
169
- ) {
170
- const refreshToken = currentDatabaseElement.tokens.refresh_token;
171
-
172
- currentDatabaseElement.tokens = {
173
- ...tokens,
174
- refresh_token: refreshToken,
175
- };
176
- } else {
177
- currentDatabaseElement.tokens = tokens;
178
- }
179
-
180
- currentDatabaseElement.status = 'LOGGED_IN';
181
- return secureTokens;
182
- }
183
-
184
- function hideTokens(currentDatabaseElement: OidcConfig) {
185
- const configurationName = currentDatabaseElement.configurationName;
186
- return (response: Response) => {
187
- if (response.status !== 200) {
188
- return response;
189
- }
190
- return response.json().then<Response>((tokens: Tokens) => {
191
- const secureTokens = _hideTokens(tokens, currentDatabaseElement, configurationName);
192
- const body = JSON.stringify(secureTokens);
193
- return new Response(body, response);
194
- });
195
- };
196
- }
197
-
198
- export {
199
- b64DecodeUnicode,
200
- computeTimeLeft,
201
- isTokensValid,
202
- extractTokenPayload,
203
- isTokensOidcValid,
204
- hideTokens,
205
- _hideTokens
206
- };
@@ -1,27 +0,0 @@
1
-
2
- const fetchFromIssuerCache = {};
3
-
4
- export const getFromCache = (localStorageKey, storage = window.sessionStorage, timeCacheSecond) => {
5
- if (!fetchFromIssuerCache[localStorageKey]) {
6
- if (storage) {
7
- const cacheJson = storage.getItem(localStorageKey);
8
- if (cacheJson) {
9
- fetchFromIssuerCache[localStorageKey] = JSON.parse(cacheJson);
10
- }
11
- }
12
- }
13
- const oneHourMinisecond = 1000 * timeCacheSecond;
14
- // @ts-ignore
15
- if (fetchFromIssuerCache[localStorageKey] && (fetchFromIssuerCache[localStorageKey].timestamp + oneHourMinisecond) > Date.now()) {
16
- return fetchFromIssuerCache[localStorageKey].result;
17
- }
18
- return null;
19
- };
20
-
21
- export const setCache = (localStorageKey, result, storage = window.sessionStorage) => {
22
- const timestamp = Date.now();
23
- fetchFromIssuerCache[localStorageKey] = { result, timestamp };
24
- if (storage) {
25
- storage.setItem(localStorageKey, JSON.stringify({ result, timestamp }));
26
- }
27
- };
@@ -1,60 +0,0 @@
1
- import { CheckSessionIFrame } from './checkSessionIFrame.js';
2
- import { _silentLoginAsync, SilentLoginResponse } from './silentLogin.js';
3
- import { OidcConfiguration } from './types.js';
4
-
5
- // eslint-disable-next-line @typescript-eslint/ban-types
6
- export const startCheckSessionAsync = (oidc:any, oidcDatabase:any, configuration :OidcConfiguration) => (checkSessionIFrameUri, clientId, sessionState, isSilentSignin = false) => {
7
- const silentLoginAsync = (extras, state = undefined, scope = undefined):Promise<SilentLoginResponse> => {
8
- return _silentLoginAsync(oidc.configurationName, configuration, oidc.publishEvent.bind(oidc))(extras, state, scope);
9
- };
10
-
11
- return new Promise<CheckSessionIFrame>((resolve, reject): void => {
12
- if (configuration.silent_login_uri && configuration.silent_redirect_uri && configuration.monitor_session && checkSessionIFrameUri && sessionState && !isSilentSignin) {
13
- const checkSessionCallback = () => {
14
- oidc.checkSessionIFrame.stop();
15
- const tokens = oidc.tokens;
16
- if (tokens === null) {
17
- return;
18
- }
19
- const idToken = tokens.idToken;
20
- const idTokenPayload = tokens.idTokenPayload;
21
- return silentLoginAsync({
22
- prompt: 'none',
23
- id_token_hint: idToken,
24
- scope: configuration.scope || 'openid',
25
- }).then((silentSigninResponse) => {
26
- const iFrameIdTokenPayload = silentSigninResponse.tokens.idTokenPayload;
27
- if (idTokenPayload.sub === iFrameIdTokenPayload.sub) {
28
- const sessionState = silentSigninResponse.sessionState;
29
- oidc.checkSessionIFrame.start(silentSigninResponse.sessionState);
30
- if (idTokenPayload.sid === iFrameIdTokenPayload.sid) {
31
- console.debug('SessionMonitor._callback: Same sub still logged in at OP, restarting check session iframe; session_state:', sessionState);
32
- } else {
33
- console.debug('SessionMonitor._callback: Same sub still logged in at OP, session state has changed, restarting check session iframe; session_state:', sessionState);
34
- }
35
- } else {
36
- console.debug('SessionMonitor._callback: Different subject signed into OP:', iFrameIdTokenPayload.sub);
37
- }
38
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
39
- }).catch(async (e) => {
40
- console.warn('SessionMonitor._callback: Silent login failed, logging out other tabs:', e);
41
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
42
- for (const [key, oidc] of Object.entries(oidcDatabase)) {
43
- // @ts-ignore
44
- await oidc.logoutOtherTabAsync(configuration.client_id, idTokenPayload.sub);
45
- }
46
- });
47
- };
48
-
49
- oidc.checkSessionIFrame = new CheckSessionIFrame(checkSessionCallback, clientId, checkSessionIFrameUri);
50
- oidc.checkSessionIFrame.load().then(() => {
51
- oidc.checkSessionIFrame.start(sessionState);
52
- resolve(oidc.checkSessionIFrame);
53
- }).catch((e) => {
54
- reject(e);
55
- });
56
- } else {
57
- resolve(null);
58
- }
59
- });
60
- };
@@ -1,83 +0,0 @@
1
- const DefaultInterval = 2000;
2
-
3
- const Log = console;
4
-
5
- export class CheckSessionIFrame {
6
- private readonly _client_id: any;
7
- private readonly _callback: any;
8
- private _url: any;
9
- private readonly _interval: number;
10
- private readonly _stopOnError: boolean;
11
- private readonly _frame_origin: string;
12
- private readonly _frame: HTMLIFrameElement;
13
- private _boundMessageEvent: any;
14
- private _timer: number;
15
- constructor(callback, client_id, url, interval = DefaultInterval, stopOnError = true) {
16
- this._callback = callback;
17
- this._client_id = client_id;
18
- this._url = url;
19
- this._interval = interval || DefaultInterval;
20
- this._stopOnError = stopOnError;
21
- const idx = url.indexOf('/', url.indexOf('//') + 2);
22
- this._frame_origin = url.substr(0, idx);
23
- this._frame = window.document.createElement('iframe');
24
- this._frame.style.visibility = 'hidden';
25
- this._frame.style.position = 'absolute';
26
- this._frame.style.display = 'none';
27
- // @ts-ignore
28
- this._frame.width = 0;
29
- // @ts-ignore
30
- this._frame.height = 0;
31
-
32
- this._frame.src = url;
33
- }
34
-
35
- load() {
36
- return new Promise<void>((resolve) => {
37
- this._frame.onload = () => {
38
- resolve();
39
- };
40
- window.document.body.appendChild(this._frame);
41
- this._boundMessageEvent = this._message.bind(this);
42
- window.addEventListener('message', this._boundMessageEvent, false);
43
- });
44
- }
45
-
46
- _message(e) {
47
- if (e.origin === this._frame_origin &&
48
- e.source === this._frame.contentWindow
49
- ) {
50
- if (e.data === 'error') {
51
- Log.error('CheckSessionIFrame: error message from check session op iframe');
52
- if (this._stopOnError) {
53
- this.stop();
54
- }
55
- } else if (e.data === 'changed') {
56
- Log.debug(e);
57
- Log.debug('CheckSessionIFrame: changed message from check session op iframe');
58
- this.stop();
59
- this._callback();
60
- } else {
61
- Log.debug('CheckSessionIFrame: ' + e.data + ' message from check session op iframe');
62
- }
63
- }
64
- }
65
-
66
- start(session_state) {
67
- Log.debug('CheckSessionIFrame.start :' + session_state);
68
- this.stop();
69
- const send = () => {
70
- this._frame.contentWindow.postMessage(this._client_id + ' ' + session_state, this._frame_origin);
71
- };
72
- send();
73
- this._timer = window.setInterval(send, this._interval);
74
- }
75
-
76
- stop() {
77
- if (this._timer) {
78
- Log.debug('CheckSessionIFrame.stop');
79
- window.clearInterval(this._timer);
80
- this._timer = null;
81
- }
82
- }
83
- }
@@ -1,61 +0,0 @@
1
- import * as base64 from 'base64-js';
2
-
3
- const crytoInfo = () => {
4
- const hasCrypto = typeof window !== 'undefined' && !!(window.crypto as any);
5
- const hasSubtleCrypto = hasCrypto && !!(window.crypto.subtle as any);
6
- return { hasCrypto, hasSubtleCrypto };
7
- };
8
- const charset = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
9
-
10
- const bufferToString = (buffer: Uint8Array) => {
11
- const state = [];
12
- for (let i = 0; i < buffer.byteLength; i += 1) {
13
- const index = buffer[i] % charset.length;
14
- state.push(charset[index]);
15
- }
16
- return state.join('');
17
- };
18
-
19
- const urlSafe = (buffer: Uint8Array): string => {
20
- const encoded = base64.fromByteArray(new Uint8Array(buffer));
21
- return encoded.replace(/\+/g, '-').replace(/\//g, '_').replace(/=/g, '');
22
- };
23
-
24
- export const generateRandom = (size: number) => {
25
- const buffer = new Uint8Array(size);
26
- const { hasCrypto } = crytoInfo();
27
- if (hasCrypto) {
28
- window.crypto.getRandomValues(buffer);
29
- } else {
30
- // fall back to Math.random() if nothing else is available
31
- for (let i = 0; i < size; i += 1) {
32
- buffer[i] = (Math.random() * charset.length) | 0;
33
- }
34
- }
35
- return bufferToString(buffer);
36
- };
37
-
38
- export function textEncodeLite(str: string) {
39
- const buf = new ArrayBuffer(str.length);
40
- const bufView = new Uint8Array(buf);
41
-
42
- for (let i = 0; i < str.length; i++) {
43
- bufView[i] = str.charCodeAt(i);
44
- }
45
- return bufView;
46
- }
47
- export const deriveChallengeAsync = (code: string): Promise<string> => {
48
- if (code.length < 43 || code.length > 128) {
49
- return Promise.reject(new Error('Invalid code length.'));
50
- }
51
- const { hasSubtleCrypto } = crytoInfo();
52
- if (!hasSubtleCrypto) {
53
- return Promise.reject(new Error('window.crypto.subtle is unavailable.'));
54
- }
55
-
56
- return new Promise((resolve, reject) => {
57
- crypto.subtle.digest('SHA-256', textEncodeLite(code)).then(buffer => {
58
- return resolve(urlSafe(new Uint8Array(buffer)));
59
- }, error => reject(error));
60
- });
61
- };
@@ -1,29 +0,0 @@
1
-
2
- export const eventNames = {
3
- service_worker_not_supported_by_browser: 'service_worker_not_supported_by_browser',
4
- token_aquired: 'token_aquired',
5
- logout_from_another_tab: 'logout_from_another_tab',
6
- logout_from_same_tab: 'logout_from_same_tab',
7
- token_renewed: 'token_renewed',
8
- token_timer: 'token_timer',
9
- loginAsync_begin: 'loginAsync_begin',
10
- loginAsync_error: 'loginAsync_error',
11
- loginCallbackAsync_begin: 'loginCallbackAsync_begin',
12
- loginCallbackAsync_end: 'loginCallbackAsync_end',
13
- loginCallbackAsync_error: 'loginCallbackAsync_error',
14
- refreshTokensAsync_begin: 'refreshTokensAsync_begin',
15
- refreshTokensAsync: 'refreshTokensAsync',
16
- refreshTokensAsync_end: 'refreshTokensAsync_end',
17
- refreshTokensAsync_error: 'refreshTokensAsync_error',
18
- refreshTokensAsync_silent_error: 'refreshTokensAsync_silent_error',
19
- tryKeepExistingSessionAsync_begin: 'tryKeepExistingSessionAsync_begin',
20
- tryKeepExistingSessionAsync_end: 'tryKeepExistingSessionAsync_end',
21
- tryKeepExistingSessionAsync_error: 'tryKeepExistingSessionAsync_error',
22
- silentLoginAsync_begin: 'silentLoginAsync_begin',
23
- silentLoginAsync: 'silentLoginAsync',
24
- silentLoginAsync_end: 'silentLoginAsync_end',
25
- silentLoginAsync_error: 'silentLoginAsync_error',
26
- syncTokensAsync_begin: 'syncTokensAsync_begin',
27
- syncTokensAsync_end: 'syncTokensAsync_end',
28
- syncTokensAsync_error: 'syncTokensAsync_error',
29
- };
@@ -1,2 +0,0 @@
1
- export { AuthorityConfiguration, Fetch, OidcConfiguration, StringMap } from './types.js';
2
- export { OidcUserInfo, VanillaOidc } from './vanillaOidc.js';
@@ -1,21 +0,0 @@
1
- import { excludeOs, getOperatingSystem } from './initWorker';
2
-
3
- import { describe, it, expect } from 'vitest';
4
-
5
- describe('initWorker test Suite', () => {
6
-
7
- it.each([['Mozilla/5.0 (iPhone; CPU iPhone OS 12_1 like Mac OS X) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/12.0 Mobile/15E148 Safari/604.1', 'iOS', '12.1.0'],
8
- ['Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_6) AppleWebKit/605.1.15 (KHTML, like Gecko) CriOS/69.0.3497.105 Mobile/15E148 Safari/605.1', 'Mac OS X', '10_15_6'],
9
- ])(
10
- 'getOperatingSystem should return OS for Version',
11
- (userAgent, expectedOs, expectedVersion) => {
12
- const operatingSystem = getOperatingSystem({ userAgent, appVersion: 'OS ' + expectedVersion.replaceAll('.', '_') });
13
- expect(expectedOs).toBe(operatingSystem.os);
14
- expect(expectedVersion).toBe(operatingSystem.osVersion);
15
-
16
- const isExcluded = excludeOs(operatingSystem);
17
- expect(isExcluded).toBe(true);
18
- },
19
- );
20
-
21
- });
@@ -1,90 +0,0 @@
1
-
2
- export const initSession = (configurationName, storage = sessionStorage) => {
3
- const clearAsync = (status) => {
4
- storage[`oidc.${configurationName}`] = JSON.stringify({ tokens: null, status });
5
- return Promise.resolve();
6
- };
7
-
8
- const initAsync = async () => {
9
- if (!storage[`oidc.${configurationName}`]) {
10
- storage[`oidc.${configurationName}`] = JSON.stringify({ tokens: null, status: null });
11
- return { tokens: null, status: null };
12
- }
13
- const data = JSON.parse(storage[`oidc.${configurationName}`]);
14
- return Promise.resolve({ tokens: data.tokens, status: data.status });
15
- };
16
-
17
- const setTokens = (tokens) => {
18
- storage[`oidc.${configurationName}`] = JSON.stringify({ tokens });
19
- };
20
-
21
- const setSessionStateAsync = async (sessionState) => {
22
- storage[`oidc.session_state.${configurationName}`] = sessionState;
23
- };
24
-
25
- const getSessionStateAsync = async () => {
26
- return storage[`oidc.session_state.${configurationName}`];
27
- };
28
-
29
- const setNonceAsync = (nonce) => {
30
- localStorage[`oidc.nonce.${configurationName}`] = nonce.nonce;
31
- };
32
-
33
- const getNonceAsync = async () => {
34
- // @ts-ignore
35
- return { nonce: localStorage[`oidc.nonce.${configurationName}`] };
36
- };
37
-
38
- const getTokens = () => {
39
- if (!storage[`oidc.${configurationName}`]) {
40
- return null;
41
- }
42
- return JSON.stringify({ tokens: JSON.parse(storage[`oidc.${configurationName}`]).tokens });
43
- };
44
-
45
- let getLoginParamsCache = null;
46
- const setLoginParams = (configurationName:string, data) => {
47
- getLoginParamsCache = data;
48
- storage[`oidc.login.${configurationName}`] = JSON.stringify(data);
49
- };
50
- const getLoginParams = (configurationName) => {
51
- const dataString = storage[`oidc.login.${configurationName}`];
52
- if (!getLoginParamsCache) {
53
- getLoginParamsCache = JSON.parse(dataString);
54
- }
55
- return getLoginParamsCache;
56
- };
57
-
58
- const getStateAsync = async () => {
59
- return storage[`oidc.state.${configurationName}`];
60
- };
61
-
62
- const setStateAsync = async (state:string) => {
63
- storage[`oidc.state.${configurationName}`] = state;
64
- };
65
-
66
- const getCodeVerifierAsync = async () => {
67
- return storage[`oidc.code_verifier.${configurationName}`];
68
- };
69
-
70
- const setCodeVerifierAsync = async (codeVerifier) => {
71
- storage[`oidc.code_verifier.${configurationName}`] = codeVerifier;
72
- };
73
-
74
- return {
75
- clearAsync,
76
- initAsync,
77
- setTokens,
78
- getTokens,
79
- setSessionStateAsync,
80
- getSessionStateAsync,
81
- setNonceAsync,
82
- getNonceAsync,
83
- setLoginParams,
84
- getLoginParams,
85
- getStateAsync,
86
- setStateAsync,
87
- getCodeVerifierAsync,
88
- setCodeVerifierAsync,
89
- };
90
- };