@multiplatform.one/keycloak 0.7.16 → 1.0.0

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 (158) hide show
  1. package/lib/@types/expoKeycloakAuth.d.d.mts +25 -0
  2. package/lib/@types/expoKeycloakAuth.d.d.ts +25 -0
  3. package/lib/@types/expoKeycloakAuth.d.js +1 -0
  4. package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
  5. package/lib/Authenticated.d.mts +32 -0
  6. package/lib/Authenticated.d.ts +32 -0
  7. package/lib/Authenticated.js +20 -0
  8. package/lib/Authenticated.mjs +20 -0
  9. package/lib/apollo.d.mts +7 -0
  10. package/lib/apollo.d.ts +7 -0
  11. package/lib/apollo.js +15 -0
  12. package/lib/apollo.mjs +15 -0
  13. package/lib/authConfig.d.mts +12 -0
  14. package/lib/authConfig.d.ts +12 -0
  15. package/lib/authConfig.js +9 -0
  16. package/lib/authConfig.mjs +9 -0
  17. package/lib/chunk-2L5TXBDK.mjs +7 -0
  18. package/lib/chunk-2MYOFYAK.mjs +53 -0
  19. package/lib/chunk-2VDDEPLF.js +27 -0
  20. package/lib/chunk-2VGMJ7WP.js +34 -0
  21. package/lib/chunk-32AVT4GA.js +9 -0
  22. package/lib/chunk-3ZTSLDX7.js +13 -0
  23. package/lib/chunk-6APOOEW6.js +28 -0
  24. package/lib/chunk-6F4PWJZI.js +1 -0
  25. package/lib/chunk-6FRYV4MK.mjs +27 -0
  26. package/lib/chunk-6WBHOY7M.js +50 -0
  27. package/lib/chunk-74FSREBY.js +161 -0
  28. package/lib/chunk-A2V2S4HP.js +22 -0
  29. package/lib/chunk-BUZONXAW.js +1 -0
  30. package/lib/chunk-C6TOWKPW.mjs +245 -0
  31. package/lib/chunk-DNEUOHZQ.mjs +28 -0
  32. package/lib/chunk-EGCPD3BX.js +51 -0
  33. package/lib/chunk-HH32BME2.mjs +0 -0
  34. package/lib/chunk-HTWZLBA4.mjs +13 -0
  35. package/lib/chunk-I5FNGKQ6.js +16 -0
  36. package/lib/chunk-IGSEESI3.mjs +51 -0
  37. package/lib/chunk-JAFUI2JQ.mjs +9 -0
  38. package/lib/chunk-JPQI72HR.mjs +0 -0
  39. package/lib/chunk-KWNIT4G4.mjs +34 -0
  40. package/lib/chunk-L3HTVJ4B.mjs +13 -0
  41. package/lib/chunk-MDAAMGTE.js +1 -0
  42. package/lib/chunk-NQMFZ6RW.mjs +50 -0
  43. package/lib/chunk-OAUYHIWG.mjs +0 -0
  44. package/lib/chunk-OBB23GPX.mjs +0 -0
  45. package/lib/chunk-OYWXU5N7.mjs +161 -0
  46. package/lib/chunk-P57PW2II.js +11 -0
  47. package/lib/chunk-TUJRPTZE.js +13 -0
  48. package/lib/chunk-UESWAK47.mjs +0 -0
  49. package/lib/chunk-UKSHA3X3.mjs +16 -0
  50. package/lib/chunk-VS4M7GMO.js +1 -0
  51. package/lib/chunk-W4LGQZMF.js +245 -0
  52. package/lib/chunk-WBQAMGXK.mjs +0 -0
  53. package/lib/chunk-WMH347OL.mjs +22 -0
  54. package/lib/chunk-WS4IMGVL.js +1 -0
  55. package/lib/chunk-YACGLW5Q.js +7 -0
  56. package/lib/chunk-YYYDFAI4.js +53 -0
  57. package/lib/chunk-ZCBD6HWK.js +1 -0
  58. package/lib/chunk-ZFXKCRJC.mjs +11 -0
  59. package/lib/hooks/index.d.mts +5 -0
  60. package/lib/hooks/index.d.ts +5 -0
  61. package/lib/hooks/index.js +19 -0
  62. package/lib/hooks/index.mjs +19 -0
  63. package/lib/hooks/useAuthConfig.d.mts +6 -0
  64. package/lib/hooks/useAuthConfig.d.ts +6 -0
  65. package/lib/hooks/useAuthConfig.js +8 -0
  66. package/lib/hooks/useAuthConfig.mjs +8 -0
  67. package/lib/hooks/useTokensFromQuery/index.d.mts +3 -0
  68. package/lib/hooks/useTokensFromQuery/index.d.ts +3 -0
  69. package/lib/hooks/useTokensFromQuery/index.js +7 -0
  70. package/lib/hooks/useTokensFromQuery/index.mjs +7 -0
  71. package/lib/hooks/useTokensFromQuery/index.native.d.mts +3 -0
  72. package/lib/hooks/useTokensFromQuery/index.native.d.ts +3 -0
  73. package/lib/hooks/useTokensFromQuery/index.native.js +7 -0
  74. package/lib/hooks/useTokensFromQuery/index.native.mjs +7 -0
  75. package/lib/hooks/useTokensFromState.d.mts +3 -0
  76. package/lib/hooks/useTokensFromState.d.ts +3 -0
  77. package/lib/hooks/useTokensFromState.js +9 -0
  78. package/lib/hooks/useTokensFromState.mjs +9 -0
  79. package/lib/index.d.mts +18 -0
  80. package/lib/index.d.ts +18 -0
  81. package/lib/index.js +70 -0
  82. package/lib/index.mjs +70 -0
  83. package/lib/keycloak/context.d.mts +12 -0
  84. package/lib/keycloak/context.d.ts +12 -0
  85. package/lib/keycloak/context.js +7 -0
  86. package/lib/keycloak/context.mjs +7 -0
  87. package/lib/keycloak/index.d.mts +7 -0
  88. package/lib/keycloak/index.d.ts +7 -0
  89. package/lib/keycloak/index.js +14 -0
  90. package/lib/keycloak/index.mjs +14 -0
  91. package/lib/keycloak/keycloak.d.mts +37 -0
  92. package/lib/keycloak/keycloak.d.ts +37 -0
  93. package/lib/keycloak/keycloak.js +13 -0
  94. package/lib/keycloak/keycloak.mjs +13 -0
  95. package/lib/keycloak/keycloak.native.d.mts +33 -0
  96. package/lib/keycloak/keycloak.native.d.ts +33 -0
  97. package/lib/keycloak/keycloak.native.js +134 -0
  98. package/lib/keycloak/keycloak.native.mjs +134 -0
  99. package/lib/provider/AfterAuth.d.mts +28 -0
  100. package/lib/provider/AfterAuth.d.ts +28 -0
  101. package/lib/provider/AfterAuth.js +18 -0
  102. package/lib/provider/AfterAuth.mjs +18 -0
  103. package/lib/provider/AuthProvider/AuthProvider.d.mts +37 -0
  104. package/lib/provider/AuthProvider/AuthProvider.d.ts +37 -0
  105. package/lib/provider/AuthProvider/AuthProvider.js +19 -0
  106. package/lib/provider/AuthProvider/AuthProvider.mjs +19 -0
  107. package/lib/provider/AuthProvider/AuthProvider.native.d.mts +29 -0
  108. package/lib/provider/AuthProvider/AuthProvider.native.d.ts +29 -0
  109. package/lib/provider/AuthProvider/AuthProvider.native.js +25 -0
  110. package/lib/provider/AuthProvider/AuthProvider.native.mjs +25 -0
  111. package/lib/provider/AuthProvider/index.d.mts +4 -0
  112. package/lib/provider/AuthProvider/index.d.ts +4 -0
  113. package/lib/provider/AuthProvider/index.js +20 -0
  114. package/lib/provider/AuthProvider/index.mjs +20 -0
  115. package/lib/provider/KeycloakProvider.d.mts +34 -0
  116. package/lib/provider/KeycloakProvider.d.ts +34 -0
  117. package/lib/provider/KeycloakProvider.js +21 -0
  118. package/lib/provider/KeycloakProvider.mjs +21 -0
  119. package/lib/provider/index.d.mts +8 -0
  120. package/lib/provider/index.d.ts +8 -0
  121. package/lib/provider/index.js +28 -0
  122. package/lib/provider/index.mjs +28 -0
  123. package/lib/routes.d.mts +27 -0
  124. package/lib/routes.d.ts +27 -0
  125. package/lib/routes.js +127 -0
  126. package/lib/routes.mjs +127 -0
  127. package/lib/session/index.d.mts +3 -0
  128. package/lib/session/index.d.ts +3 -0
  129. package/lib/session/index.js +10 -0
  130. package/lib/session/index.mjs +10 -0
  131. package/lib/session/session.d.mts +18 -0
  132. package/lib/session/session.d.ts +18 -0
  133. package/lib/session/session.js +9 -0
  134. package/lib/session/session.mjs +9 -0
  135. package/lib/session/session.native.d.mts +8 -0
  136. package/lib/session/session.native.d.ts +8 -0
  137. package/lib/session/session.native.js +13 -0
  138. package/lib/session/session.native.mjs +13 -0
  139. package/lib/state.d.mts +12 -0
  140. package/lib/state.d.ts +12 -0
  141. package/lib/state.js +9 -0
  142. package/lib/state.mjs +9 -0
  143. package/lib/token.d.mts +17 -0
  144. package/lib/token.d.ts +17 -0
  145. package/lib/token.js +9 -0
  146. package/lib/token.mjs +9 -0
  147. package/lib/types.d.mts +20 -0
  148. package/lib/types.d.ts +20 -0
  149. package/lib/types.js +1 -0
  150. package/lib/types.mjs +1 -0
  151. package/package.json +7 -6
  152. package/src/Authenticated.tsx +2 -4
  153. package/src/apollo.ts +95 -0
  154. package/src/index.ts +1 -0
  155. package/src/keycloak/keycloak.ts +4 -3
  156. package/src/provider/AfterAuth.tsx +1 -1
  157. package/src/routes.ts +40 -38
  158. package/src/session/session.ts +19 -9
@@ -0,0 +1,34 @@
1
+ import React__default, { PropsWithChildren } from 'react';
2
+ import { AuthConfig } from '../authConfig.mjs';
3
+ import { Session } from 'next-auth';
4
+
5
+ /**
6
+ * File: /src/provider/KeycloakProvider.tsx
7
+ * Project: @multiplatform.one/keycloak
8
+ * File Created: 10-01-2024 13:56:05
9
+ * Author: Clay Risser
10
+ * -----
11
+ * BitSpur (c) Copyright 2021 - 2024
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+
26
+ interface KeycloakProviderProps extends PropsWithChildren, AuthConfig {
27
+ baseUrl?: string;
28
+ clientId?: string;
29
+ realm?: string;
30
+ session?: Session;
31
+ }
32
+ declare function KeycloakProvider({ children, debug, realm, clientId, baseUrl, session }: KeycloakProviderProps): React__default.JSX.Element;
33
+
34
+ export { KeycloakProvider, type KeycloakProviderProps };
@@ -0,0 +1,34 @@
1
+ import React__default, { PropsWithChildren } from 'react';
2
+ import { AuthConfig } from '../authConfig.js';
3
+ import { Session } from 'next-auth';
4
+
5
+ /**
6
+ * File: /src/provider/KeycloakProvider.tsx
7
+ * Project: @multiplatform.one/keycloak
8
+ * File Created: 10-01-2024 13:56:05
9
+ * Author: Clay Risser
10
+ * -----
11
+ * BitSpur (c) Copyright 2021 - 2024
12
+ *
13
+ * Licensed under the Apache License, Version 2.0 (the "License");
14
+ * you may not use this file except in compliance with the License.
15
+ * You may obtain a copy of the License at
16
+ *
17
+ * http://www.apache.org/licenses/LICENSE-2.0
18
+ *
19
+ * Unless required by applicable law or agreed to in writing, software
20
+ * distributed under the License is distributed on an "AS IS" BASIS,
21
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
22
+ * See the License for the specific language governing permissions and
23
+ * limitations under the License.
24
+ */
25
+
26
+ interface KeycloakProviderProps extends PropsWithChildren, AuthConfig {
27
+ baseUrl?: string;
28
+ clientId?: string;
29
+ realm?: string;
30
+ session?: Session;
31
+ }
32
+ declare function KeycloakProvider({ children, debug, realm, clientId, baseUrl, session }: KeycloakProviderProps): React__default.JSX.Element;
33
+
34
+ export { KeycloakProvider, type KeycloakProviderProps };
@@ -0,0 +1,21 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
+
3
+ var _chunk6APOOEW6js = require('../chunk-6APOOEW6.js');
4
+ require('../chunk-MDAAMGTE.js');
5
+ require('../chunk-W4LGQZMF.js');
6
+ require('../chunk-EGCPD3BX.js');
7
+ require('../chunk-ZCBD6HWK.js');
8
+ require('../chunk-TUJRPTZE.js');
9
+ require('../chunk-3ZTSLDX7.js');
10
+ require('../chunk-I5FNGKQ6.js');
11
+ require('../chunk-VS4M7GMO.js');
12
+ require('../chunk-74FSREBY.js');
13
+ require('../chunk-YACGLW5Q.js');
14
+ require('../chunk-2VGMJ7WP.js');
15
+ require('../chunk-32AVT4GA.js');
16
+ require('../chunk-A2V2S4HP.js');
17
+ require('../chunk-2VDDEPLF.js');
18
+ require('../chunk-P57PW2II.js');
19
+
20
+
21
+ exports.KeycloakProvider = _chunk6APOOEW6js.KeycloakProvider;
@@ -0,0 +1,21 @@
1
+ import {
2
+ KeycloakProvider
3
+ } from "../chunk-DNEUOHZQ.mjs";
4
+ import "../chunk-JPQI72HR.mjs";
5
+ import "../chunk-C6TOWKPW.mjs";
6
+ import "../chunk-IGSEESI3.mjs";
7
+ import "../chunk-HH32BME2.mjs";
8
+ import "../chunk-L3HTVJ4B.mjs";
9
+ import "../chunk-HTWZLBA4.mjs";
10
+ import "../chunk-UKSHA3X3.mjs";
11
+ import "../chunk-OBB23GPX.mjs";
12
+ import "../chunk-OYWXU5N7.mjs";
13
+ import "../chunk-2L5TXBDK.mjs";
14
+ import "../chunk-KWNIT4G4.mjs";
15
+ import "../chunk-JAFUI2JQ.mjs";
16
+ import "../chunk-WMH347OL.mjs";
17
+ import "../chunk-6FRYV4MK.mjs";
18
+ import "../chunk-ZFXKCRJC.mjs";
19
+ export {
20
+ KeycloakProvider
21
+ };
@@ -0,0 +1,8 @@
1
+ export { AfterAuth, AfterAuthProps } from './AfterAuth.mjs';
2
+ export { AuthProvider, AuthProviderProps, MessageSchema } from './AuthProvider/AuthProvider.mjs';
3
+ export { KeycloakProvider, KeycloakProviderProps } from './KeycloakProvider.mjs';
4
+ import 'react';
5
+ import 'keycloak-js';
6
+ import 'next-auth/react';
7
+ import '../authConfig.mjs';
8
+ import 'next-auth';
@@ -0,0 +1,8 @@
1
+ export { AfterAuth, AfterAuthProps } from './AfterAuth.js';
2
+ export { AuthProvider, AuthProviderProps, MessageSchema } from './AuthProvider/AuthProvider.js';
3
+ export { KeycloakProvider, KeycloakProviderProps } from './KeycloakProvider.js';
4
+ import 'react';
5
+ import 'keycloak-js';
6
+ import 'next-auth/react';
7
+ import '../authConfig.js';
8
+ import 'next-auth';
@@ -0,0 +1,28 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-BUZONXAW.js');
2
+
3
+
4
+ var _chunk6APOOEW6js = require('../chunk-6APOOEW6.js');
5
+ require('../chunk-MDAAMGTE.js');
6
+
7
+
8
+ var _chunkW4LGQZMFjs = require('../chunk-W4LGQZMF.js');
9
+
10
+
11
+ var _chunkEGCPD3BXjs = require('../chunk-EGCPD3BX.js');
12
+ require('../chunk-ZCBD6HWK.js');
13
+ require('../chunk-TUJRPTZE.js');
14
+ require('../chunk-3ZTSLDX7.js');
15
+ require('../chunk-I5FNGKQ6.js');
16
+ require('../chunk-VS4M7GMO.js');
17
+ require('../chunk-74FSREBY.js');
18
+ require('../chunk-YACGLW5Q.js');
19
+ require('../chunk-2VGMJ7WP.js');
20
+ require('../chunk-32AVT4GA.js');
21
+ require('../chunk-A2V2S4HP.js');
22
+ require('../chunk-2VDDEPLF.js');
23
+ require('../chunk-P57PW2II.js');
24
+
25
+
26
+
27
+
28
+ exports.AfterAuth = _chunkEGCPD3BXjs.AfterAuth; exports.AuthProvider = _chunkW4LGQZMFjs.AuthProvider; exports.KeycloakProvider = _chunk6APOOEW6js.KeycloakProvider;
@@ -0,0 +1,28 @@
1
+ import "../chunk-UESWAK47.mjs";
2
+ import {
3
+ KeycloakProvider
4
+ } from "../chunk-DNEUOHZQ.mjs";
5
+ import "../chunk-JPQI72HR.mjs";
6
+ import {
7
+ AuthProvider
8
+ } from "../chunk-C6TOWKPW.mjs";
9
+ import {
10
+ AfterAuth
11
+ } from "../chunk-IGSEESI3.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-OYWXU5N7.mjs";
18
+ import "../chunk-2L5TXBDK.mjs";
19
+ import "../chunk-KWNIT4G4.mjs";
20
+ import "../chunk-JAFUI2JQ.mjs";
21
+ import "../chunk-WMH347OL.mjs";
22
+ import "../chunk-6FRYV4MK.mjs";
23
+ import "../chunk-ZFXKCRJC.mjs";
24
+ export {
25
+ AfterAuth,
26
+ AuthProvider,
27
+ KeycloakProvider
28
+ };
@@ -0,0 +1,27 @@
1
+ import * as next_server from 'next/server';
2
+ import { AccessTokenParsed } from './token.mjs';
3
+ import { AuthOptions } from 'next-auth';
4
+ import { JWT } from 'next-auth/jwt';
5
+ import { OAuthUserConfig } from 'next-auth/providers';
6
+ import 'keycloak-js';
7
+
8
+ declare function createAuthHandler(options?: AuthOptions): any;
9
+ declare function createLogoutHandler(options?: AuthOptions): {
10
+ GET(): Promise<next_server.NextResponse<unknown>>;
11
+ };
12
+ declare function createNextAuthOptions(options?: CreateAuthHandlerOptions): AuthOptions;
13
+ interface CreateAuthHandlerOptions {
14
+ keycloakProvider?: Partial<OAuthUserConfig<any>>;
15
+ nextAuth?: AuthOptions;
16
+ }
17
+ interface NextToken extends JWT {
18
+ accessToken?: string;
19
+ decoded: AccessTokenParsed;
20
+ err?: Error;
21
+ expiresAt: number;
22
+ idToken?: string;
23
+ refreshToken: string;
24
+ roles: string[];
25
+ }
26
+
27
+ export { type CreateAuthHandlerOptions, type NextToken, createAuthHandler, createLogoutHandler, createNextAuthOptions };
@@ -0,0 +1,27 @@
1
+ import * as next_server from 'next/server';
2
+ import { AccessTokenParsed } from './token.js';
3
+ import { AuthOptions } from 'next-auth';
4
+ import { JWT } from 'next-auth/jwt';
5
+ import { OAuthUserConfig } from 'next-auth/providers';
6
+ import 'keycloak-js';
7
+
8
+ declare function createAuthHandler(options?: AuthOptions): any;
9
+ declare function createLogoutHandler(options?: AuthOptions): {
10
+ GET(): Promise<next_server.NextResponse<unknown>>;
11
+ };
12
+ declare function createNextAuthOptions(options?: CreateAuthHandlerOptions): AuthOptions;
13
+ interface CreateAuthHandlerOptions {
14
+ keycloakProvider?: Partial<OAuthUserConfig<any>>;
15
+ nextAuth?: AuthOptions;
16
+ }
17
+ interface NextToken extends JWT {
18
+ accessToken?: string;
19
+ decoded: AccessTokenParsed;
20
+ err?: Error;
21
+ expiresAt: number;
22
+ idToken?: string;
23
+ refreshToken: string;
24
+ roles: string[];
25
+ }
26
+
27
+ export { type CreateAuthHandlerOptions, type NextToken, createAuthHandler, createLogoutHandler, createNextAuthOptions };
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;
10
+ var NextAuth = _chunkP57PW2IIjs.__require.call(void 0, "next-auth").default;
11
+ var NextResponse = _chunkP57PW2IIjs.__require.call(void 0, "next/server").NextResponse;
12
+ var logger = console;
13
+ function createAuthHandler(options = createNextAuthOptions()) {
14
+ return NextAuth(options);
15
+ }
16
+ function createLogoutHandler(options = createNextAuthOptions()) {
17
+ return {
18
+ async GET() {
19
+ const idToken = await _asyncOptionalChain([(await _nextauth.getServerSession.call(void 0, options)), 'optionalAccess', async _ => _.idToken]);
20
+ if (idToken) {
21
+ try {
22
+ await fetch(
23
+ `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}/protocol/openid-connect/logout?id_token_hint=${idToken}&post_logout_redirect_uri=${encodeURIComponent(
24
+ process.env.NEXTAUTH_URL || ""
25
+ )}`,
26
+ { method: "GET" }
27
+ );
28
+ } catch (err) {
29
+ logger.error(err);
30
+ return new NextResponse(null, { status: 500 });
31
+ }
32
+ }
33
+ return new NextResponse();
34
+ }
35
+ };
36
+ }
37
+ function createNextAuthOptions(options = {}) {
38
+ if (_nextAuth)
39
+ return _nextAuth;
40
+ _nextAuth = {
41
+ ...options.nextAuth,
42
+ providers: [
43
+ KeycloakProvider({
44
+ clientId: process.env.KEYCLOAK_CLIENT_ID || "",
45
+ clientSecret: process.env.KEYCLOAK_CLIENT_SECRET || "",
46
+ issuer: `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}`,
47
+ ...options.keycloakProvider
48
+ }),
49
+ ..._optionalChain([options, 'access', _2 => _2.nextAuth, 'optionalAccess', _3 => _3.providers]) || []
50
+ ],
51
+ callbacks: {
52
+ ..._optionalChain([options, 'access', _4 => _4.nextAuth, 'optionalAccess', _5 => _5.callbacks]),
53
+ async jwt(params) {
54
+ if (typeof _optionalChain([options, 'access', _6 => _6.nextAuth, 'optionalAccess', _7 => _7.callbacks, 'optionalAccess', _8 => _8.jwt]) === "function") {
55
+ return _optionalChain([options, 'access', _9 => _9.nextAuth, 'optionalAccess', _10 => _10.callbacks, 'access', _11 => _11.jwt, 'call', _12 => _12(params)]);
56
+ }
57
+ const { token, account } = params;
58
+ if (account) {
59
+ const decoded = _jwtdecode.jwtDecode.call(void 0, account.access_token || "");
60
+ token.decoded = decoded;
61
+ token.accessToken = account.access_token;
62
+ token.idToken = account.id_token;
63
+ token.expiresAt = account.expires_at;
64
+ token.refreshToken = account.refresh_token;
65
+ token.roles = _optionalChain([decoded, 'access', _13 => _13.realm_access, 'optionalAccess', _14 => _14.roles]);
66
+ return token;
67
+ } else if (Math.floor(Date.now() / 1e3) < Number(token.expiresAt)) {
68
+ return token;
69
+ } else {
70
+ try {
71
+ return refreshAccessToken(token);
72
+ } catch (err) {
73
+ return { ...token, err };
74
+ }
75
+ }
76
+ },
77
+ async session(params) {
78
+ if (typeof _optionalChain([options, 'access', _15 => _15.nextAuth, 'optionalAccess', _16 => _16.callbacks, 'optionalAccess', _17 => _17.session]) === "function") {
79
+ return options.nextAuth.callbacks.session(params);
80
+ }
81
+ const { session: nextSession, token: nextToken } = params;
82
+ const session = nextSession;
83
+ const token = nextToken;
84
+ if (token.accessToken)
85
+ session.accessToken = token.accessToken;
86
+ if (token.idToken)
87
+ session.idToken = token.idToken;
88
+ session.err = token.err;
89
+ return session;
90
+ }
91
+ }
92
+ };
93
+ return _nextAuth;
94
+ }
95
+ async function refreshAccessToken(nextToken) {
96
+ const res = await fetch(
97
+ `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}/protocol/openid-connect/token`,
98
+ {
99
+ method: "POST",
100
+ headers: {
101
+ "Content-Type": "application/x-www-form-urlencoded"
102
+ },
103
+ body: new URLSearchParams({
104
+ client_id: process.env.KEYCLOAK_CLIENT_ID || "",
105
+ client_secret: process.env.KEYCLOAK_CLIENT_SECRET || "",
106
+ grant_type: "refresh_token",
107
+ refresh_token: nextToken.refreshToken
108
+ })
109
+ }
110
+ );
111
+ const refreshToken = await res.json();
112
+ if (!res.ok)
113
+ throw refreshToken;
114
+ return {
115
+ ...nextToken,
116
+ accessToken: refreshToken.access_token,
117
+ decoded: _jwtdecode.jwtDecode.call(void 0, refreshToken.access_token),
118
+ expiresAt: Math.floor(Date.now() / 1e3) + Number(refreshToken.expires_in),
119
+ idToken: refreshToken.id_token,
120
+ refreshToken: refreshToken.refresh_token
121
+ };
122
+ }
123
+
124
+
125
+
126
+
127
+ exports.createAuthHandler = createAuthHandler; exports.createLogoutHandler = createLogoutHandler; exports.createNextAuthOptions = createNextAuthOptions;
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;
10
+ var NextAuth = __require("next-auth").default;
11
+ var NextResponse = __require("next/server").NextResponse;
12
+ var logger = console;
13
+ function createAuthHandler(options = createNextAuthOptions()) {
14
+ return NextAuth(options);
15
+ }
16
+ function createLogoutHandler(options = createNextAuthOptions()) {
17
+ return {
18
+ async GET() {
19
+ const idToken = (await getServerSession(options))?.idToken;
20
+ if (idToken) {
21
+ try {
22
+ await fetch(
23
+ `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}/protocol/openid-connect/logout?id_token_hint=${idToken}&post_logout_redirect_uri=${encodeURIComponent(
24
+ process.env.NEXTAUTH_URL || ""
25
+ )}`,
26
+ { method: "GET" }
27
+ );
28
+ } catch (err) {
29
+ logger.error(err);
30
+ return new NextResponse(null, { status: 500 });
31
+ }
32
+ }
33
+ return new NextResponse();
34
+ }
35
+ };
36
+ }
37
+ function createNextAuthOptions(options = {}) {
38
+ if (_nextAuth)
39
+ return _nextAuth;
40
+ _nextAuth = {
41
+ ...options.nextAuth,
42
+ providers: [
43
+ KeycloakProvider({
44
+ clientId: process.env.KEYCLOAK_CLIENT_ID || "",
45
+ clientSecret: process.env.KEYCLOAK_CLIENT_SECRET || "",
46
+ issuer: `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}`,
47
+ ...options.keycloakProvider
48
+ }),
49
+ ...options.nextAuth?.providers || []
50
+ ],
51
+ callbacks: {
52
+ ...options.nextAuth?.callbacks,
53
+ async jwt(params) {
54
+ if (typeof options.nextAuth?.callbacks?.jwt === "function") {
55
+ return options.nextAuth?.callbacks.jwt(params);
56
+ }
57
+ const { token, account } = params;
58
+ if (account) {
59
+ const decoded = jwtDecode(account.access_token || "");
60
+ token.decoded = decoded;
61
+ token.accessToken = account.access_token;
62
+ token.idToken = account.id_token;
63
+ token.expiresAt = account.expires_at;
64
+ token.refreshToken = account.refresh_token;
65
+ token.roles = decoded.realm_access?.roles;
66
+ return token;
67
+ } else if (Math.floor(Date.now() / 1e3) < Number(token.expiresAt)) {
68
+ return token;
69
+ } else {
70
+ try {
71
+ return refreshAccessToken(token);
72
+ } catch (err) {
73
+ return { ...token, err };
74
+ }
75
+ }
76
+ },
77
+ async session(params) {
78
+ if (typeof options.nextAuth?.callbacks?.session === "function") {
79
+ return options.nextAuth.callbacks.session(params);
80
+ }
81
+ const { session: nextSession, token: nextToken } = params;
82
+ const session = nextSession;
83
+ const token = nextToken;
84
+ if (token.accessToken)
85
+ session.accessToken = token.accessToken;
86
+ if (token.idToken)
87
+ session.idToken = token.idToken;
88
+ session.err = token.err;
89
+ return session;
90
+ }
91
+ }
92
+ };
93
+ return _nextAuth;
94
+ }
95
+ async function refreshAccessToken(nextToken) {
96
+ const res = await fetch(
97
+ `${process.env.KEYCLOAK_BASE_URL}/realms/${process.env.KEYCLOAK_REALM || "master"}/protocol/openid-connect/token`,
98
+ {
99
+ method: "POST",
100
+ headers: {
101
+ "Content-Type": "application/x-www-form-urlencoded"
102
+ },
103
+ body: new URLSearchParams({
104
+ client_id: process.env.KEYCLOAK_CLIENT_ID || "",
105
+ client_secret: process.env.KEYCLOAK_CLIENT_SECRET || "",
106
+ grant_type: "refresh_token",
107
+ refresh_token: nextToken.refreshToken
108
+ })
109
+ }
110
+ );
111
+ const refreshToken = await res.json();
112
+ if (!res.ok)
113
+ throw refreshToken;
114
+ return {
115
+ ...nextToken,
116
+ accessToken: refreshToken.access_token,
117
+ decoded: jwtDecode(refreshToken.access_token),
118
+ expiresAt: Math.floor(Date.now() / 1e3) + Number(refreshToken.expires_in),
119
+ idToken: refreshToken.id_token,
120
+ refreshToken: refreshToken.refresh_token
121
+ };
122
+ }
123
+ export {
124
+ createAuthHandler,
125
+ createLogoutHandler,
126
+ createNextAuthOptions
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 _chunk2VGMJ7WPjs = require('../chunk-2VGMJ7WP.js');
6
+ require('../chunk-P57PW2II.js');
7
+
8
+
9
+
10
+ exports.getSession = _chunk2VGMJ7WPjs.getSession; exports.useSession = _chunk2VGMJ7WPjs.useSession;
@@ -0,0 +1,10 @@
1
+ import "../chunk-OAUYHIWG.mjs";
2
+ import {
3
+ getSession,
4
+ useSession
5
+ } from "../chunk-KWNIT4G4.mjs";
6
+ import "../chunk-ZFXKCRJC.mjs";
7
+ export {
8
+ getSession,
9
+ useSession
10
+ };
@@ -0,0 +1,18 @@
1
+ import { AuthOptions, Session as Session$1 } from 'next-auth';
2
+ import { GetSessionParams, SessionContextValue as SessionContextValue$1, UseSessionOptions } from 'next-auth/react';
3
+
4
+ declare function getSession(options?: AuthOptions | GetSessionParams, req?: any, res?: any): 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 { AuthOptions, Session as Session$1 } from 'next-auth';
2
+ import { GetSessionParams, SessionContextValue as SessionContextValue$1, UseSessionOptions } from 'next-auth/react';
3
+
4
+ declare function getSession(options?: AuthOptions | GetSessionParams, req?: any, res?: any): 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 _chunk2VGMJ7WPjs = require('../chunk-2VGMJ7WP.js');
5
+ require('../chunk-P57PW2II.js');
6
+
7
+
8
+
9
+ exports.getSession = _chunk2VGMJ7WPjs.getSession; exports.useSession = _chunk2VGMJ7WPjs.useSession;
@@ -0,0 +1,9 @@
1
+ import {
2
+ getSession,
3
+ useSession
4
+ } from "../chunk-KWNIT4G4.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
+ };
@@ -0,0 +1,12 @@
1
+ declare const persist: boolean;
2
+ declare function useAuthState(): {
3
+ idToken: string;
4
+ refreshToken: string;
5
+ token: string;
6
+ } & {
7
+ setIdToken: (value: string) => void;
8
+ setRefreshToken: (value: string) => void;
9
+ setToken: (value: string) => void;
10
+ } & Record<string, Function>;
11
+
12
+ export { persist, useAuthState };