@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,25 +1,28 @@
1
+ import "../chunk-UESWAK47.mjs";
2
+ import {
3
+ KeycloakProvider
4
+ } from "../chunk-Y5MS3XVZ.mjs";
5
+ import "../chunk-JPQI72HR.mjs";
1
6
  import {
2
7
  AuthProvider
3
- } from "../chunk-XVPWAAZ4.mjs";
8
+ } from "../chunk-CGLMLNUS.mjs";
4
9
  import {
5
- KeycloakProvider,
6
- defaultKeycloakInitOptions
7
- } from "../chunk-BVB33X7V.mjs";
8
- import "../chunk-XO4W2SMN.mjs";
9
- import "../chunk-AYKQVWMR.mjs";
10
- import "../chunk-2GUOEPFY.mjs";
11
- import "../chunk-NXTVYIBR.mjs";
12
- import "../chunk-J4CCMILN.mjs";
13
- import "../chunk-L5HMOY4M.mjs";
14
- import "../chunk-UHTKOFS6.mjs";
15
- import "../chunk-Y4XMF3R6.mjs";
16
- import "../chunk-UOKDJT5L.mjs";
17
- import "../chunk-AD6VPMID.mjs";
18
- import "../chunk-64PPU7Q3.mjs";
19
- import "../chunk-7MTPH6XK.mjs";
20
- import "../chunk-RPUOO7AV.mjs";
10
+ AfterAuth
11
+ } from "../chunk-Y23BWOII.mjs";
12
+ import "../chunk-HH32BME2.mjs";
13
+ import "../chunk-L3HTVJ4B.mjs";
14
+ import "../chunk-HTWZLBA4.mjs";
15
+ import "../chunk-UKSHA3X3.mjs";
16
+ import "../chunk-OBB23GPX.mjs";
17
+ import "../chunk-UH4K7HGE.mjs";
18
+ import "../chunk-2L5TXBDK.mjs";
19
+ import "../chunk-FU4CT24B.mjs";
20
+ import "../chunk-JAFUI2JQ.mjs";
21
+ import "../chunk-WMH347OL.mjs";
22
+ import "../chunk-6FRYV4MK.mjs";
23
+ import "../chunk-ZFXKCRJC.mjs";
21
24
  export {
25
+ AfterAuth,
22
26
  AuthProvider,
23
- KeycloakProvider,
24
- defaultKeycloakInitOptions
27
+ KeycloakProvider
25
28
  };
@@ -0,0 +1,28 @@
1
+ import { AccessTokenParsed } from './token.mjs';
2
+ import { AuthOptions } from 'next-auth';
3
+ import { JWT } from 'next-auth/jwt';
4
+ import { OAuthUserConfig } from 'next-auth/providers';
5
+ import 'keycloak-js';
6
+
7
+ declare function createAuthHandler(options?: CreateAuthHandlerOptions): {
8
+ GET: any;
9
+ POST: any;
10
+ };
11
+ declare function createLogoutHandler(options?: CreateAuthHandlerOptions): {
12
+ GET(): Promise<any>;
13
+ };
14
+ interface CreateAuthHandlerOptions {
15
+ keycloakProvider?: Partial<OAuthUserConfig<any>>;
16
+ nextAuth?: AuthOptions;
17
+ }
18
+ interface NextToken extends JWT {
19
+ accessToken?: string;
20
+ decoded: AccessTokenParsed;
21
+ err?: Error;
22
+ expiresAt: number;
23
+ idToken?: string;
24
+ refreshToken: string;
25
+ roles: string[];
26
+ }
27
+
28
+ export { type CreateAuthHandlerOptions, type NextToken, createAuthHandler, createLogoutHandler };
@@ -0,0 +1,28 @@
1
+ import { AccessTokenParsed } from './token.js';
2
+ import { AuthOptions } from 'next-auth';
3
+ import { JWT } from 'next-auth/jwt';
4
+ import { OAuthUserConfig } from 'next-auth/providers';
5
+ import 'keycloak-js';
6
+
7
+ declare function createAuthHandler(options?: CreateAuthHandlerOptions): {
8
+ GET: any;
9
+ POST: any;
10
+ };
11
+ declare function createLogoutHandler(options?: CreateAuthHandlerOptions): {
12
+ GET(): Promise<any>;
13
+ };
14
+ interface CreateAuthHandlerOptions {
15
+ keycloakProvider?: Partial<OAuthUserConfig<any>>;
16
+ nextAuth?: AuthOptions;
17
+ }
18
+ interface NextToken extends JWT {
19
+ accessToken?: string;
20
+ decoded: AccessTokenParsed;
21
+ err?: Error;
22
+ expiresAt: number;
23
+ idToken?: string;
24
+ refreshToken: string;
25
+ roles: string[];
26
+ }
27
+
28
+ export { type CreateAuthHandlerOptions, type NextToken, createAuthHandler, createLogoutHandler };
package/lib/routes.js ADDED
@@ -0,0 +1,127 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true}); 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; } async function _asyncOptionalChain(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 = await fn(value); } else if (op === 'call' || op === 'optionalCall') { value = await fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
+
3
+ var _chunkP57PW2IIjs = require('./chunk-P57PW2II.js');
4
+
5
+ // src/routes.ts
6
+ var _nextauth = require('next-auth');
7
+ var _jwtdecode = require('jwt-decode');
8
+ var KeycloakProvider = _chunkP57PW2IIjs.__require.call(void 0, "next-auth/providers/keycloak").default;
9
+ var NextAuth = _chunkP57PW2IIjs.__require.call(void 0, "next-auth").default;
10
+ var NextResponse = _chunkP57PW2IIjs.__require.call(void 0, "next/server").NextResponse;
11
+ var logger = console;
12
+ var _nextAuth;
13
+ function createAuthHandler(options = {}) {
14
+ const handler = NextAuth(createAuthOptions(options));
15
+ return {
16
+ GET: handler,
17
+ POST: handler
18
+ };
19
+ }
20
+ function createLogoutHandler(options = {}) {
21
+ return {
22
+ async GET() {
23
+ const idToken = await _asyncOptionalChain([(await _nextauth.getServerSession.call(void 0, createAuthOptions(options))), 'optionalAccess', async _ => _.idToken]);
24
+ if (idToken) {
25
+ try {
26
+ await fetch(
27
+ `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}/protocol/openid-connect/logout?id_token_hint=${idToken}&post_logout_redirect_uri=${encodeURIComponent(
28
+ process.env.NEXTAUTH_URL || ""
29
+ )}`,
30
+ { method: "GET" }
31
+ );
32
+ } catch (err) {
33
+ logger.error(err);
34
+ return new NextResponse(null, { status: 500 });
35
+ }
36
+ }
37
+ return new NextResponse();
38
+ }
39
+ };
40
+ }
41
+ function createAuthOptions(options = {}) {
42
+ if (_nextAuth)
43
+ return _nextAuth;
44
+ _nextAuth = {
45
+ ...options.nextAuth,
46
+ providers: [
47
+ KeycloakProvider({
48
+ clientId: process.env.KEYCLOAK_CLIENT_ID || "",
49
+ clientSecret: process.env.KEYCLOAK_CLIENT_SECRET || "",
50
+ issuer: `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}`,
51
+ ...options.keycloakProvider
52
+ }),
53
+ ..._optionalChain([options, 'access', _2 => _2.nextAuth, 'optionalAccess', _3 => _3.providers]) || []
54
+ ],
55
+ callbacks: {
56
+ ..._optionalChain([options, 'access', _4 => _4.nextAuth, 'optionalAccess', _5 => _5.callbacks]),
57
+ async jwt(params) {
58
+ if (typeof _optionalChain([options, 'access', _6 => _6.nextAuth, 'optionalAccess', _7 => _7.callbacks, 'optionalAccess', _8 => _8.jwt]) === "function") {
59
+ return _optionalChain([options, 'access', _9 => _9.nextAuth, 'optionalAccess', _10 => _10.callbacks, 'access', _11 => _11.jwt, 'call', _12 => _12(params)]);
60
+ }
61
+ const { token, account } = params;
62
+ if (account) {
63
+ const decoded = _jwtdecode.jwtDecode.call(void 0, account.access_token || "");
64
+ token.decoded = decoded;
65
+ token.accessToken = account.access_token;
66
+ token.idToken = account.id_token;
67
+ token.expiresAt = account.expires_at;
68
+ token.refreshToken = account.refresh_token;
69
+ token.roles = _optionalChain([decoded, 'access', _13 => _13.realm_access, 'optionalAccess', _14 => _14.roles]);
70
+ return token;
71
+ } else if (Math.floor(Date.now() / 1e3) < Number(token.expiresAt)) {
72
+ return token;
73
+ } else {
74
+ try {
75
+ return refreshAccessToken(token);
76
+ } catch (err) {
77
+ return { ...token, err };
78
+ }
79
+ }
80
+ },
81
+ async session(params) {
82
+ if (typeof _optionalChain([options, 'access', _15 => _15.nextAuth, 'optionalAccess', _16 => _16.callbacks, 'optionalAccess', _17 => _17.session]) === "function") {
83
+ return options.nextAuth.callbacks.session(params);
84
+ }
85
+ const { session: nextSession, token: nextToken } = params;
86
+ const session = nextSession;
87
+ const token = nextToken;
88
+ if (token.accessToken)
89
+ session.accessToken = token.accessToken;
90
+ if (token.idToken)
91
+ session.idToken = token.idToken;
92
+ session.err = token.err;
93
+ return session;
94
+ }
95
+ }
96
+ };
97
+ return _nextAuth;
98
+ }
99
+ async function refreshAccessToken(nextToken) {
100
+ const res = await fetch(process.env.REFRESH_TOKEN_URL || "", {
101
+ method: "POST",
102
+ headers: {
103
+ "Content-Type": "application/x-www-form-urlencoded"
104
+ },
105
+ body: new URLSearchParams({
106
+ client_id: process.env.KEYCLOAK_CLIENT_ID || "",
107
+ client_secret: process.env.KEYCLOAK_CLIENT_SECRET || "",
108
+ grant_type: "refresh_token",
109
+ refresh_token: nextToken.refreshToken
110
+ })
111
+ });
112
+ const refreshToken = await res.json();
113
+ if (!res.ok)
114
+ throw refreshToken;
115
+ return {
116
+ ...nextToken,
117
+ accessToken: refreshToken.access_token,
118
+ decoded: _jwtdecode.jwtDecode.call(void 0, refreshToken.access_token),
119
+ expiresAt: Math.floor(Date.now() / 1e3) + Number(refreshToken.expires_in),
120
+ idToken: refreshToken.id_token,
121
+ refreshToken: refreshToken.refresh_token
122
+ };
123
+ }
124
+
125
+
126
+
127
+ exports.createAuthHandler = createAuthHandler; exports.createLogoutHandler = createLogoutHandler;
package/lib/routes.mjs ADDED
@@ -0,0 +1,127 @@
1
+ import {
2
+ __require
3
+ } from "./chunk-ZFXKCRJC.mjs";
4
+
5
+ // src/routes.ts
6
+ import { getServerSession } from "next-auth";
7
+ import { jwtDecode } from "jwt-decode";
8
+ var KeycloakProvider = __require("next-auth/providers/keycloak").default;
9
+ var NextAuth = __require("next-auth").default;
10
+ var NextResponse = __require("next/server").NextResponse;
11
+ var logger = console;
12
+ var _nextAuth;
13
+ function createAuthHandler(options = {}) {
14
+ const handler = NextAuth(createAuthOptions(options));
15
+ return {
16
+ GET: handler,
17
+ POST: handler
18
+ };
19
+ }
20
+ function createLogoutHandler(options = {}) {
21
+ return {
22
+ async GET() {
23
+ const idToken = (await getServerSession(createAuthOptions(options)))?.idToken;
24
+ if (idToken) {
25
+ try {
26
+ await fetch(
27
+ `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}/protocol/openid-connect/logout?id_token_hint=${idToken}&post_logout_redirect_uri=${encodeURIComponent(
28
+ process.env.NEXTAUTH_URL || ""
29
+ )}`,
30
+ { method: "GET" }
31
+ );
32
+ } catch (err) {
33
+ logger.error(err);
34
+ return new NextResponse(null, { status: 500 });
35
+ }
36
+ }
37
+ return new NextResponse();
38
+ }
39
+ };
40
+ }
41
+ function createAuthOptions(options = {}) {
42
+ if (_nextAuth)
43
+ return _nextAuth;
44
+ _nextAuth = {
45
+ ...options.nextAuth,
46
+ providers: [
47
+ KeycloakProvider({
48
+ clientId: process.env.KEYCLOAK_CLIENT_ID || "",
49
+ clientSecret: process.env.KEYCLOAK_CLIENT_SECRET || "",
50
+ issuer: `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}`,
51
+ ...options.keycloakProvider
52
+ }),
53
+ ...options.nextAuth?.providers || []
54
+ ],
55
+ callbacks: {
56
+ ...options.nextAuth?.callbacks,
57
+ async jwt(params) {
58
+ if (typeof options.nextAuth?.callbacks?.jwt === "function") {
59
+ return options.nextAuth?.callbacks.jwt(params);
60
+ }
61
+ const { token, account } = params;
62
+ if (account) {
63
+ const decoded = jwtDecode(account.access_token || "");
64
+ token.decoded = decoded;
65
+ token.accessToken = account.access_token;
66
+ token.idToken = account.id_token;
67
+ token.expiresAt = account.expires_at;
68
+ token.refreshToken = account.refresh_token;
69
+ token.roles = decoded.realm_access?.roles;
70
+ return token;
71
+ } else if (Math.floor(Date.now() / 1e3) < Number(token.expiresAt)) {
72
+ return token;
73
+ } else {
74
+ try {
75
+ return refreshAccessToken(token);
76
+ } catch (err) {
77
+ return { ...token, err };
78
+ }
79
+ }
80
+ },
81
+ async session(params) {
82
+ if (typeof options.nextAuth?.callbacks?.session === "function") {
83
+ return options.nextAuth.callbacks.session(params);
84
+ }
85
+ const { session: nextSession, token: nextToken } = params;
86
+ const session = nextSession;
87
+ const token = nextToken;
88
+ if (token.accessToken)
89
+ session.accessToken = token.accessToken;
90
+ if (token.idToken)
91
+ session.idToken = token.idToken;
92
+ session.err = token.err;
93
+ return session;
94
+ }
95
+ }
96
+ };
97
+ return _nextAuth;
98
+ }
99
+ async function refreshAccessToken(nextToken) {
100
+ const res = await fetch(process.env.REFRESH_TOKEN_URL || "", {
101
+ method: "POST",
102
+ headers: {
103
+ "Content-Type": "application/x-www-form-urlencoded"
104
+ },
105
+ body: new URLSearchParams({
106
+ client_id: process.env.KEYCLOAK_CLIENT_ID || "",
107
+ client_secret: process.env.KEYCLOAK_CLIENT_SECRET || "",
108
+ grant_type: "refresh_token",
109
+ refresh_token: nextToken.refreshToken
110
+ })
111
+ });
112
+ const refreshToken = await res.json();
113
+ if (!res.ok)
114
+ throw refreshToken;
115
+ return {
116
+ ...nextToken,
117
+ accessToken: refreshToken.access_token,
118
+ decoded: jwtDecode(refreshToken.access_token),
119
+ expiresAt: Math.floor(Date.now() / 1e3) + Number(refreshToken.expires_in),
120
+ idToken: refreshToken.id_token,
121
+ refreshToken: refreshToken.refresh_token
122
+ };
123
+ }
124
+ export {
125
+ createAuthHandler,
126
+ createLogoutHandler
127
+ };
@@ -0,0 +1,3 @@
1
+ export { Session, SessionContextValue, getSession, useSession } from './session.mjs';
2
+ import 'next-auth';
3
+ import 'next-auth/react';
@@ -0,0 +1,3 @@
1
+ export { Session, SessionContextValue, getSession, useSession } from './session.js';
2
+ import 'next-auth';
3
+ import 'next-auth/react';
@@ -0,0 +1,10 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-WS4IMGVL.js');
2
+
3
+
4
+
5
+ var _chunkNH335CDKjs = require('../chunk-NH335CDK.js');
6
+ require('../chunk-P57PW2II.js');
7
+
8
+
9
+
10
+ exports.getSession = _chunkNH335CDKjs.getSession; exports.useSession = _chunkNH335CDKjs.useSession;
@@ -0,0 +1,10 @@
1
+ import "../chunk-OAUYHIWG.mjs";
2
+ import {
3
+ getSession,
4
+ useSession
5
+ } from "../chunk-FU4CT24B.mjs";
6
+ import "../chunk-ZFXKCRJC.mjs";
7
+ export {
8
+ getSession,
9
+ useSession
10
+ };
@@ -0,0 +1,18 @@
1
+ import { Session as Session$1 } from 'next-auth';
2
+ import { SessionContextValue as SessionContextValue$1, UseSessionOptions } from 'next-auth/react';
3
+
4
+ declare function getSession(): Promise<Session | null>;
5
+ type SessionContextValue<R extends boolean> = Partial<Omit<SessionContextValue$1<R> & {
6
+ session: Session;
7
+ }, 'data'>>;
8
+ declare let useSession: <R extends boolean>(options?: UseSessionOptions<R> | undefined) => Partial<Omit<SessionContextValue$1<R> & {
9
+ session: Session;
10
+ }, "data">>;
11
+ interface Session extends Session$1 {
12
+ accessToken?: string;
13
+ err?: Error;
14
+ idToken?: string;
15
+ refreshToken?: string;
16
+ }
17
+
18
+ export { type Session, type SessionContextValue, getSession, useSession };
@@ -0,0 +1,18 @@
1
+ import { Session as Session$1 } from 'next-auth';
2
+ import { SessionContextValue as SessionContextValue$1, UseSessionOptions } from 'next-auth/react';
3
+
4
+ declare function getSession(): Promise<Session | null>;
5
+ type SessionContextValue<R extends boolean> = Partial<Omit<SessionContextValue$1<R> & {
6
+ session: Session;
7
+ }, 'data'>>;
8
+ declare let useSession: <R extends boolean>(options?: UseSessionOptions<R> | undefined) => Partial<Omit<SessionContextValue$1<R> & {
9
+ session: Session;
10
+ }, "data">>;
11
+ interface Session extends Session$1 {
12
+ accessToken?: string;
13
+ err?: Error;
14
+ idToken?: string;
15
+ refreshToken?: string;
16
+ }
17
+
18
+ export { type Session, type SessionContextValue, getSession, useSession };
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkNH335CDKjs = require('../chunk-NH335CDK.js');
5
+ require('../chunk-P57PW2II.js');
6
+
7
+
8
+
9
+ exports.getSession = _chunkNH335CDKjs.getSession; exports.useSession = _chunkNH335CDKjs.useSession;
@@ -0,0 +1,9 @@
1
+ import {
2
+ getSession,
3
+ useSession
4
+ } from "../chunk-FU4CT24B.mjs";
5
+ import "../chunk-ZFXKCRJC.mjs";
6
+ export {
7
+ getSession,
8
+ useSession
9
+ };
@@ -0,0 +1,8 @@
1
+ import { SessionContextValue } from './session.mjs';
2
+ import { UseSessionOptions } from 'next-auth/react';
3
+ import 'next-auth';
4
+
5
+ declare function getSession(): Promise<null>;
6
+ declare function useSession<R extends boolean>(_options?: UseSessionOptions<R>): SessionContextValue<R>;
7
+
8
+ export { getSession, useSession };
@@ -0,0 +1,8 @@
1
+ import { SessionContextValue } from './session.js';
2
+ import { UseSessionOptions } from 'next-auth/react';
3
+ import 'next-auth';
4
+
5
+ declare function getSession(): Promise<null>;
6
+ declare function useSession<R extends boolean>(_options?: UseSessionOptions<R>): SessionContextValue<R>;
7
+
8
+ export { getSession, useSession };
@@ -0,0 +1,13 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-P57PW2II.js');
2
+
3
+ // src/session/session.native.ts
4
+ async function getSession() {
5
+ return null;
6
+ }
7
+ function useSession(_options) {
8
+ return {};
9
+ }
10
+
11
+
12
+
13
+ exports.getSession = getSession; exports.useSession = useSession;
@@ -0,0 +1,13 @@
1
+ import "../chunk-ZFXKCRJC.mjs";
2
+
3
+ // src/session/session.native.ts
4
+ async function getSession() {
5
+ return null;
6
+ }
7
+ function useSession(_options) {
8
+ return {};
9
+ }
10
+ export {
11
+ getSession,
12
+ useSession
13
+ };
@@ -1,3 +1,4 @@
1
+ declare const persist: boolean;
1
2
  declare function useAuthState(): {
2
3
  idToken: string;
3
4
  refreshToken: string;
@@ -8,4 +9,4 @@ declare function useAuthState(): {
8
9
  setToken: (value: string) => void;
9
10
  } & Record<string, Function>;
10
11
 
11
- export { useAuthState };
12
+ export { persist, useAuthState };
@@ -1,3 +1,4 @@
1
+ declare const persist: boolean;
1
2
  declare function useAuthState(): {
2
3
  idToken: string;
3
4
  refreshToken: string;
@@ -8,4 +9,4 @@ declare function useAuthState(): {
8
9
  setToken: (value: string) => void;
9
10
  } & Record<string, Function>;
10
11
 
11
- export { useAuthState };
12
+ export { persist, useAuthState };
package/lib/state.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunkA2V2S4HPjs = require('./chunk-A2V2S4HP.js');
5
+ require('./chunk-P57PW2II.js');
6
+
7
+
8
+
9
+ exports.persist = _chunkA2V2S4HPjs.persist; exports.useAuthState = _chunkA2V2S4HPjs.useAuthState;
package/lib/state.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ persist,
3
+ useAuthState
4
+ } from "./chunk-WMH347OL.mjs";
5
+ import "./chunk-ZFXKCRJC.mjs";
6
+ export {
7
+ persist,
8
+ useAuthState
9
+ };
@@ -0,0 +1,17 @@
1
+ import { KeycloakTokenParsed } from 'keycloak-js';
2
+
3
+ declare function validToken(token?: string | boolean, refreshToken?: string | boolean): string | boolean | undefined;
4
+ declare function isTokenValid(token: string): boolean;
5
+ interface TokenParsed extends KeycloakTokenParsed {
6
+ jti?: string;
7
+ sid?: string;
8
+ typ?: 'Bearer' | string;
9
+ }
10
+ interface AccessTokenParsed extends TokenParsed {
11
+ email?: string;
12
+ email_verified?: boolean;
13
+ preferred_username?: string;
14
+ scope?: string;
15
+ }
16
+
17
+ export { type AccessTokenParsed, type TokenParsed, isTokenValid, validToken };
package/lib/token.d.ts ADDED
@@ -0,0 +1,17 @@
1
+ import { KeycloakTokenParsed } from 'keycloak-js';
2
+
3
+ declare function validToken(token?: string | boolean, refreshToken?: string | boolean): string | boolean | undefined;
4
+ declare function isTokenValid(token: string): boolean;
5
+ interface TokenParsed extends KeycloakTokenParsed {
6
+ jti?: string;
7
+ sid?: string;
8
+ typ?: 'Bearer' | string;
9
+ }
10
+ interface AccessTokenParsed extends TokenParsed {
11
+ email?: string;
12
+ email_verified?: boolean;
13
+ preferred_username?: string;
14
+ scope?: string;
15
+ }
16
+
17
+ export { type AccessTokenParsed, type TokenParsed, isTokenValid, validToken };
package/lib/token.js ADDED
@@ -0,0 +1,9 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+
4
+ var _chunk2VDDEPLFjs = require('./chunk-2VDDEPLF.js');
5
+ require('./chunk-P57PW2II.js');
6
+
7
+
8
+
9
+ exports.isTokenValid = _chunk2VDDEPLFjs.isTokenValid; exports.validToken = _chunk2VDDEPLFjs.validToken;
@@ -1,8 +1,8 @@
1
1
  import {
2
2
  isTokenValid,
3
3
  validToken
4
- } from "./chunk-7MTPH6XK.mjs";
5
- import "./chunk-RPUOO7AV.mjs";
4
+ } from "./chunk-6FRYV4MK.mjs";
5
+ import "./chunk-ZFXKCRJC.mjs";
6
6
  export {
7
7
  isTokenValid,
8
8
  validToken
package/lib/types.d.mts CHANGED
@@ -12,6 +12,9 @@ declare global {
12
12
  };
13
13
  }
14
14
  }
15
- declare const _default: null;
15
+ interface KeycloakMock {
16
+ email?: string;
17
+ username: string;
18
+ }
16
19
 
17
- export { _default as default };
20
+ export type { KeycloakMock };
package/lib/types.d.ts CHANGED
@@ -12,6 +12,9 @@ declare global {
12
12
  };
13
13
  }
14
14
  }
15
- declare const _default: null;
15
+ interface KeycloakMock {
16
+ email?: string;
17
+ username: string;
18
+ }
16
19
 
17
- export { _default as default };
20
+ export type { KeycloakMock };
package/lib/types.js CHANGED
@@ -1,8 +1 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- require("./chunk-XEO3YXBM.js");
6
- // src/types.ts
7
- var types_default = null;
8
- exports.default = types_default;
1
+ "use strict";require('./chunk-6F4PWJZI.js');
package/lib/types.mjs CHANGED
@@ -1,7 +1 @@
1
- import "./chunk-RPUOO7AV.mjs";
2
-
3
- // src/types.ts
4
- var types_default = null;
5
- export {
6
- types_default as default
7
- };
1
+ import "./chunk-WBQAMGXK.mjs";