@multiplatform.one/keycloak 0.7.1 → 0.7.2

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 (101) hide show
  1. package/lib/@types/coreJsPure.d.d.ts +2 -0
  2. package/lib/@types/coreJsPure.d.js +1 -0
  3. package/lib/@types/coreJsPure.d.mjs +0 -0
  4. package/lib/@types/expoKeycloakAuth.d.d.ts +28 -0
  5. package/lib/@types/expoKeycloakAuth.d.js +1 -0
  6. package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
  7. package/lib/Authenticated.d.ts +36 -0
  8. package/lib/Authenticated.js +19 -0
  9. package/lib/Authenticated.mjs +20 -0
  10. package/lib/authConfig.d.ts +37 -0
  11. package/lib/authConfig.js +8 -0
  12. package/lib/authConfig.mjs +9 -0
  13. package/lib/chunk-2GUOEPFY.mjs +0 -0
  14. package/lib/chunk-3ZPHNEJL.js +11 -0
  15. package/lib/chunk-64PPU7Q3.mjs +13 -0
  16. package/lib/chunk-6NDWOV55.js +1 -0
  17. package/lib/chunk-6QZDLO3M.mjs +41 -0
  18. package/lib/chunk-73FF4BX7.js +78 -0
  19. package/lib/chunk-7MTPH6XK.mjs +26 -0
  20. package/lib/chunk-A7UBOIAL.js +13 -0
  21. package/lib/chunk-AD6VPMID.mjs +20 -0
  22. package/lib/chunk-AYKQVWMR.mjs +0 -0
  23. package/lib/chunk-BTHRDOLL.mjs +84 -0
  24. package/lib/chunk-C2FNSVJO.js +17 -0
  25. package/lib/chunk-CLO6HIJN.mjs +52 -0
  26. package/lib/chunk-DJW5IKQS.mjs +265 -0
  27. package/lib/chunk-JLIMB5OD.js +56 -0
  28. package/lib/chunk-JYEIPNPN.mjs +76 -0
  29. package/lib/chunk-K2MQYDVB.mjs +50 -0
  30. package/lib/chunk-KLLABHIC.js +13 -0
  31. package/lib/chunk-L5HMOY4M.mjs +18 -0
  32. package/lib/chunk-NHABU752.mjs +10 -0
  33. package/lib/chunk-NRD376XV.js +33 -0
  34. package/lib/chunk-NWRANDZ6.js +98 -0
  35. package/lib/chunk-NXTVYIBR.mjs +11 -0
  36. package/lib/chunk-OYWAYMFN.js +17 -0
  37. package/lib/chunk-QFP2JWHZ.js +443 -0
  38. package/lib/chunk-RTZ3CZKS.js +161 -0
  39. package/lib/chunk-S3M2DZ6G.js +460 -0
  40. package/lib/chunk-UBVYEZI3.js +1 -0
  41. package/lib/chunk-UOKDJT5L.mjs +16 -0
  42. package/lib/chunk-XXPGZHWZ.js +22 -0
  43. package/lib/chunk-Y4XMF3R6.mjs +13 -0
  44. package/lib/chunk-YGNNHTFE.js +12 -0
  45. package/lib/hooks/index.d.ts +9 -0
  46. package/lib/hooks/index.js +23 -0
  47. package/lib/hooks/index.mjs +34 -0
  48. package/lib/hooks/useAuthConfig.d.ts +29 -0
  49. package/lib/hooks/useAuthConfig.js +8 -0
  50. package/lib/hooks/useAuthConfig.mjs +8 -0
  51. package/lib/hooks/useCurrentRouteName/index.d.ts +26 -0
  52. package/lib/hooks/useCurrentRouteName/index.js +7 -0
  53. package/lib/hooks/useCurrentRouteName/index.mjs +7 -0
  54. package/lib/hooks/useCurrentRouteName/index.native.d.ts +26 -0
  55. package/lib/hooks/useCurrentRouteName/index.native.js +14 -0
  56. package/lib/hooks/useCurrentRouteName/index.native.mjs +14 -0
  57. package/lib/hooks/useKeycloak/index.d.ts +70 -0
  58. package/lib/hooks/useKeycloak/index.js +11 -0
  59. package/lib/hooks/useKeycloak/index.mjs +12 -0
  60. package/lib/hooks/useKeycloak/useKeycloak.d.ts +2 -0
  61. package/lib/hooks/useKeycloak/useKeycloak.js +10 -0
  62. package/lib/hooks/useKeycloak/useKeycloak.mjs +11 -0
  63. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +44 -0
  64. package/lib/hooks/useKeycloak/useKeycloak.native.js +80 -0
  65. package/lib/hooks/useKeycloak/useKeycloak.native.mjs +69 -0
  66. package/lib/hooks/useLogin.d.ts +26 -0
  67. package/lib/hooks/useLogin.js +11 -0
  68. package/lib/hooks/useLogin.mjs +11 -0
  69. package/lib/hooks/useTokensFromQuery/index.d.ts +26 -0
  70. package/lib/hooks/useTokensFromQuery/index.js +7 -0
  71. package/lib/hooks/useTokensFromQuery/index.mjs +7 -0
  72. package/lib/hooks/useTokensFromQuery/index.native.d.ts +26 -0
  73. package/lib/hooks/useTokensFromQuery/index.native.js +10 -0
  74. package/lib/hooks/useTokensFromQuery/index.native.mjs +7 -0
  75. package/lib/hooks/useTokensFromState.d.ts +26 -0
  76. package/lib/hooks/useTokensFromState.js +9 -0
  77. package/lib/hooks/useTokensFromState.mjs +9 -0
  78. package/lib/index.d.ts +13 -0
  79. package/lib/index.mjs +56 -0
  80. package/lib/provider/afterAuth.d.ts +32 -0
  81. package/lib/provider/afterAuth.js +18 -0
  82. package/lib/provider/afterAuth.mjs +18 -0
  83. package/lib/provider/index.d.ts +42 -0
  84. package/lib/provider/index.js +22 -0
  85. package/lib/provider/index.mjs +25 -0
  86. package/lib/provider/keycloakProvider.d.ts +45 -0
  87. package/lib/provider/keycloakProvider.js +20 -0
  88. package/lib/provider/keycloakProvider.mjs +21 -0
  89. package/lib/provider/keycloakProvider.native.d.ts +32 -0
  90. package/lib/provider/keycloakProvider.native.js +87 -0
  91. package/lib/provider/keycloakProvider.native.mjs +30 -0
  92. package/lib/state/index.d.ts +34 -0
  93. package/lib/state/index.js +7 -0
  94. package/lib/state/index.mjs +7 -0
  95. package/lib/types.d.ts +40 -0
  96. package/lib/types.js +8 -0
  97. package/lib/types.mjs +7 -0
  98. package/lib/util.d.ts +27 -0
  99. package/lib/util.js +8 -0
  100. package/lib/util.mjs +9 -0
  101. package/package.json +6 -6
@@ -0,0 +1,2 @@
1
+
2
+ export { }
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1,28 @@
1
+ /**
2
+ * File: /src/@types/expoKeycloakAuth.d.ts
3
+ * Project: @multiplatform.one/keycloak
4
+ * File Created: 28-11-2022 14:56:57
5
+ * Author: Clay Risser
6
+ * -----
7
+ * Last Modified: 28-11-2022 14:57:43
8
+ * Modified By: Clay Risser
9
+ * -----
10
+ * Risser Labs LLC (c) Copyright 2022
11
+ *
12
+ * Licensed under the Apache License, Version 2.0 (the "License");
13
+ * you may not use this file except in compliance with the License.
14
+ * You may obtain a copy of the License at
15
+ *
16
+ * http://www.apache.org/licenses/LICENSE-2.0
17
+ *
18
+ * Unless required by applicable law or agreed to in writing, software
19
+ * distributed under the License is distributed on an "AS IS" BASIS,
20
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
21
+ * See the License for the specific language governing permissions and
22
+ * limitations under the License.
23
+ */
24
+
25
+ declare module 'expo-keycloak-auth' {
26
+ export function useKeycloak(): any;
27
+ export const KeycloakProvider: any;
28
+ }
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -0,0 +1,36 @@
1
+ import React__default, { ReactNode, ComponentType } from 'react';
2
+
3
+ /**
4
+ * File: /auth/Authenticated.tsx
5
+ * Project: app
6
+ * File Created: 08-11-2022 05:58:23
7
+ * Author: Clay Risser
8
+ * -----
9
+ * Last Modified: 22-11-2022 06:26:38
10
+ * Modified By: Clay Risser
11
+ * -----
12
+ * Risser Labs LLC (c) Copyright 2021 - 2022
13
+ *
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+
27
+ interface AuthenticatedProps {
28
+ children: ReactNode;
29
+ disabled?: boolean;
30
+ loggedOutComponent?: ComponentType;
31
+ loginRoute?: string;
32
+ }
33
+ declare function Authenticated({ children, disabled, loginRoute, loggedOutComponent }: AuthenticatedProps): React__default.JSX.Element;
34
+ declare function withAuthenticated<P extends object>(Component: ComponentType<P>): (props: P) => React__default.JSX.Element;
35
+
36
+ export { Authenticated, AuthenticatedProps, withAuthenticated };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _chunk73FF4BX7js = require("./chunk-73FF4BX7.js");
6
+ require("./chunk-UBVYEZI3.js");
7
+ require("./chunk-6NDWOV55.js");
8
+ require("./chunk-KLLABHIC.js");
9
+ require("./chunk-NRD376XV.js");
10
+ require("./chunk-OYWAYMFN.js");
11
+ require("./chunk-S3M2DZ6G.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-XXPGZHWZ.js");
18
+ exports.Authenticated = _chunk73FF4BX7js.Authenticated;
19
+ exports.withAuthenticated = _chunk73FF4BX7js.withAuthenticated;
@@ -0,0 +1,20 @@
1
+ import {
2
+ Authenticated,
3
+ withAuthenticated
4
+ } from "./chunk-CLO6HIJN.mjs";
5
+ import "./chunk-AYKQVWMR.mjs";
6
+ import "./chunk-2GUOEPFY.mjs";
7
+ import "./chunk-NXTVYIBR.mjs";
8
+ import "./chunk-6QZDLO3M.mjs";
9
+ import "./chunk-L5HMOY4M.mjs";
10
+ import "./chunk-BTHRDOLL.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-NHABU752.mjs";
17
+ export {
18
+ Authenticated,
19
+ withAuthenticated
20
+ };
@@ -0,0 +1,37 @@
1
+ import * as React from 'react';
2
+
3
+ /**
4
+ * File: /src/authConfig.ts
5
+ * Project: app
6
+ * File Created: 08-11-2022 09:21:15
7
+ * Author: Clay Risser
8
+ * -----
9
+ * Last Modified: 26-05-2023 08:07:00
10
+ * Modified By: Clay Risser
11
+ * -----
12
+ * Risser Labs LLC (c) Copyright 2021 - 2022
13
+ *
14
+ * Licensed under the Apache License, Version 2.0 (the "License");
15
+ * you may not use this file except in compliance with the License.
16
+ * You may obtain a copy of the License at
17
+ *
18
+ * http://www.apache.org/licenses/LICENSE-2.0
19
+ *
20
+ * Unless required by applicable law or agreed to in writing, software
21
+ * distributed under the License is distributed on an "AS IS" BASIS,
22
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
23
+ * See the License for the specific language governing permissions and
24
+ * limitations under the License.
25
+ */
26
+ declare const defaultAuthConfig: AuthConfig;
27
+ declare const AuthConfigContext: React.Context<AuthConfig>;
28
+ interface AuthConfig {
29
+ debug?: boolean;
30
+ ensureFreshness?: boolean;
31
+ loginRoute?: string;
32
+ messageHandlerKeys?: string[];
33
+ persist?: boolean;
34
+ ssr?: boolean;
35
+ }
36
+
37
+ export { AuthConfig, AuthConfigContext, defaultAuthConfig };
@@ -0,0 +1,8 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ var _chunkA7UBOIALjs = require("./chunk-A7UBOIAL.js");
6
+ require("./chunk-XXPGZHWZ.js");
7
+ exports.AuthConfigContext = _chunkA7UBOIALjs.AuthConfigContext;
8
+ exports.defaultAuthConfig = _chunkA7UBOIALjs.defaultAuthConfig;
@@ -0,0 +1,9 @@
1
+ import {
2
+ AuthConfigContext,
3
+ defaultAuthConfig
4
+ } from "./chunk-64PPU7Q3.mjs";
5
+ import "./chunk-NHABU752.mjs";
6
+ export {
7
+ AuthConfigContext,
8
+ defaultAuthConfig
9
+ };
File without changes
@@ -0,0 +1,11 @@
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;
@@ -0,0 +1,13 @@
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
+ };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,41 @@
1
+ import {
2
+ useCurrentRouteName
3
+ } from "./chunk-L5HMOY4M.mjs";
4
+ import {
5
+ useKeycloak
6
+ } from "./chunk-BTHRDOLL.mjs";
7
+ import {
8
+ useAuthConfig
9
+ } from "./chunk-Y4XMF3R6.mjs";
10
+
11
+ // src/hooks/useLogin.ts
12
+ import { MultiPlatform } from "multiplatform.one";
13
+ import { useRouter } from "solito/router";
14
+ function useLogin(loginRoute) {
15
+ if (MultiPlatform.isStorybook)
16
+ return () => null;
17
+ const keycloak = useKeycloak();
18
+ const authConfig = useAuthConfig();
19
+ const currentRouteName = useCurrentRouteName();
20
+ const router = useRouter();
21
+ return () => {
22
+ if (!loginRoute)
23
+ loginRoute = authConfig.loginRoute;
24
+ if (!loginRoute) {
25
+ keycloak.login();
26
+ return;
27
+ }
28
+ const url = new URL(`x://${loginRoute}`);
29
+ const searchParams = new URLSearchParams(url.search);
30
+ if (currentRouteName)
31
+ searchParams.append("backTo", currentRouteName);
32
+ let query = searchParams.toString();
33
+ if (query.length)
34
+ query = `?${query}`;
35
+ router.push(`${url.pathname.substring(2)}${query}`);
36
+ };
37
+ }
38
+
39
+ export {
40
+ useLogin
41
+ };
@@ -0,0 +1,78 @@
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 _chunkNRD376XVjs = require("./chunk-NRD376XV.js");
40
+ var _chunkS3M2DZ6Gjs = require("./chunk-S3M2DZ6G.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 = _chunkNRD376XVjs.useLogin.call(void 0, loginRoute);
52
+ var tokensFromQuery = _chunkKLLABHICjs.useTokensFromQuery.call(void 0);
53
+ var tokensFromState = _chunkYGNNHTFEjs.useTokensFromState.call(void 0);
54
+ var authenticated = _chunkS3M2DZ6Gjs.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;
@@ -0,0 +1,26 @@
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
+ };
@@ -0,0 +1,13 @@
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;
@@ -0,0 +1,20 @@
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
+ };
File without changes
@@ -0,0 +1,84 @@
1
+ import {
2
+ useAuthConfig
3
+ } from "./chunk-Y4XMF3R6.mjs";
4
+ import {
5
+ __publicField
6
+ } from "./chunk-NHABU752.mjs";
7
+
8
+ // src/hooks/useKeycloak/useKeycloak.ts
9
+ import { MultiPlatform } from "multiplatform.one";
10
+ import { useKeycloak as useReactKeycloak } from "@bitspur/react-keycloak-web";
11
+ import { useKeycloak as useSsrKeycloak } from "@bitspur/react-keycloak-ssr";
12
+ function useKeycloak() {
13
+ const authConfig = useAuthConfig();
14
+ if (MultiPlatform.isStorybook) {
15
+ return new Keycloak(
16
+ {
17
+ email: "storybook@example.com",
18
+ login: async () => void 0,
19
+ logout: async () => void 0,
20
+ subject: "0",
21
+ username: "storybook"
22
+ },
23
+ true
24
+ );
25
+ }
26
+ if (MultiPlatform.isNext && authConfig.ssr) {
27
+ const { keycloak: keycloak2, initialized: initialized2 } = useSsrKeycloak();
28
+ return new Keycloak(keycloak2, initialized2);
29
+ }
30
+ const { keycloak, initialized } = useReactKeycloak();
31
+ return new Keycloak(keycloak, initialized);
32
+ }
33
+ var Keycloak = class {
34
+ constructor(keycloak, initialized) {
35
+ this.keycloak = keycloak;
36
+ __publicField(this, "authenticated");
37
+ this.authenticated = initialized ? keycloak?.authenticated : void 0;
38
+ }
39
+ get idToken() {
40
+ return this.keycloak?.idToken;
41
+ }
42
+ get realmAccess() {
43
+ return this.keycloak?.realmAccess;
44
+ }
45
+ get refreshToken() {
46
+ return this.keycloak?.refreshToken;
47
+ }
48
+ get refreshTokenParsed() {
49
+ return this.keycloak?.refreshTokenParsed;
50
+ }
51
+ get resourceAccess() {
52
+ return this.keycloak?.resourceAccess;
53
+ }
54
+ get subject() {
55
+ return this.keycloak?.subject;
56
+ }
57
+ get token() {
58
+ return this.keycloak?.token;
59
+ }
60
+ get tokenParsed() {
61
+ return this.keycloak?.tokenParsed;
62
+ }
63
+ get email() {
64
+ return this.keycloak?.tokenParsed?.email;
65
+ }
66
+ get username() {
67
+ return this.keycloak?.tokenParsed?.preferred_username;
68
+ }
69
+ async login() {
70
+ if (!this.keycloak)
71
+ return;
72
+ return this.keycloak.login();
73
+ }
74
+ async logout() {
75
+ if (!this.keycloak)
76
+ return;
77
+ return this.keycloak.logout();
78
+ }
79
+ };
80
+
81
+ export {
82
+ useKeycloak,
83
+ Keycloak
84
+ };
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ }); // src/state/index.ts
5
+ var _zustand = require("multiplatform.one/zustand");
6
+ var _config = require("app/config");
7
+ var useStore = _zustand.createStateStore.call(void 0, "auth", {
8
+ idToken: "",
9
+ refreshToken: "",
10
+ token: ""
11
+ }, void 0, {
12
+ persist: _config.config.get("KEYCLOAK_PERSIST") === "1"
13
+ }).useStore;
14
+ function useAuthState() {
15
+ return useStore();
16
+ }
17
+ exports.useAuthState = useAuthState;
@@ -0,0 +1,52 @@
1
+ import {
2
+ useTokensFromQuery
3
+ } from "./chunk-NXTVYIBR.mjs";
4
+ import {
5
+ useLogin
6
+ } from "./chunk-6QZDLO3M.mjs";
7
+ import {
8
+ useKeycloak
9
+ } from "./chunk-BTHRDOLL.mjs";
10
+ import {
11
+ useAuthConfig
12
+ } from "./chunk-Y4XMF3R6.mjs";
13
+ import {
14
+ useTokensFromState
15
+ } from "./chunk-UOKDJT5L.mjs";
16
+ import {
17
+ useAuthState
18
+ } from "./chunk-AD6VPMID.mjs";
19
+
20
+ // src/Authenticated.tsx
21
+ import React, { useEffect } from "react";
22
+ function Authenticated({ children, disabled, loginRoute, loggedOutComponent }) {
23
+ const authConfig = useAuthConfig();
24
+ const authState = useAuthState();
25
+ const login = useLogin(loginRoute);
26
+ const tokensFromQuery = useTokensFromQuery();
27
+ const tokensFromState = useTokensFromState();
28
+ const { authenticated } = useKeycloak();
29
+ useEffect(() => {
30
+ if (authenticated !== false)
31
+ return;
32
+ if (authConfig.persist) {
33
+ authState.setIdToken("");
34
+ authState.setRefreshToken("");
35
+ authState.setToken("");
36
+ }
37
+ if (typeof window !== "undefined" && !tokensFromQuery && !tokensFromState && window.self === window.top)
38
+ login();
39
+ }, [authenticated]);
40
+ if (disabled || authenticated)
41
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
42
+ const LoggedOutComponent = loggedOutComponent || (() => /* @__PURE__ */ React.createElement(React.Fragment, null, authConfig.debug ? "not authenticated" : null));
43
+ return /* @__PURE__ */ React.createElement(LoggedOutComponent, null);
44
+ }
45
+ function withAuthenticated(Component) {
46
+ return (props) => /* @__PURE__ */ React.createElement(Authenticated, null, /* @__PURE__ */ React.createElement(Component, { ...props }));
47
+ }
48
+
49
+ export {
50
+ Authenticated,
51
+ withAuthenticated
52
+ };