@multiplatform.one/keycloak 0.7.14 → 0.7.16

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 (155) hide show
  1. package/package.json +28 -28
  2. package/routes/index.d.ts +22 -0
  3. package/routes/index.js +22 -0
  4. package/src/Authenticated.tsx +27 -17
  5. package/src/authConfig.ts +3 -9
  6. package/src/hooks/index.ts +0 -3
  7. package/src/hooks/useTokensFromQuery/index.ts +1 -0
  8. package/src/hooks/useTokensFromState.ts +1 -1
  9. package/src/index.ts +3 -0
  10. package/src/{@types/coreJsPure.d.ts → keycloak/context.ts} +6 -11
  11. package/{lib/@types/expoKeycloakAuth.d.d.mts → src/keycloak/index.ts} +4 -7
  12. package/src/keycloak/keycloak.native.ts +148 -0
  13. package/src/keycloak/keycloak.ts +175 -0
  14. package/src/provider/AfterAuth.tsx +63 -0
  15. package/src/provider/{keycloakProvider.native.tsx → AuthProvider/AuthProvider.native.tsx} +8 -16
  16. package/src/provider/{keycloakProvider.tsx → AuthProvider/AuthProvider.tsx} +81 -94
  17. package/{lib/@types/expoKeycloakAuth.d.d.ts → src/provider/AuthProvider/index.ts} +4 -7
  18. package/src/provider/KeycloakProvider.tsx +53 -0
  19. package/src/{hooks/useCurrentRouteName/index.native.ts → provider/index.ts} +6 -11
  20. package/src/routes.ts +163 -0
  21. package/src/session/index.ts +22 -0
  22. package/src/session/session.native.ts +31 -0
  23. package/src/session/session.ts +68 -0
  24. package/src/{state/index.ts → state.ts} +5 -4
  25. package/src/{util.ts → token.ts} +25 -11
  26. package/src/types.ts +4 -1
  27. package/lib/@types/coreJsPure.d.d.mts +0 -2
  28. package/lib/@types/coreJsPure.d.d.ts +0 -2
  29. package/lib/@types/coreJsPure.d.js +0 -1
  30. package/lib/@types/coreJsPure.d.mjs +0 -0
  31. package/lib/@types/expoKeycloakAuth.d.js +0 -1
  32. package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
  33. package/lib/Authenticated.d.mts +0 -33
  34. package/lib/Authenticated.d.ts +0 -33
  35. package/lib/Authenticated.js +0 -19
  36. package/lib/Authenticated.mjs +0 -20
  37. package/lib/authConfig.d.mts +0 -14
  38. package/lib/authConfig.d.ts +0 -14
  39. package/lib/authConfig.js +0 -8
  40. package/lib/authConfig.mjs +0 -9
  41. package/lib/chunk-2GUOEPFY.mjs +0 -0
  42. package/lib/chunk-3ZPHNEJL.js +0 -11
  43. package/lib/chunk-64PPU7Q3.mjs +0 -13
  44. package/lib/chunk-6NDWOV55.js +0 -1
  45. package/lib/chunk-7MTPH6XK.mjs +0 -26
  46. package/lib/chunk-A7UBOIAL.js +0 -13
  47. package/lib/chunk-AD6VPMID.mjs +0 -20
  48. package/lib/chunk-AUUZ6BI7.js +0 -78
  49. package/lib/chunk-AYKQVWMR.mjs +0 -0
  50. package/lib/chunk-BVB33X7V.mjs +0 -265
  51. package/lib/chunk-C2FNSVJO.js +0 -17
  52. package/lib/chunk-J4CCMILN.mjs +0 -41
  53. package/lib/chunk-K33RKJZX.js +0 -443
  54. package/lib/chunk-KLLABHIC.js +0 -13
  55. package/lib/chunk-L5HMOY4M.mjs +0 -18
  56. package/lib/chunk-MZ6E62HK.js +0 -33
  57. package/lib/chunk-NWRANDZ6.js +0 -98
  58. package/lib/chunk-NXTVYIBR.mjs +0 -11
  59. package/lib/chunk-OYWAYMFN.js +0 -17
  60. package/lib/chunk-RPUOO7AV.mjs +0 -10
  61. package/lib/chunk-RYM7KERK.mjs +0 -52
  62. package/lib/chunk-UBVYEZI3.js +0 -1
  63. package/lib/chunk-UHTKOFS6.mjs +0 -84
  64. package/lib/chunk-UL6L5ONI.js +0 -460
  65. package/lib/chunk-UOKDJT5L.mjs +0 -16
  66. package/lib/chunk-W5DJLFTQ.js +0 -56
  67. package/lib/chunk-WT5W6BSZ.js +0 -161
  68. package/lib/chunk-XEO3YXBM.js +0 -22
  69. package/lib/chunk-XO4W2SMN.mjs +0 -50
  70. package/lib/chunk-XVPWAAZ4.mjs +0 -76
  71. package/lib/chunk-Y4XMF3R6.mjs +0 -13
  72. package/lib/chunk-YGNNHTFE.js +0 -12
  73. package/lib/hooks/index.d.mts +0 -9
  74. package/lib/hooks/index.d.ts +0 -9
  75. package/lib/hooks/index.js +0 -23
  76. package/lib/hooks/index.mjs +0 -34
  77. package/lib/hooks/useAuthConfig.d.mts +0 -6
  78. package/lib/hooks/useAuthConfig.d.ts +0 -6
  79. package/lib/hooks/useAuthConfig.js +0 -8
  80. package/lib/hooks/useAuthConfig.mjs +0 -8
  81. package/lib/hooks/useCurrentRouteName/index.d.mts +0 -3
  82. package/lib/hooks/useCurrentRouteName/index.d.ts +0 -3
  83. package/lib/hooks/useCurrentRouteName/index.js +0 -7
  84. package/lib/hooks/useCurrentRouteName/index.mjs +0 -7
  85. package/lib/hooks/useCurrentRouteName/index.native.d.mts +0 -3
  86. package/lib/hooks/useCurrentRouteName/index.native.d.ts +0 -3
  87. package/lib/hooks/useCurrentRouteName/index.native.js +0 -14
  88. package/lib/hooks/useCurrentRouteName/index.native.mjs +0 -14
  89. package/lib/hooks/useKeycloak/index.d.mts +0 -46
  90. package/lib/hooks/useKeycloak/index.d.ts +0 -46
  91. package/lib/hooks/useKeycloak/index.js +0 -11
  92. package/lib/hooks/useKeycloak/index.mjs +0 -12
  93. package/lib/hooks/useKeycloak/useKeycloak.d.mts +0 -2
  94. package/lib/hooks/useKeycloak/useKeycloak.d.ts +0 -2
  95. package/lib/hooks/useKeycloak/useKeycloak.js +0 -10
  96. package/lib/hooks/useKeycloak/useKeycloak.mjs +0 -11
  97. package/lib/hooks/useKeycloak/useKeycloak.native.d.mts +0 -20
  98. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +0 -20
  99. package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -80
  100. package/lib/hooks/useKeycloak/useKeycloak.native.mjs +0 -69
  101. package/lib/hooks/useLogin.d.mts +0 -3
  102. package/lib/hooks/useLogin.d.ts +0 -3
  103. package/lib/hooks/useLogin.js +0 -11
  104. package/lib/hooks/useLogin.mjs +0 -11
  105. package/lib/hooks/useTokensFromQuery/index.d.mts +0 -3
  106. package/lib/hooks/useTokensFromQuery/index.d.ts +0 -3
  107. package/lib/hooks/useTokensFromQuery/index.js +0 -7
  108. package/lib/hooks/useTokensFromQuery/index.mjs +0 -7
  109. package/lib/hooks/useTokensFromQuery/index.native.d.mts +0 -3
  110. package/lib/hooks/useTokensFromQuery/index.native.d.ts +0 -3
  111. package/lib/hooks/useTokensFromQuery/index.native.js +0 -10
  112. package/lib/hooks/useTokensFromQuery/index.native.mjs +0 -7
  113. package/lib/hooks/useTokensFromState.d.mts +0 -3
  114. package/lib/hooks/useTokensFromState.d.ts +0 -3
  115. package/lib/hooks/useTokensFromState.js +0 -9
  116. package/lib/hooks/useTokensFromState.mjs +0 -9
  117. package/lib/index.d.mts +0 -13
  118. package/lib/index.d.ts +0 -13
  119. package/lib/index.js +0 -34
  120. package/lib/index.mjs +0 -56
  121. package/lib/provider/afterAuth.d.mts +0 -29
  122. package/lib/provider/afterAuth.d.ts +0 -29
  123. package/lib/provider/afterAuth.js +0 -18
  124. package/lib/provider/afterAuth.mjs +0 -18
  125. package/lib/provider/index.d.mts +0 -39
  126. package/lib/provider/index.d.ts +0 -39
  127. package/lib/provider/index.js +0 -22
  128. package/lib/provider/index.mjs +0 -25
  129. package/lib/provider/keycloakProvider.d.mts +0 -42
  130. package/lib/provider/keycloakProvider.d.ts +0 -42
  131. package/lib/provider/keycloakProvider.js +0 -20
  132. package/lib/provider/keycloakProvider.mjs +0 -21
  133. package/lib/provider/keycloakProvider.native.d.mts +0 -29
  134. package/lib/provider/keycloakProvider.native.d.ts +0 -29
  135. package/lib/provider/keycloakProvider.native.js +0 -87
  136. package/lib/provider/keycloakProvider.native.mjs +0 -30
  137. package/lib/state/index.d.mts +0 -11
  138. package/lib/state/index.d.ts +0 -11
  139. package/lib/state/index.js +0 -7
  140. package/lib/state/index.mjs +0 -7
  141. package/lib/types.d.mts +0 -17
  142. package/lib/types.d.ts +0 -17
  143. package/lib/types.js +0 -8
  144. package/lib/types.mjs +0 -7
  145. package/lib/util.d.mts +0 -4
  146. package/lib/util.d.ts +0 -4
  147. package/lib/util.js +0 -8
  148. package/lib/util.mjs +0 -9
  149. package/src/hooks/useCurrentRouteName/index.ts +0 -34
  150. package/src/hooks/useKeycloak/index.ts +0 -47
  151. package/src/hooks/useKeycloak/useKeycloak.native.ts +0 -95
  152. package/src/hooks/useKeycloak/useKeycloak.ts +0 -106
  153. package/src/hooks/useLogin.ts +0 -47
  154. package/src/provider/afterAuth.tsx +0 -65
  155. package/src/provider/index.tsx +0 -117
@@ -0,0 +1,68 @@
1
+ /*
2
+ * File: /src/session.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 10-01-2024 02:31:26
5
+ * Author: Clay Risser
6
+ * -----
7
+ * BitSpur (c) Copyright 2021 - 2024
8
+ *
9
+ * Licensed under the Apache License, Version 2.0 (the "License");
10
+ * you may not use this file except in compliance with the License.
11
+ * You may obtain a copy of the License at
12
+ *
13
+ * http://www.apache.org/licenses/LICENSE-2.0
14
+ *
15
+ * Unless required by applicable law or agreed to in writing, software
16
+ * distributed under the License is distributed on an "AS IS" BASIS,
17
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18
+ * See the License for the specific language governing permissions and
19
+ * limitations under the License.
20
+ */
21
+
22
+ import type { Session as NextSession } from 'next-auth';
23
+ import type { SessionContextValue as NextSessionContextValue, UseSessionOptions } from 'next-auth/react';
24
+ import { MultiPlatform } from 'multiplatform.one';
25
+ import { useSession as useNextSession, getSession as getNextSession } from 'next-auth/react';
26
+
27
+ let _getServerSession: (() => Promise<Session | null>) | undefined;
28
+
29
+ export async function getSession(): Promise<Session | null> {
30
+ if (MultiPlatform.isServer) {
31
+ if (typeof _getServerSession === 'function') return _getServerSession();
32
+ const getSession = (await import('next-auth')).getServerSession;
33
+ _getServerSession = () => getSession();
34
+ return _getServerSession();
35
+ }
36
+ return getNextSession();
37
+ }
38
+
39
+ export type SessionContextValue<R extends boolean> = Partial<
40
+ Omit<NextSessionContextValue<R> & { session: Session }, 'data'>
41
+ >;
42
+
43
+ let useSession = <R extends boolean>(
44
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
45
+ options?: UseSessionOptions<R>,
46
+ ): SessionContextValue<R> => {
47
+ return {};
48
+ };
49
+
50
+ if (MultiPlatform.isNext) {
51
+ useSession = <R extends boolean>(options?: UseSessionOptions<R>): SessionContextValue<R> => {
52
+ const nextSession = useNextSession(options);
53
+ return {
54
+ update: nextSession.update,
55
+ status: nextSession.status,
56
+ session: nextSession.data as Session,
57
+ } as SessionContextValue<R>;
58
+ };
59
+ }
60
+
61
+ export interface Session extends NextSession {
62
+ accessToken?: string;
63
+ err?: Error;
64
+ idToken?: string;
65
+ refreshToken?: string;
66
+ }
67
+
68
+ export { useSession };
@@ -1,5 +1,5 @@
1
1
  /*
2
- * File: /src/state/index.ts
2
+ * File: /src/state.ts
3
3
  * Project: @multiplatform.one/keycloak
4
4
  * File Created: 22-06-2023 10:07:56
5
5
  * Author: Clay Risser
@@ -20,8 +20,9 @@
20
20
  */
21
21
 
22
22
  import { createStateStore } from 'multiplatform.one/zustand';
23
- // @ts-ignore
24
- import { config } from 'app/config';
23
+ import { MultiPlatform } from 'multiplatform.one';
24
+
25
+ export const persist = MultiPlatform.isIframe || (!MultiPlatform.isNext && !MultiPlatform.isServer);
25
26
 
26
27
  const { useStore } = createStateStore(
27
28
  'auth',
@@ -31,7 +32,7 @@ const { useStore } = createStateStore(
31
32
  token: '',
32
33
  },
33
34
  undefined,
34
- { persist: config.get('KEYCLOAK_PERSIST') === '1' },
35
+ { persist },
35
36
  );
36
37
 
37
38
  export function useAuthState() {
@@ -1,10 +1,10 @@
1
1
  /*
2
- * File: /src/util.ts
2
+ * File: /src/token.ts
3
3
  * Project: @multiplatform.one/keycloak
4
- * File Created: 22-06-2023 10:07:56
4
+ * File Created: 10-01-2024 16:19:33
5
5
  * Author: Clay Risser
6
6
  * -----
7
- * BitSpur (c) Copyright 2021 - 2023
7
+ * BitSpur (c) Copyright 2021 - 2024
8
8
  *
9
9
  * Licensed under the Apache License, Version 2.0 (the "License");
10
10
  * you may not use this file except in compliance with the License.
@@ -19,7 +19,12 @@
19
19
  * limitations under the License.
20
20
  */
21
21
 
22
- export function validToken(token: string | boolean, refreshToken?: string | boolean) {
22
+ import type { KeycloakTokenParsed } from 'keycloak-js';
23
+ import { jwtDecode } from 'jwt-decode';
24
+
25
+ export function validToken(token?: string | boolean, refreshToken?: string | boolean) {
26
+ if (typeof token === 'undefined') return;
27
+ if (!token) return false;
23
28
  if (typeof token !== 'string') return token;
24
29
  if (refreshToken) {
25
30
  if (refreshToken === true || isTokenValid(refreshToken)) return token;
@@ -29,11 +34,20 @@ export function validToken(token: string | boolean, refreshToken?: string | bool
29
34
  }
30
35
 
31
36
  export function isTokenValid(token: string) {
32
- try {
33
- const { exp } = JSON.parse(Buffer.from(token.split('.')?.[1] || '', 'base64').toString() || '{}');
34
- return Math.floor(Date.now() / 1000) <= exp;
35
- } catch (err) {
36
- if (err instanceof SyntaxError) return false;
37
- throw err;
38
- }
37
+ const { exp } = jwtDecode(token) as TokenParsed;
38
+ if (!exp) return false;
39
+ return Math.floor(Date.now() / 1000) <= exp;
40
+ }
41
+
42
+ export interface TokenParsed extends KeycloakTokenParsed {
43
+ jti?: string;
44
+ sid?: string;
45
+ typ?: 'Bearer' | string;
46
+ }
47
+
48
+ export interface AccessTokenParsed extends TokenParsed {
49
+ email?: string;
50
+ email_verified?: boolean;
51
+ preferred_username?: string;
52
+ scope?: string;
39
53
  }
package/src/types.ts CHANGED
@@ -34,4 +34,7 @@ declare global {
34
34
  }
35
35
  }
36
36
 
37
- export default null;
37
+ export interface KeycloakMock {
38
+ email?: string;
39
+ username: string;
40
+ }
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1,2 +0,0 @@
1
-
2
- export { }
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1,33 +0,0 @@
1
- import React__default, { ReactNode, ComponentType } from 'react';
2
-
3
- /**
4
- * File: /src/Authenticated.tsx
5
- * Project: @multiplatform.one/keycloak
6
- * File Created: 22-06-2023 10:07:56
7
- * Author: Clay Risser
8
- * -----
9
- * BitSpur (c) Copyright 2021 - 2023
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- interface AuthenticatedProps {
25
- children: ReactNode;
26
- disabled?: boolean;
27
- loggedOutComponent?: ComponentType;
28
- loginRoute?: string;
29
- }
30
- declare function Authenticated({ children, disabled, loginRoute, loggedOutComponent }: AuthenticatedProps): React__default.JSX.Element;
31
- declare function withAuthenticated<P extends object>(Component: ComponentType<P>): (props: P) => React__default.JSX.Element;
32
-
33
- export { Authenticated, type AuthenticatedProps, withAuthenticated };
@@ -1,33 +0,0 @@
1
- import React__default, { ReactNode, ComponentType } from 'react';
2
-
3
- /**
4
- * File: /src/Authenticated.tsx
5
- * Project: @multiplatform.one/keycloak
6
- * File Created: 22-06-2023 10:07:56
7
- * Author: Clay Risser
8
- * -----
9
- * BitSpur (c) Copyright 2021 - 2023
10
- *
11
- * Licensed under the Apache License, Version 2.0 (the "License");
12
- * you may not use this file except in compliance with the License.
13
- * You may obtain a copy of the License at
14
- *
15
- * http://www.apache.org/licenses/LICENSE-2.0
16
- *
17
- * Unless required by applicable law or agreed to in writing, software
18
- * distributed under the License is distributed on an "AS IS" BASIS,
19
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20
- * See the License for the specific language governing permissions and
21
- * limitations under the License.
22
- */
23
-
24
- interface AuthenticatedProps {
25
- children: ReactNode;
26
- disabled?: boolean;
27
- loggedOutComponent?: ComponentType;
28
- loginRoute?: string;
29
- }
30
- declare function Authenticated({ children, disabled, loginRoute, loggedOutComponent }: AuthenticatedProps): React__default.JSX.Element;
31
- declare function withAuthenticated<P extends object>(Component: ComponentType<P>): (props: P) => React__default.JSX.Element;
32
-
33
- export { Authenticated, type AuthenticatedProps, withAuthenticated };
@@ -1,19 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- var _chunkAUUZ6BI7js = require("./chunk-AUUZ6BI7.js");
6
- require("./chunk-UBVYEZI3.js");
7
- require("./chunk-6NDWOV55.js");
8
- require("./chunk-KLLABHIC.js");
9
- require("./chunk-MZ6E62HK.js");
10
- require("./chunk-OYWAYMFN.js");
11
- require("./chunk-UL6L5ONI.js");
12
- require("./chunk-3ZPHNEJL.js");
13
- require("./chunk-YGNNHTFE.js");
14
- require("./chunk-C2FNSVJO.js");
15
- require("./chunk-A7UBOIAL.js");
16
- require("./chunk-NWRANDZ6.js");
17
- require("./chunk-XEO3YXBM.js");
18
- exports.Authenticated = _chunkAUUZ6BI7js.Authenticated;
19
- exports.withAuthenticated = _chunkAUUZ6BI7js.withAuthenticated;
@@ -1,20 +0,0 @@
1
- import {
2
- Authenticated,
3
- withAuthenticated
4
- } from "./chunk-RYM7KERK.mjs";
5
- import "./chunk-AYKQVWMR.mjs";
6
- import "./chunk-2GUOEPFY.mjs";
7
- import "./chunk-NXTVYIBR.mjs";
8
- import "./chunk-J4CCMILN.mjs";
9
- import "./chunk-L5HMOY4M.mjs";
10
- import "./chunk-UHTKOFS6.mjs";
11
- import "./chunk-Y4XMF3R6.mjs";
12
- import "./chunk-UOKDJT5L.mjs";
13
- import "./chunk-AD6VPMID.mjs";
14
- import "./chunk-64PPU7Q3.mjs";
15
- import "./chunk-7MTPH6XK.mjs";
16
- import "./chunk-RPUOO7AV.mjs";
17
- export {
18
- Authenticated,
19
- withAuthenticated
20
- };
@@ -1,14 +0,0 @@
1
- import * as React from 'react';
2
-
3
- declare const defaultAuthConfig: AuthConfig;
4
- declare const AuthConfigContext: React.Context<AuthConfig>;
5
- interface AuthConfig {
6
- debug?: boolean;
7
- ensureFreshness?: boolean;
8
- loginRoute?: string;
9
- messageHandlerKeys?: string[];
10
- persist?: boolean;
11
- ssr?: boolean;
12
- }
13
-
14
- export { type AuthConfig, AuthConfigContext, defaultAuthConfig };
@@ -1,14 +0,0 @@
1
- import * as React from 'react';
2
-
3
- declare const defaultAuthConfig: AuthConfig;
4
- declare const AuthConfigContext: React.Context<AuthConfig>;
5
- interface AuthConfig {
6
- debug?: boolean;
7
- ensureFreshness?: boolean;
8
- loginRoute?: string;
9
- messageHandlerKeys?: string[];
10
- persist?: boolean;
11
- ssr?: boolean;
12
- }
13
-
14
- export { type AuthConfig, AuthConfigContext, defaultAuthConfig };
package/lib/authConfig.js DELETED
@@ -1,8 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- var _chunkA7UBOIALjs = require("./chunk-A7UBOIAL.js");
6
- require("./chunk-XEO3YXBM.js");
7
- exports.AuthConfigContext = _chunkA7UBOIALjs.AuthConfigContext;
8
- exports.defaultAuthConfig = _chunkA7UBOIALjs.defaultAuthConfig;
@@ -1,9 +0,0 @@
1
- import {
2
- AuthConfigContext,
3
- defaultAuthConfig
4
- } from "./chunk-64PPU7Q3.mjs";
5
- import "./chunk-RPUOO7AV.mjs";
6
- export {
7
- AuthConfigContext,
8
- defaultAuthConfig
9
- };
File without changes
@@ -1,11 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- var _chunkA7UBOIALjs = require("./chunk-A7UBOIAL.js");
6
- // src/hooks/useAuthConfig.ts
7
- var _react = require("react");
8
- function useAuthConfig() {
9
- return _react.useContext.call(void 0, _chunkA7UBOIALjs.AuthConfigContext);
10
- }
11
- exports.useAuthConfig = useAuthConfig;
@@ -1,13 +0,0 @@
1
- // src/authConfig.ts
2
- import { createContext } from "react";
3
- var defaultAuthConfig = {
4
- ensureFreshness: true,
5
- persist: false,
6
- ssr: false
7
- };
8
- var AuthConfigContext = createContext(defaultAuthConfig);
9
-
10
- export {
11
- defaultAuthConfig,
12
- AuthConfigContext
13
- };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,26 +0,0 @@
1
- // src/util.ts
2
- function validToken(token, refreshToken) {
3
- if (typeof token !== "string")
4
- return token;
5
- if (refreshToken) {
6
- if (refreshToken === true || isTokenValid(refreshToken))
7
- return token;
8
- return false;
9
- }
10
- return isTokenValid(token) ? token : false;
11
- }
12
- function isTokenValid(token) {
13
- try {
14
- const { exp } = JSON.parse(Buffer.from(token.split(".")?.[1] || "", "base64").toString() || "{}");
15
- return Math.floor(Date.now() / 1e3) <= exp;
16
- } catch (err) {
17
- if (err instanceof SyntaxError)
18
- return false;
19
- throw err;
20
- }
21
- }
22
-
23
- export {
24
- validToken,
25
- isTokenValid
26
- };
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- }); // src/authConfig.ts
5
- var _react = require("react");
6
- var defaultAuthConfig = {
7
- ensureFreshness: true,
8
- persist: false,
9
- ssr: false
10
- };
11
- var AuthConfigContext = _react.createContext.call(void 0, defaultAuthConfig);
12
- exports.defaultAuthConfig = defaultAuthConfig;
13
- exports.AuthConfigContext = AuthConfigContext;
@@ -1,20 +0,0 @@
1
- // src/state/index.ts
2
- import { createStateStore } from "multiplatform.one/zustand";
3
- import { config } from "app/config";
4
- var { useStore } = createStateStore(
5
- "auth",
6
- {
7
- idToken: "",
8
- refreshToken: "",
9
- token: ""
10
- },
11
- void 0,
12
- { persist: config.get("KEYCLOAK_PERSIST") === "1" }
13
- );
14
- function useAuthState() {
15
- return useStore();
16
- }
17
-
18
- export {
19
- useAuthState
20
- };
@@ -1,78 +0,0 @@
1
- "use strict";
2
- function _define_property(obj, key, value) {
3
- if (key in obj) {
4
- Object.defineProperty(obj, key, {
5
- value: value,
6
- enumerable: true,
7
- configurable: true,
8
- writable: true
9
- });
10
- } else {
11
- obj[key] = value;
12
- }
13
- return obj;
14
- }
15
- function _object_spread(target) {
16
- for(var i = 1; i < arguments.length; i++){
17
- var source = arguments[i] != null ? arguments[i] : {};
18
- var ownKeys = Object.keys(source);
19
- if (typeof Object.getOwnPropertySymbols === "function") {
20
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
21
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
22
- }));
23
- }
24
- ownKeys.forEach(function(key) {
25
- _define_property(target, key, source[key]);
26
- });
27
- }
28
- return target;
29
- }
30
- Object.defineProperty(exports, "__esModule", {
31
- value: true
32
- });
33
- function _interopRequireDefault(obj) {
34
- return obj && obj.__esModule ? obj : {
35
- default: obj
36
- };
37
- }
38
- var _chunkKLLABHICjs = require("./chunk-KLLABHIC.js");
39
- var _chunkMZ6E62HKjs = require("./chunk-MZ6E62HK.js");
40
- var _chunkUL6L5ONIjs = require("./chunk-UL6L5ONI.js");
41
- var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
42
- var _chunkYGNNHTFEjs = require("./chunk-YGNNHTFE.js");
43
- var _chunkC2FNSVJOjs = require("./chunk-C2FNSVJO.js");
44
- // src/Authenticated.tsx
45
- var _react = require("react");
46
- var _react2 = _interopRequireDefault(_react);
47
- function Authenticated(param) {
48
- var children = param.children, disabled = param.disabled, loginRoute = param.loginRoute, loggedOutComponent = param.loggedOutComponent;
49
- var authConfig = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0);
50
- var authState = _chunkC2FNSVJOjs.useAuthState.call(void 0);
51
- var login = _chunkMZ6E62HKjs.useLogin.call(void 0, loginRoute);
52
- var tokensFromQuery = _chunkKLLABHICjs.useTokensFromQuery.call(void 0);
53
- var tokensFromState = _chunkYGNNHTFEjs.useTokensFromState.call(void 0);
54
- var authenticated = _chunkUL6L5ONIjs.useKeycloak.call(void 0).authenticated;
55
- _react.useEffect.call(void 0, function() {
56
- if (authenticated !== false) return;
57
- if (authConfig.persist) {
58
- authState.setIdToken("");
59
- authState.setRefreshToken("");
60
- authState.setToken("");
61
- }
62
- if (typeof window !== "undefined" && !tokensFromQuery && !tokensFromState && window.self === window.top) login();
63
- }, [
64
- authenticated
65
- ]);
66
- if (disabled || authenticated) return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
67
- var LoggedOutComponent = loggedOutComponent || function() {
68
- return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, authConfig.debug ? "not authenticated" : null);
69
- };
70
- return /* @__PURE__ */ _react2.default.createElement(LoggedOutComponent, null);
71
- }
72
- function withAuthenticated(Component) {
73
- return function(props) {
74
- return /* @__PURE__ */ _react2.default.createElement(Authenticated, null, /* @__PURE__ */ _react2.default.createElement(Component, _object_spread({}, props)));
75
- };
76
- }
77
- exports.Authenticated = Authenticated;
78
- exports.withAuthenticated = withAuthenticated;
File without changes