@multiplatform.one/keycloak 0.7.15 → 0.7.17

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 (228) hide show
  1. package/lib/@types/expoKeycloakAuth.d.js +1 -1
  2. package/lib/Authenticated.d.mts +2 -2
  3. package/lib/Authenticated.d.ts +2 -2
  4. package/lib/Authenticated.js +20 -19
  5. package/lib/Authenticated.mjs +13 -13
  6. package/lib/authConfig.d.mts +2 -4
  7. package/lib/authConfig.d.ts +2 -4
  8. package/lib/authConfig.js +9 -8
  9. package/lib/authConfig.mjs +2 -2
  10. package/lib/chunk-2BKS6UM5.js +51 -0
  11. package/lib/chunk-2BSUCVXL.js +50 -0
  12. package/lib/chunk-2L5TXBDK.mjs +7 -0
  13. package/lib/chunk-2VDDEPLF.js +27 -0
  14. package/lib/chunk-32AVT4GA.js +9 -0
  15. package/lib/chunk-3ZTSLDX7.js +13 -0
  16. package/lib/chunk-6F4PWJZI.js +1 -0
  17. package/lib/{chunk-7MTPH6XK.mjs → chunk-6FRYV4MK.mjs} +10 -9
  18. package/lib/chunk-A2V2S4HP.js +22 -0
  19. package/lib/chunk-BUZONXAW.js +1 -0
  20. package/lib/{chunk-BVB33X7V.mjs → chunk-CGLMLNUS.mjs} +61 -81
  21. package/lib/chunk-FU4CT24B.mjs +32 -0
  22. package/lib/{chunk-Y4XMF3R6.mjs → chunk-HTWZLBA4.mjs} +1 -1
  23. package/lib/chunk-I5FNGKQ6.js +16 -0
  24. package/lib/{chunk-64PPU7Q3.mjs → chunk-JAFUI2JQ.mjs} +1 -5
  25. package/lib/{chunk-NXTVYIBR.mjs → chunk-L3HTVJ4B.mjs} +2 -0
  26. package/lib/chunk-MDAAMGTE.js +1 -0
  27. package/lib/chunk-NH335CDK.js +32 -0
  28. package/lib/chunk-OA5TSQWZ.mjs +50 -0
  29. package/lib/chunk-OBB23GPX.mjs +0 -0
  30. package/lib/chunk-OZLV3US5.js +245 -0
  31. package/lib/chunk-P57PW2II.js +11 -0
  32. package/lib/chunk-TUJRPTZE.js +13 -0
  33. package/lib/chunk-UESWAK47.mjs +0 -0
  34. package/lib/chunk-UH4K7HGE.mjs +163 -0
  35. package/lib/{chunk-UOKDJT5L.mjs → chunk-UKSHA3X3.mjs} +2 -2
  36. package/lib/chunk-VS4M7GMO.js +1 -0
  37. package/lib/chunk-WBQAMGXK.mjs +0 -0
  38. package/lib/{chunk-AD6VPMID.mjs → chunk-WMH347OL.mjs} +5 -3
  39. package/lib/chunk-WS4IMGVL.js +1 -0
  40. package/lib/chunk-X53FOCXA.js +28 -0
  41. package/lib/chunk-Y23BWOII.mjs +51 -0
  42. package/lib/chunk-Y5MS3XVZ.mjs +28 -0
  43. package/lib/chunk-YACGLW5Q.js +7 -0
  44. package/lib/chunk-ZCBD6HWK.js +1 -0
  45. package/lib/chunk-ZFXKCRJC.mjs +11 -0
  46. package/lib/chunk-ZW4GP2I5.js +163 -0
  47. package/lib/hooks/index.d.mts +0 -4
  48. package/lib/hooks/index.d.ts +0 -4
  49. package/lib/hooks/index.js +19 -23
  50. package/lib/hooks/index.mjs +8 -23
  51. package/lib/hooks/useAuthConfig.js +8 -8
  52. package/lib/hooks/useAuthConfig.mjs +3 -3
  53. package/lib/hooks/useTokensFromQuery/index.js +7 -7
  54. package/lib/hooks/useTokensFromQuery/index.mjs +2 -2
  55. package/lib/hooks/useTokensFromQuery/index.native.js +5 -8
  56. package/lib/hooks/useTokensFromQuery/index.native.mjs +1 -1
  57. package/lib/hooks/useTokensFromState.js +9 -9
  58. package/lib/hooks/useTokensFromState.mjs +4 -4
  59. package/lib/index.d.mts +10 -7
  60. package/lib/index.d.ts +10 -7
  61. package/lib/index.js +62 -34
  62. package/lib/index.mjs +32 -26
  63. package/lib/keycloak/context.d.mts +12 -0
  64. package/lib/keycloak/context.d.ts +12 -0
  65. package/lib/keycloak/context.js +7 -0
  66. package/lib/keycloak/context.mjs +7 -0
  67. package/lib/keycloak/index.d.mts +7 -0
  68. package/lib/keycloak/index.d.ts +7 -0
  69. package/lib/keycloak/index.js +14 -0
  70. package/lib/keycloak/index.mjs +14 -0
  71. package/lib/keycloak/keycloak.d.mts +37 -0
  72. package/lib/keycloak/keycloak.d.ts +37 -0
  73. package/lib/keycloak/keycloak.js +13 -0
  74. package/lib/keycloak/keycloak.mjs +13 -0
  75. package/lib/keycloak/keycloak.native.d.mts +33 -0
  76. package/lib/keycloak/keycloak.native.d.ts +33 -0
  77. package/lib/keycloak/keycloak.native.js +134 -0
  78. package/lib/keycloak/keycloak.native.mjs +134 -0
  79. package/lib/provider/{afterAuth.d.ts → AfterAuth.d.mts} +6 -7
  80. package/lib/provider/{afterAuth.d.mts → AfterAuth.d.ts} +6 -7
  81. package/lib/provider/AfterAuth.js +18 -0
  82. package/lib/provider/AfterAuth.mjs +18 -0
  83. package/lib/provider/AuthProvider/AuthProvider.d.mts +37 -0
  84. package/lib/provider/AuthProvider/AuthProvider.d.ts +37 -0
  85. package/lib/provider/AuthProvider/AuthProvider.js +19 -0
  86. package/lib/provider/AuthProvider/AuthProvider.mjs +19 -0
  87. package/lib/provider/{keycloakProvider.native.d.ts → AuthProvider/AuthProvider.native.d.mts} +9 -9
  88. package/lib/provider/{keycloakProvider.native.d.mts → AuthProvider/AuthProvider.native.d.ts} +9 -9
  89. package/lib/provider/AuthProvider/AuthProvider.native.js +25 -0
  90. package/lib/provider/AuthProvider/AuthProvider.native.mjs +25 -0
  91. package/lib/provider/AuthProvider/index.d.mts +4 -0
  92. package/lib/provider/AuthProvider/index.d.ts +4 -0
  93. package/lib/provider/AuthProvider/index.js +20 -0
  94. package/lib/provider/AuthProvider/index.mjs +20 -0
  95. package/lib/provider/KeycloakProvider.d.mts +34 -0
  96. package/lib/provider/KeycloakProvider.d.ts +34 -0
  97. package/lib/provider/KeycloakProvider.js +21 -0
  98. package/lib/provider/KeycloakProvider.mjs +21 -0
  99. package/lib/provider/index.d.mts +8 -39
  100. package/lib/provider/index.d.ts +8 -39
  101. package/lib/provider/index.js +28 -22
  102. package/lib/provider/index.mjs +22 -19
  103. package/lib/routes.d.mts +28 -0
  104. package/lib/routes.d.ts +28 -0
  105. package/lib/routes.js +127 -0
  106. package/lib/routes.mjs +127 -0
  107. package/lib/session/index.d.mts +3 -0
  108. package/lib/session/index.d.ts +3 -0
  109. package/lib/session/index.js +10 -0
  110. package/lib/session/index.mjs +10 -0
  111. package/lib/session/session.d.mts +18 -0
  112. package/lib/session/session.d.ts +18 -0
  113. package/lib/session/session.js +9 -0
  114. package/lib/session/session.mjs +9 -0
  115. package/lib/session/session.native.d.mts +8 -0
  116. package/lib/session/session.native.d.ts +8 -0
  117. package/lib/session/session.native.js +13 -0
  118. package/lib/session/session.native.mjs +13 -0
  119. package/lib/{state/index.d.ts → state.d.mts} +2 -1
  120. package/lib/{state/index.d.mts → state.d.ts} +2 -1
  121. package/lib/state.js +9 -0
  122. package/lib/state.mjs +9 -0
  123. package/lib/token.d.mts +17 -0
  124. package/lib/token.d.ts +17 -0
  125. package/lib/token.js +9 -0
  126. package/lib/{util.mjs → token.mjs} +2 -2
  127. package/lib/types.d.mts +5 -2
  128. package/lib/types.d.ts +5 -2
  129. package/lib/types.js +1 -8
  130. package/lib/types.mjs +1 -7
  131. package/package.json +28 -28
  132. package/routes/index.d.ts +22 -0
  133. package/routes/index.js +22 -0
  134. package/src/Authenticated.tsx +27 -17
  135. package/src/authConfig.ts +3 -9
  136. package/src/hooks/index.ts +0 -3
  137. package/src/hooks/useTokensFromQuery/index.ts +1 -0
  138. package/src/hooks/useTokensFromState.ts +1 -1
  139. package/src/index.ts +3 -0
  140. package/src/{@types/coreJsPure.d.ts → keycloak/context.ts} +6 -11
  141. package/src/{hooks/useCurrentRouteName/index.native.ts → keycloak/index.ts} +4 -11
  142. package/src/keycloak/keycloak.native.ts +148 -0
  143. package/src/keycloak/keycloak.ts +175 -0
  144. package/src/provider/AfterAuth.tsx +63 -0
  145. package/src/provider/{keycloakProvider.native.tsx → AuthProvider/AuthProvider.native.tsx} +8 -16
  146. package/src/provider/{keycloakProvider.tsx → AuthProvider/AuthProvider.tsx} +81 -94
  147. package/src/provider/AuthProvider/index.ts +22 -0
  148. package/src/provider/KeycloakProvider.tsx +53 -0
  149. package/src/provider/index.ts +24 -0
  150. package/src/routes.ts +163 -0
  151. package/src/session/index.ts +22 -0
  152. package/src/{hooks/useCurrentRouteName/index.ts → session/session.native.ts} +11 -14
  153. package/src/session/session.ts +68 -0
  154. package/src/{state/index.ts → state.ts} +5 -4
  155. package/src/{util.ts → token.ts} +25 -11
  156. package/src/types.ts +4 -1
  157. package/lib/@types/coreJsPure.d.d.mts +0 -2
  158. package/lib/@types/coreJsPure.d.d.ts +0 -2
  159. package/lib/@types/coreJsPure.d.js +0 -1
  160. package/lib/chunk-3ZPHNEJL.js +0 -11
  161. package/lib/chunk-6NDWOV55.js +0 -1
  162. package/lib/chunk-A7UBOIAL.js +0 -13
  163. package/lib/chunk-AUUZ6BI7.js +0 -78
  164. package/lib/chunk-C2FNSVJO.js +0 -17
  165. package/lib/chunk-J4CCMILN.mjs +0 -41
  166. package/lib/chunk-K33RKJZX.js +0 -443
  167. package/lib/chunk-KLLABHIC.js +0 -13
  168. package/lib/chunk-L5HMOY4M.mjs +0 -18
  169. package/lib/chunk-MZ6E62HK.js +0 -33
  170. package/lib/chunk-NWRANDZ6.js +0 -98
  171. package/lib/chunk-OYWAYMFN.js +0 -17
  172. package/lib/chunk-RPUOO7AV.mjs +0 -10
  173. package/lib/chunk-RYM7KERK.mjs +0 -52
  174. package/lib/chunk-UBVYEZI3.js +0 -1
  175. package/lib/chunk-UHTKOFS6.mjs +0 -84
  176. package/lib/chunk-UL6L5ONI.js +0 -460
  177. package/lib/chunk-W5DJLFTQ.js +0 -56
  178. package/lib/chunk-WT5W6BSZ.js +0 -161
  179. package/lib/chunk-XEO3YXBM.js +0 -22
  180. package/lib/chunk-XO4W2SMN.mjs +0 -50
  181. package/lib/chunk-XVPWAAZ4.mjs +0 -76
  182. package/lib/chunk-YGNNHTFE.js +0 -12
  183. package/lib/hooks/useCurrentRouteName/index.d.mts +0 -3
  184. package/lib/hooks/useCurrentRouteName/index.d.ts +0 -3
  185. package/lib/hooks/useCurrentRouteName/index.js +0 -7
  186. package/lib/hooks/useCurrentRouteName/index.mjs +0 -7
  187. package/lib/hooks/useCurrentRouteName/index.native.d.mts +0 -3
  188. package/lib/hooks/useCurrentRouteName/index.native.d.ts +0 -3
  189. package/lib/hooks/useCurrentRouteName/index.native.js +0 -14
  190. package/lib/hooks/useCurrentRouteName/index.native.mjs +0 -14
  191. package/lib/hooks/useKeycloak/index.d.mts +0 -46
  192. package/lib/hooks/useKeycloak/index.d.ts +0 -46
  193. package/lib/hooks/useKeycloak/index.js +0 -11
  194. package/lib/hooks/useKeycloak/index.mjs +0 -12
  195. package/lib/hooks/useKeycloak/useKeycloak.d.mts +0 -2
  196. package/lib/hooks/useKeycloak/useKeycloak.d.ts +0 -2
  197. package/lib/hooks/useKeycloak/useKeycloak.js +0 -10
  198. package/lib/hooks/useKeycloak/useKeycloak.mjs +0 -11
  199. package/lib/hooks/useKeycloak/useKeycloak.native.d.mts +0 -20
  200. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +0 -20
  201. package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -80
  202. package/lib/hooks/useKeycloak/useKeycloak.native.mjs +0 -69
  203. package/lib/hooks/useLogin.d.mts +0 -3
  204. package/lib/hooks/useLogin.d.ts +0 -3
  205. package/lib/hooks/useLogin.js +0 -11
  206. package/lib/hooks/useLogin.mjs +0 -11
  207. package/lib/provider/afterAuth.js +0 -18
  208. package/lib/provider/afterAuth.mjs +0 -18
  209. package/lib/provider/keycloakProvider.d.mts +0 -42
  210. package/lib/provider/keycloakProvider.d.ts +0 -42
  211. package/lib/provider/keycloakProvider.js +0 -20
  212. package/lib/provider/keycloakProvider.mjs +0 -21
  213. package/lib/provider/keycloakProvider.native.js +0 -87
  214. package/lib/provider/keycloakProvider.native.mjs +0 -30
  215. package/lib/state/index.js +0 -7
  216. package/lib/state/index.mjs +0 -7
  217. package/lib/util.d.mts +0 -4
  218. package/lib/util.d.ts +0 -4
  219. package/lib/util.js +0 -8
  220. package/src/hooks/useKeycloak/index.ts +0 -47
  221. package/src/hooks/useKeycloak/useKeycloak.native.ts +0 -95
  222. package/src/hooks/useKeycloak/useKeycloak.ts +0 -106
  223. package/src/hooks/useLogin.ts +0 -47
  224. package/src/provider/afterAuth.tsx +0 -65
  225. package/src/provider/index.tsx +0 -117
  226. /package/lib/{@types/coreJsPure.d.mjs → chunk-HH32BME2.mjs} +0 -0
  227. /package/lib/{chunk-2GUOEPFY.mjs → chunk-JPQI72HR.mjs} +0 -0
  228. /package/lib/{chunk-AYKQVWMR.mjs → chunk-OAUYHIWG.mjs} +0 -0
@@ -1,10 +1,6 @@
1
1
  // src/authConfig.ts
2
2
  import { createContext } from "react";
3
- var defaultAuthConfig = {
4
- ensureFreshness: true,
5
- persist: false,
6
- ssr: false
7
- };
3
+ var defaultAuthConfig = {};
8
4
  var AuthConfigContext = createContext(defaultAuthConfig);
9
5
 
10
6
  export {
@@ -2,6 +2,8 @@
2
2
  import { MultiPlatform } from "multiplatform.one";
3
3
  import { useRouter } from "next/router";
4
4
  function useTokensFromQuery() {
5
+ if (!MultiPlatform.isIframe)
6
+ return false;
5
7
  const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
6
8
  return "idToken" in query || "token" in query || "refreshToken" in query;
7
9
  }
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,32 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { newObj[key] = obj[key]; } } } newObj.default = obj; return newObj; } }// src/session/session.ts
2
+ var _multiplatformone = require('multiplatform.one');
3
+ var _react = require('next-auth/react');
4
+ var _getServerSession;
5
+ async function getSession() {
6
+ if (_multiplatformone.MultiPlatform.isServer) {
7
+ if (typeof _getServerSession === "function")
8
+ return _getServerSession();
9
+ const getSession2 = (await Promise.resolve().then(() => _interopRequireWildcard(require("next-auth")))).getServerSession;
10
+ _getServerSession = () => getSession2();
11
+ return _getServerSession();
12
+ }
13
+ return _react.getSession.call(void 0, );
14
+ }
15
+ var useSession = (options) => {
16
+ return {};
17
+ };
18
+ if (_multiplatformone.MultiPlatform.isNext) {
19
+ useSession = exports.useSession = (options) => {
20
+ const nextSession = _react.useSession.call(void 0, options);
21
+ return {
22
+ update: nextSession.update,
23
+ status: nextSession.status,
24
+ session: nextSession.data
25
+ };
26
+ };
27
+ }
28
+
29
+
30
+
31
+
32
+ exports.getSession = getSession; exports.useSession = useSession;
@@ -0,0 +1,50 @@
1
+ import {
2
+ useTokensFromQuery
3
+ } from "./chunk-L3HTVJ4B.mjs";
4
+ import {
5
+ useAuthConfig
6
+ } from "./chunk-HTWZLBA4.mjs";
7
+ import {
8
+ useTokensFromState
9
+ } from "./chunk-UKSHA3X3.mjs";
10
+ import {
11
+ useKeycloak
12
+ } from "./chunk-UH4K7HGE.mjs";
13
+
14
+ // src/Authenticated.tsx
15
+ import React, { useEffect } from "react";
16
+ import { MultiPlatform } from "multiplatform.one";
17
+ function Authenticated({ children, disabled, loggedOutComponent, loadingComponent }) {
18
+ const authConfig = useAuthConfig();
19
+ const keycloak = useKeycloak();
20
+ const tokensFromQuery = useTokensFromQuery();
21
+ const tokensFromState = useTokensFromState();
22
+ useEffect(() => {
23
+ if (!keycloak || MultiPlatform.isIframe || MultiPlatform.isServer || keycloak.authenticated || tokensFromQuery || tokensFromState) {
24
+ return;
25
+ }
26
+ keycloak.login({
27
+ redirectUri: authConfig.loginRedirectUri
28
+ });
29
+ }, [keycloak]);
30
+ if (typeof disabled === "undefined")
31
+ disabled = authConfig.disabled;
32
+ if (disabled)
33
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
34
+ if (typeof keycloak === "undefined") {
35
+ const LoadingComponent = loadingComponent;
36
+ return LoadingComponent ? /* @__PURE__ */ React.createElement(LoadingComponent, null) : /* @__PURE__ */ React.createElement(React.Fragment, null, authConfig.debug ? "loading" : null);
37
+ }
38
+ if (keycloak.authenticated)
39
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
40
+ const LoggedOutComponent = loggedOutComponent;
41
+ return LoggedOutComponent ? /* @__PURE__ */ React.createElement(LoggedOutComponent, null) : /* @__PURE__ */ React.createElement(React.Fragment, null, authConfig.debug ? "not authenticated" : null);
42
+ }
43
+ function withAuthenticated(Component) {
44
+ return (props) => /* @__PURE__ */ React.createElement(Authenticated, null, /* @__PURE__ */ React.createElement(Component, { ...props }));
45
+ }
46
+
47
+ export {
48
+ Authenticated,
49
+ withAuthenticated
50
+ };
File without changes
@@ -0,0 +1,245 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunk2BKS6UM5js = require('./chunk-2BKS6UM5.js');
4
+
5
+
6
+ var _chunk3ZTSLDX7js = require('./chunk-3ZTSLDX7.js');
7
+
8
+
9
+ var _chunkZW4GP2I5js = require('./chunk-ZW4GP2I5.js');
10
+
11
+
12
+ var _chunkYACGLW5Qjs = require('./chunk-YACGLW5Q.js');
13
+
14
+
15
+
16
+ var _chunkA2V2S4HPjs = require('./chunk-A2V2S4HP.js');
17
+
18
+
19
+ var _chunk2VDDEPLFjs = require('./chunk-2VDDEPLF.js');
20
+
21
+ // src/provider/AuthProvider/AuthProvider.tsx
22
+ var _keycloakjs = require('keycloak-js'); var _keycloakjs2 = _interopRequireDefault(_keycloakjs);
23
+ var _react = require('react'); var _react2 = _interopRequireDefault(_react);
24
+ var _multiplatformone = require('multiplatform.one');
25
+ var _react3 = require('next-auth/react');
26
+ var _router = require('next/router');
27
+ var logger = console;
28
+ function AuthProvider({ children, sessionProvider, keycloakInitOptions, keycloakConfig }) {
29
+ const { debug, messageHandlerKeys } = _chunk3ZTSLDX7js.useAuthConfig.call(void 0, );
30
+ const { query } = _multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0, ) : { query: {} };
31
+ const authState = _chunkA2V2S4HPjs.useAuthState.call(void 0, );
32
+ const [keycloak, setKeycloak] = _react.useState.call(void 0, );
33
+ const [refreshToken, setRefreshToken] = _react.useState.call(void 0,
34
+ _chunk2VDDEPLFjs.validToken.call(void 0,
35
+ _multiplatformone.MultiPlatform.isIframe ? "refreshToken" in query && (_optionalChain([query, 'access', _ => _.refreshToken, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()]) || true) || _chunkA2V2S4HPjs.persist && authState.refreshToken || false : void 0
36
+ )
37
+ );
38
+ const [token, setToken] = _react.useState.call(void 0,
39
+ _chunk2VDDEPLFjs.validToken.call(void 0,
40
+ _multiplatformone.MultiPlatform.isIframe ? "token" in query && (_optionalChain([query, 'access', _4 => _4.token, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]) || true) || _chunkA2V2S4HPjs.persist && authState.token || false : void 0,
41
+ refreshToken
42
+ )
43
+ );
44
+ const [idToken, setIdToken] = _react.useState.call(void 0,
45
+ _chunk2VDDEPLFjs.validToken.call(void 0,
46
+ _multiplatformone.MultiPlatform.isIframe ? "idToken" in query && (_optionalChain([query, 'access', _7 => _7.idToken, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]) || true) || _chunkA2V2S4HPjs.persist && authState.idToken || false : void 0,
47
+ refreshToken
48
+ )
49
+ );
50
+ _react.useEffect.call(void 0, () => {
51
+ if (token !== true && refreshToken !== true && idToken !== true)
52
+ return;
53
+ if (debug)
54
+ logger.debug("post message", JSON.stringify({ type: "LOADED" }));
55
+ (messageHandlerKeys || []).forEach((key) => {
56
+ _optionalChain([window, 'optionalAccess', _10 => _10.webkit, 'optionalAccess', _11 => _11.messageHandlers, 'optionalAccess', _12 => _12[key], 'optionalAccess', _13 => _13.postMessage, 'call', _14 => _14(JSON.stringify({ type: "LOADED" }))]);
57
+ });
58
+ _optionalChain([window, 'optionalAccess', _15 => _15.ReactNativeWebView, 'optionalAccess', _16 => _16.postMessage, 'call', _17 => _17(JSON.stringify({ type: "LOADED" }))]);
59
+ _optionalChain([window, 'optionalAccess', _18 => _18.parent, 'optionalAccess', _19 => _19.postMessage, 'call', _20 => _20(JSON.stringify({ type: "LOADED" }))]);
60
+ }, []);
61
+ _react.useEffect.call(void 0, () => {
62
+ if (refreshToken !== true)
63
+ return;
64
+ const messageCallback = (e) => {
65
+ let data = _optionalChain([e, 'optionalAccess', _21 => _21.data]) || null;
66
+ if (typeof data === "string") {
67
+ try {
68
+ data = JSON.parse(data);
69
+ } catch (err) {
70
+ }
71
+ }
72
+ if (debug)
73
+ logger.debug("received message", JSON.stringify(data));
74
+ const message = data;
75
+ if (!message.type)
76
+ return;
77
+ if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
78
+ if (debug)
79
+ logger.debug("setting refresh token", message.payload);
80
+ setRefreshToken(_chunk2VDDEPLFjs.validToken.call(void 0, message.payload));
81
+ window.removeEventListener("message", messageCallback);
82
+ }
83
+ };
84
+ if (debug) {
85
+ logger.debug(
86
+ "listening for message",
87
+ JSON.stringify({
88
+ type: "REFRESH_TOKEN",
89
+ payload: "<some_refresh_token>"
90
+ })
91
+ );
92
+ }
93
+ window.addEventListener("message", messageCallback);
94
+ return () => {
95
+ window.removeEventListener("message", messageCallback);
96
+ };
97
+ }, []);
98
+ _react.useEffect.call(void 0, () => {
99
+ if (token !== true)
100
+ return;
101
+ const messageCallback = (e) => {
102
+ let data = _optionalChain([e, 'optionalAccess', _22 => _22.data]) || null;
103
+ if (typeof data === "string") {
104
+ try {
105
+ data = JSON.parse(data);
106
+ } catch (err) {
107
+ }
108
+ }
109
+ if (debug)
110
+ logger.debug("received message", JSON.stringify(data));
111
+ const message = data;
112
+ if (!message.type)
113
+ return;
114
+ if (message.type.toUpperCase() === "TOKEN" && message.payload) {
115
+ if (debug)
116
+ logger.debug("setting token", message.payload);
117
+ setToken(_chunk2VDDEPLFjs.validToken.call(void 0, message.payload, refreshToken));
118
+ window.removeEventListener("message", messageCallback);
119
+ }
120
+ };
121
+ if (debug) {
122
+ logger.debug(
123
+ "listening for message",
124
+ JSON.stringify({
125
+ type: "TOKEN",
126
+ payload: "<some_token>"
127
+ })
128
+ );
129
+ }
130
+ window.addEventListener("message", messageCallback);
131
+ return () => {
132
+ window.removeEventListener("message", messageCallback);
133
+ };
134
+ }, []);
135
+ _react.useEffect.call(void 0, () => {
136
+ if (idToken !== true)
137
+ return;
138
+ const messageCallback = (e) => {
139
+ let data = _optionalChain([e, 'optionalAccess', _23 => _23.data]) || null;
140
+ if (typeof data === "string") {
141
+ try {
142
+ data = JSON.parse(data);
143
+ } catch (err) {
144
+ }
145
+ }
146
+ if (debug)
147
+ logger.debug("received message", JSON.stringify(data));
148
+ const message = data;
149
+ if (!message.type)
150
+ return;
151
+ if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
152
+ if (debug)
153
+ logger.debug("setting id token", message.payload);
154
+ setIdToken(_chunk2VDDEPLFjs.validToken.call(void 0, message.payload, refreshToken));
155
+ window.removeEventListener("message", messageCallback);
156
+ }
157
+ };
158
+ if (debug) {
159
+ logger.debug(
160
+ "listening for message",
161
+ JSON.stringify({
162
+ type: "ID_TOKEN",
163
+ payload: "<some_id_token>"
164
+ })
165
+ );
166
+ }
167
+ window.addEventListener("message", messageCallback);
168
+ return () => {
169
+ window.removeEventListener("message", messageCallback);
170
+ };
171
+ }, []);
172
+ const keycloakClient = _react.useMemo.call(void 0,
173
+ () => _multiplatformone.MultiPlatform.isIframe && keycloakConfig ? new (0, _keycloakjs2.default)({
174
+ url: keycloakConfig.url,
175
+ realm: keycloakConfig.realm,
176
+ clientId: keycloakConfig.clientId
177
+ }) : void 0,
178
+ [keycloakInitOptions, keycloakConfig, token, refreshToken, idToken]
179
+ );
180
+ const initOptions = _react.useMemo.call(void 0, () => {
181
+ if (!_multiplatformone.MultiPlatform.isIframe)
182
+ return;
183
+ const initOptions2 = {
184
+ ...defaultKeycloakInitOptions,
185
+ ...keycloakInitOptions
186
+ };
187
+ if (debug)
188
+ initOptions2.enableLogging = true;
189
+ if (token && typeof token === "string") {
190
+ initOptions2.token = token;
191
+ initOptions2.timeSkew = 0;
192
+ if (idToken && typeof idToken === "string")
193
+ initOptions2.idToken = idToken;
194
+ if (refreshToken && typeof refreshToken === "string")
195
+ initOptions2.refreshToken = refreshToken;
196
+ }
197
+ if (typeof window !== "undefined" && window.self !== window.top || token && !refreshToken) {
198
+ initOptions2.checkLoginIframe = false;
199
+ initOptions2.flow = "implicit";
200
+ initOptions2.onLoad = void 0;
201
+ }
202
+ return initOptions2;
203
+ }, [keycloakInitOptions, token, idToken, refreshToken]);
204
+ _react.useEffect.call(void 0, () => {
205
+ function onError() {
206
+ if (keycloakClient && initOptions)
207
+ setKeycloak(new (0, _chunkZW4GP2I5js.Keycloak)(keycloakClient));
208
+ }
209
+ function onUpdate() {
210
+ if (keycloakClient && initOptions)
211
+ setKeycloak(new (0, _chunkZW4GP2I5js.Keycloak)(keycloakClient));
212
+ }
213
+ if (keycloakClient && initOptions) {
214
+ (async () => {
215
+ keycloakClient.onAuthError = onError;
216
+ keycloakClient.onAuthLogout = onUpdate;
217
+ keycloakClient.onAuthRefreshError = onError;
218
+ keycloakClient.onAuthRefreshSuccess = onUpdate;
219
+ keycloakClient.onAuthSuccess = onUpdate;
220
+ keycloakClient.onReady = onUpdate;
221
+ keycloakClient.onTokenExpired = async () => {
222
+ try {
223
+ await keycloakClient.updateToken(5);
224
+ } catch (err) {
225
+ setKeycloak(new (0, _chunkZW4GP2I5js.Keycloak)());
226
+ }
227
+ };
228
+ const authenticated = await keycloakClient.init(initOptions);
229
+ setKeycloak(new (0, _chunkZW4GP2I5js.Keycloak)(authenticated ? keycloakClient : void 0));
230
+ })();
231
+ }
232
+ }, []);
233
+ return /* @__PURE__ */ _react2.default.createElement(_react3.SessionProvider, { ...sessionProvider }, /* @__PURE__ */ _react2.default.createElement(_chunkYACGLW5Qjs.KeycloakContext.Provider, { value: keycloak }, /* @__PURE__ */ _react2.default.createElement(_chunk2BKS6UM5js.AfterAuth, null, children)));
234
+ }
235
+ var defaultKeycloakInitOptions = {
236
+ checkLoginIframe: true,
237
+ checkLoginIframeInterval: 5,
238
+ enableLogging: false,
239
+ onLoad: "check-sso",
240
+ pkceMethod: "S256"
241
+ };
242
+
243
+
244
+
245
+ exports.AuthProvider = AuthProvider;
@@ -0,0 +1,11 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
+ get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
+ }) : x)(function(x) {
4
+ if (typeof require !== "undefined")
5
+ return require.apply(this, arguments);
6
+ throw Error('Dynamic require of "' + x + '" is not supported');
7
+ });
8
+
9
+
10
+
11
+ exports.__require = __require;
@@ -0,0 +1,13 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/hooks/useTokensFromQuery/index.ts
2
+ var _multiplatformone = require('multiplatform.one');
3
+ var _router = require('next/router');
4
+ function useTokensFromQuery() {
5
+ if (!_multiplatformone.MultiPlatform.isIframe)
6
+ return false;
7
+ const { query } = _multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0, ) : { query: {} };
8
+ return "idToken" in query || "token" in query || "refreshToken" in query;
9
+ }
10
+
11
+
12
+
13
+ exports.useTokensFromQuery = useTokensFromQuery;
File without changes
@@ -0,0 +1,163 @@
1
+ import {
2
+ KeycloakContext
3
+ } from "./chunk-2L5TXBDK.mjs";
4
+ import {
5
+ getSession,
6
+ useSession
7
+ } from "./chunk-FU4CT24B.mjs";
8
+
9
+ // src/keycloak/keycloak.ts
10
+ import { MultiPlatform } from "multiplatform.one";
11
+ import { jwtDecode } from "jwt-decode";
12
+ import { signIn, signOut } from "next-auth/react";
13
+ import { useContext } from "react";
14
+ var Keycloak = class {
15
+ token;
16
+ idToken;
17
+ refreshToken;
18
+ _idTokenParsed;
19
+ _refreshTokenParsed;
20
+ _tokenParsed;
21
+ keycloakClient;
22
+ mock;
23
+ constructor(input, idToken, refreshToken) {
24
+ if (typeof input === "string") {
25
+ this.token = input;
26
+ this.idToken = idToken;
27
+ this.refreshToken = refreshToken;
28
+ } else if (typeof input === "object") {
29
+ if (typeof input.init === "function") {
30
+ this.keycloakClient = input;
31
+ } else if (input.accessToken) {
32
+ const session = input;
33
+ this.token = session.accessToken;
34
+ this.idToken = session.idToken;
35
+ this.refreshToken = session.refreshToken;
36
+ } else {
37
+ this.mock = input;
38
+ }
39
+ }
40
+ if (this.token && !this._tokenParsed)
41
+ this._tokenParsed = jwtDecode(this.token);
42
+ if (this.idToken && !this._idTokenParsed)
43
+ this._idTokenParsed = jwtDecode(this.idToken);
44
+ if (this.refreshToken && !this._refreshTokenParsed) {
45
+ this._refreshTokenParsed = jwtDecode(this.refreshToken);
46
+ }
47
+ }
48
+ get tokenParsed() {
49
+ if (this.keycloakClient)
50
+ return this.keycloakClient.tokenParsed;
51
+ return this._tokenParsed;
52
+ }
53
+ get idTokenParsed() {
54
+ if (this.keycloakClient)
55
+ return this.keycloakClient.idTokenParsed;
56
+ return this._idTokenParsed;
57
+ }
58
+ get refreshTokenParsed() {
59
+ if (this.keycloakClient)
60
+ return this.keycloakClient.refreshTokenParsed;
61
+ return this._refreshTokenParsed;
62
+ }
63
+ get clientId() {
64
+ if (this.keycloakClient)
65
+ return this.keycloakClient.clientId;
66
+ return this.tokenParsed?.azp;
67
+ }
68
+ get email() {
69
+ if (this.keycloakClient)
70
+ return this.keycloakClient.tokenParsed?.email;
71
+ if (this.mock)
72
+ return this.mock.email;
73
+ return this.tokenParsed?.email;
74
+ }
75
+ get realm() {
76
+ if (this.keycloakClient)
77
+ return this.keycloakClient.realm;
78
+ return this.tokenParsed?.iss?.split("/").pop();
79
+ }
80
+ get realmAccess() {
81
+ if (this.keycloakClient)
82
+ return this.keycloakClient.realmAccess;
83
+ return this.tokenParsed?.realm_access;
84
+ }
85
+ get resourceAccess() {
86
+ if (this.keycloakClient)
87
+ return this.keycloakClient.resourceAccess;
88
+ return this.tokenParsed?.resource_access;
89
+ }
90
+ get sessionId() {
91
+ if (this.keycloakClient)
92
+ return this.keycloakClient.sessionId;
93
+ return this.tokenParsed?.session_state;
94
+ }
95
+ get subject() {
96
+ if (this.keycloakClient)
97
+ return this.keycloakClient.subject;
98
+ return this.tokenParsed?.sub;
99
+ }
100
+ get username() {
101
+ if (this.mock)
102
+ return this.mock.username;
103
+ return this.tokenParsed?.preferred_username;
104
+ }
105
+ async login(options = {}) {
106
+ if (this.keycloakClient) {
107
+ await this.keycloakClient.login(options);
108
+ } else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
109
+ await signIn("keycloak", {
110
+ callbackUrl: options.redirectUri
111
+ });
112
+ }
113
+ }
114
+ async logout(options = {}) {
115
+ if (this.keycloakClient) {
116
+ await this.keycloakClient.logout(options);
117
+ } else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
118
+ await fetch("/api/auth/logout", { method: "GET" });
119
+ await signOut({
120
+ callbackUrl: options.redirectUri
121
+ });
122
+ }
123
+ }
124
+ get authenticated() {
125
+ if (this.mock)
126
+ return true;
127
+ if (this.keycloakClient)
128
+ return !!this.keycloakClient.authenticated;
129
+ if (!this.tokenParsed?.exp || !this.idToken)
130
+ return false;
131
+ return this.tokenParsed.exp > Date.now() / 1e3;
132
+ }
133
+ };
134
+ function useKeycloak() {
135
+ const keycloak = useContext(KeycloakContext);
136
+ if (keycloak)
137
+ return keycloak;
138
+ const { session, status } = useSession();
139
+ if (MultiPlatform.isServer)
140
+ return;
141
+ if (MultiPlatform.isStorybook) {
142
+ return new Keycloak({
143
+ email: "storybook@example.com",
144
+ username: "storybook"
145
+ });
146
+ } else if (status === "unauthenticated") {
147
+ return new Keycloak();
148
+ } else if (status === "authenticated" && session?.accessToken) {
149
+ return new Keycloak(session);
150
+ }
151
+ }
152
+ async function getKeycloak() {
153
+ const session = await getSession();
154
+ if (session?.accessToken)
155
+ return new Keycloak(session);
156
+ return new Keycloak();
157
+ }
158
+
159
+ export {
160
+ Keycloak,
161
+ useKeycloak,
162
+ getKeycloak
163
+ };
@@ -1,9 +1,9 @@
1
1
  import {
2
2
  useAuthState
3
- } from "./chunk-AD6VPMID.mjs";
3
+ } from "./chunk-WMH347OL.mjs";
4
4
  import {
5
5
  validToken
6
- } from "./chunk-7MTPH6XK.mjs";
6
+ } from "./chunk-6FRYV4MK.mjs";
7
7
 
8
8
  // src/hooks/useTokensFromState.ts
9
9
  function useTokensFromState() {
@@ -0,0 +1 @@
1
+ "use strict";
File without changes
@@ -1,6 +1,7 @@
1
- // src/state/index.ts
1
+ // src/state.ts
2
2
  import { createStateStore } from "multiplatform.one/zustand";
3
- import { config } from "app/config";
3
+ import { MultiPlatform } from "multiplatform.one";
4
+ var persist = MultiPlatform.isIframe || !MultiPlatform.isNext && !MultiPlatform.isServer;
4
5
  var { useStore } = createStateStore(
5
6
  "auth",
6
7
  {
@@ -9,12 +10,13 @@ var { useStore } = createStateStore(
9
10
  token: ""
10
11
  },
11
12
  void 0,
12
- { persist: config.get("KEYCLOAK_PERSIST") === "1" }
13
+ { persist }
13
14
  );
14
15
  function useAuthState() {
15
16
  return useStore();
16
17
  }
17
18
 
18
19
  export {
20
+ persist,
19
21
  useAuthState
20
22
  };
@@ -0,0 +1 @@
1
+ "use strict";
@@ -0,0 +1,28 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
+
3
+ var _chunkOZLV3US5js = require('./chunk-OZLV3US5.js');
4
+
5
+
6
+ var _chunk32AVT4GAjs = require('./chunk-32AVT4GA.js');
7
+
8
+ // src/provider/KeycloakProvider.tsx
9
+ var _react = require('react'); var _react2 = _interopRequireDefault(_react);
10
+ function KeycloakProvider({ children, debug, realm, clientId, baseUrl, session }) {
11
+ const authConfig = _react.useMemo.call(void 0, () => ({ debug }), [debug]);
12
+ return /* @__PURE__ */ _react2.default.createElement(_chunk32AVT4GAjs.AuthConfigContext.Provider, { value: authConfig }, /* @__PURE__ */ _react2.default.createElement(
13
+ _chunkOZLV3US5js.AuthProvider,
14
+ {
15
+ sessionProvider: { session },
16
+ keycloakConfig: {
17
+ realm: realm || "main",
18
+ clientId: clientId || "app",
19
+ url: baseUrl
20
+ }
21
+ },
22
+ children
23
+ ));
24
+ }
25
+
26
+
27
+
28
+ exports.KeycloakProvider = KeycloakProvider;
@@ -0,0 +1,51 @@
1
+ import {
2
+ useAuthConfig
3
+ } from "./chunk-HTWZLBA4.mjs";
4
+ import {
5
+ useKeycloak
6
+ } from "./chunk-UH4K7HGE.mjs";
7
+ import {
8
+ persist,
9
+ useAuthState
10
+ } from "./chunk-WMH347OL.mjs";
11
+
12
+ // src/provider/AfterAuth.tsx
13
+ import React, { useEffect } from "react";
14
+ var logger = console;
15
+ function AfterAuth({ children }) {
16
+ const authConfig = useAuthConfig();
17
+ const authState = useAuthState();
18
+ const keycloak = useKeycloak();
19
+ useEffect(() => {
20
+ if (!persist || !keycloak?.authenticated)
21
+ return;
22
+ if (keycloak.token) {
23
+ authState.setToken(keycloak.token);
24
+ if (keycloak.idToken)
25
+ authState.setIdToken(keycloak.idToken);
26
+ if (keycloak.refreshToken)
27
+ authState.setRefreshToken(keycloak.refreshToken);
28
+ }
29
+ }, [keycloak?.authenticated, keycloak?.token, keycloak?.idToken, keycloak?.refreshToken]);
30
+ useEffect(() => {
31
+ if (authConfig.debug && keycloak?.token)
32
+ logger.debug("token", keycloak.token);
33
+ }, [keycloak?.token]);
34
+ useEffect(() => {
35
+ if (authConfig.debug && keycloak?.idToken)
36
+ logger.debug("idToken", keycloak.idToken);
37
+ }, [keycloak?.idToken]);
38
+ useEffect(() => {
39
+ if (authConfig.debug && keycloak?.refreshToken)
40
+ logger.debug("refreshToken", keycloak.refreshToken);
41
+ }, [keycloak?.refreshToken]);
42
+ useEffect(() => {
43
+ if (keycloak?.authenticated)
44
+ logger.debug("authenticated", keycloak.authenticated);
45
+ }, [keycloak?.authenticated]);
46
+ return /* @__PURE__ */ React.createElement(React.Fragment, null, children);
47
+ }
48
+
49
+ export {
50
+ AfterAuth
51
+ };