@multiplatform.one/keycloak 0.7.16 → 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 (145) 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 +33 -0
  6. package/lib/Authenticated.d.ts +33 -0
  7. package/lib/Authenticated.js +20 -0
  8. package/lib/Authenticated.mjs +20 -0
  9. package/lib/authConfig.d.mts +12 -0
  10. package/lib/authConfig.d.ts +12 -0
  11. package/lib/authConfig.js +9 -0
  12. package/lib/authConfig.mjs +9 -0
  13. package/lib/chunk-2BKS6UM5.js +51 -0
  14. package/lib/chunk-2BSUCVXL.js +50 -0
  15. package/lib/chunk-2L5TXBDK.mjs +7 -0
  16. package/lib/chunk-2VDDEPLF.js +27 -0
  17. package/lib/chunk-32AVT4GA.js +9 -0
  18. package/lib/chunk-3ZTSLDX7.js +13 -0
  19. package/lib/chunk-6F4PWJZI.js +1 -0
  20. package/lib/chunk-6FRYV4MK.mjs +27 -0
  21. package/lib/chunk-A2V2S4HP.js +22 -0
  22. package/lib/chunk-BUZONXAW.js +1 -0
  23. package/lib/chunk-CGLMLNUS.mjs +245 -0
  24. package/lib/chunk-FU4CT24B.mjs +32 -0
  25. package/lib/chunk-HH32BME2.mjs +0 -0
  26. package/lib/chunk-HTWZLBA4.mjs +13 -0
  27. package/lib/chunk-I5FNGKQ6.js +16 -0
  28. package/lib/chunk-JAFUI2JQ.mjs +9 -0
  29. package/lib/chunk-JPQI72HR.mjs +0 -0
  30. package/lib/chunk-L3HTVJ4B.mjs +13 -0
  31. package/lib/chunk-MDAAMGTE.js +1 -0
  32. package/lib/chunk-NH335CDK.js +32 -0
  33. package/lib/chunk-OA5TSQWZ.mjs +50 -0
  34. package/lib/chunk-OAUYHIWG.mjs +0 -0
  35. package/lib/chunk-OBB23GPX.mjs +0 -0
  36. package/lib/chunk-OZLV3US5.js +245 -0
  37. package/lib/chunk-P57PW2II.js +11 -0
  38. package/lib/chunk-TUJRPTZE.js +13 -0
  39. package/lib/chunk-UESWAK47.mjs +0 -0
  40. package/lib/chunk-UH4K7HGE.mjs +163 -0
  41. package/lib/chunk-UKSHA3X3.mjs +16 -0
  42. package/lib/chunk-VS4M7GMO.js +1 -0
  43. package/lib/chunk-WBQAMGXK.mjs +0 -0
  44. package/lib/chunk-WMH347OL.mjs +22 -0
  45. package/lib/chunk-WS4IMGVL.js +1 -0
  46. package/lib/chunk-X53FOCXA.js +28 -0
  47. package/lib/chunk-Y23BWOII.mjs +51 -0
  48. package/lib/chunk-Y5MS3XVZ.mjs +28 -0
  49. package/lib/chunk-YACGLW5Q.js +7 -0
  50. package/lib/chunk-ZCBD6HWK.js +1 -0
  51. package/lib/chunk-ZFXKCRJC.mjs +11 -0
  52. package/lib/chunk-ZW4GP2I5.js +163 -0
  53. package/lib/hooks/index.d.mts +5 -0
  54. package/lib/hooks/index.d.ts +5 -0
  55. package/lib/hooks/index.js +19 -0
  56. package/lib/hooks/index.mjs +19 -0
  57. package/lib/hooks/useAuthConfig.d.mts +6 -0
  58. package/lib/hooks/useAuthConfig.d.ts +6 -0
  59. package/lib/hooks/useAuthConfig.js +8 -0
  60. package/lib/hooks/useAuthConfig.mjs +8 -0
  61. package/lib/hooks/useTokensFromQuery/index.d.mts +3 -0
  62. package/lib/hooks/useTokensFromQuery/index.d.ts +3 -0
  63. package/lib/hooks/useTokensFromQuery/index.js +7 -0
  64. package/lib/hooks/useTokensFromQuery/index.mjs +7 -0
  65. package/lib/hooks/useTokensFromQuery/index.native.d.mts +3 -0
  66. package/lib/hooks/useTokensFromQuery/index.native.d.ts +3 -0
  67. package/lib/hooks/useTokensFromQuery/index.native.js +7 -0
  68. package/lib/hooks/useTokensFromQuery/index.native.mjs +7 -0
  69. package/lib/hooks/useTokensFromState.d.mts +3 -0
  70. package/lib/hooks/useTokensFromState.d.ts +3 -0
  71. package/lib/hooks/useTokensFromState.js +9 -0
  72. package/lib/hooks/useTokensFromState.mjs +9 -0
  73. package/lib/index.d.mts +16 -0
  74. package/lib/index.d.ts +16 -0
  75. package/lib/index.js +62 -0
  76. package/lib/index.mjs +62 -0
  77. package/lib/keycloak/context.d.mts +12 -0
  78. package/lib/keycloak/context.d.ts +12 -0
  79. package/lib/keycloak/context.js +7 -0
  80. package/lib/keycloak/context.mjs +7 -0
  81. package/lib/keycloak/index.d.mts +7 -0
  82. package/lib/keycloak/index.d.ts +7 -0
  83. package/lib/keycloak/index.js +14 -0
  84. package/lib/keycloak/index.mjs +14 -0
  85. package/lib/keycloak/keycloak.d.mts +37 -0
  86. package/lib/keycloak/keycloak.d.ts +37 -0
  87. package/lib/keycloak/keycloak.js +13 -0
  88. package/lib/keycloak/keycloak.mjs +13 -0
  89. package/lib/keycloak/keycloak.native.d.mts +33 -0
  90. package/lib/keycloak/keycloak.native.d.ts +33 -0
  91. package/lib/keycloak/keycloak.native.js +134 -0
  92. package/lib/keycloak/keycloak.native.mjs +134 -0
  93. package/lib/provider/AfterAuth.d.mts +28 -0
  94. package/lib/provider/AfterAuth.d.ts +28 -0
  95. package/lib/provider/AfterAuth.js +18 -0
  96. package/lib/provider/AfterAuth.mjs +18 -0
  97. package/lib/provider/AuthProvider/AuthProvider.d.mts +37 -0
  98. package/lib/provider/AuthProvider/AuthProvider.d.ts +37 -0
  99. package/lib/provider/AuthProvider/AuthProvider.js +19 -0
  100. package/lib/provider/AuthProvider/AuthProvider.mjs +19 -0
  101. package/lib/provider/AuthProvider/AuthProvider.native.d.mts +29 -0
  102. package/lib/provider/AuthProvider/AuthProvider.native.d.ts +29 -0
  103. package/lib/provider/AuthProvider/AuthProvider.native.js +25 -0
  104. package/lib/provider/AuthProvider/AuthProvider.native.mjs +25 -0
  105. package/lib/provider/AuthProvider/index.d.mts +4 -0
  106. package/lib/provider/AuthProvider/index.d.ts +4 -0
  107. package/lib/provider/AuthProvider/index.js +20 -0
  108. package/lib/provider/AuthProvider/index.mjs +20 -0
  109. package/lib/provider/KeycloakProvider.d.mts +34 -0
  110. package/lib/provider/KeycloakProvider.d.ts +34 -0
  111. package/lib/provider/KeycloakProvider.js +21 -0
  112. package/lib/provider/KeycloakProvider.mjs +21 -0
  113. package/lib/provider/index.d.mts +8 -0
  114. package/lib/provider/index.d.ts +8 -0
  115. package/lib/provider/index.js +28 -0
  116. package/lib/provider/index.mjs +28 -0
  117. package/lib/routes.d.mts +28 -0
  118. package/lib/routes.d.ts +28 -0
  119. package/lib/routes.js +127 -0
  120. package/lib/routes.mjs +127 -0
  121. package/lib/session/index.d.mts +3 -0
  122. package/lib/session/index.d.ts +3 -0
  123. package/lib/session/index.js +10 -0
  124. package/lib/session/index.mjs +10 -0
  125. package/lib/session/session.d.mts +18 -0
  126. package/lib/session/session.d.ts +18 -0
  127. package/lib/session/session.js +9 -0
  128. package/lib/session/session.mjs +9 -0
  129. package/lib/session/session.native.d.mts +8 -0
  130. package/lib/session/session.native.d.ts +8 -0
  131. package/lib/session/session.native.js +13 -0
  132. package/lib/session/session.native.mjs +13 -0
  133. package/lib/state.d.mts +12 -0
  134. package/lib/state.d.ts +12 -0
  135. package/lib/state.js +9 -0
  136. package/lib/state.mjs +9 -0
  137. package/lib/token.d.mts +17 -0
  138. package/lib/token.d.ts +17 -0
  139. package/lib/token.js +9 -0
  140. package/lib/token.mjs +9 -0
  141. package/lib/types.d.mts +20 -0
  142. package/lib/types.d.ts +20 -0
  143. package/lib/types.js +1 -0
  144. package/lib/types.mjs +1 -0
  145. package/package.json +3 -3
@@ -0,0 +1,28 @@
1
+ "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-BUZONXAW.js');
2
+
3
+
4
+ var _chunkX53FOCXAjs = require('../chunk-X53FOCXA.js');
5
+ require('../chunk-MDAAMGTE.js');
6
+
7
+
8
+ var _chunkOZLV3US5js = require('../chunk-OZLV3US5.js');
9
+
10
+
11
+ var _chunk2BKS6UM5js = require('../chunk-2BKS6UM5.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-ZW4GP2I5.js');
18
+ require('../chunk-YACGLW5Q.js');
19
+ require('../chunk-NH335CDK.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 = _chunk2BKS6UM5js.AfterAuth; exports.AuthProvider = _chunkOZLV3US5js.AuthProvider; exports.KeycloakProvider = _chunkX53FOCXAjs.KeycloakProvider;
@@ -0,0 +1,28 @@
1
+ import "../chunk-UESWAK47.mjs";
2
+ import {
3
+ KeycloakProvider
4
+ } from "../chunk-Y5MS3XVZ.mjs";
5
+ import "../chunk-JPQI72HR.mjs";
6
+ import {
7
+ AuthProvider
8
+ } from "../chunk-CGLMLNUS.mjs";
9
+ import {
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";
24
+ export {
25
+ AfterAuth,
26
+ AuthProvider,
27
+ KeycloakProvider
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
+ };
@@ -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 };
package/lib/state.d.ts ADDED
@@ -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 };
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;
package/lib/token.mjs ADDED
@@ -0,0 +1,9 @@
1
+ import {
2
+ isTokenValid,
3
+ validToken
4
+ } from "./chunk-6FRYV4MK.mjs";
5
+ import "./chunk-ZFXKCRJC.mjs";
6
+ export {
7
+ isTokenValid,
8
+ validToken
9
+ };
@@ -0,0 +1,20 @@
1
+ declare global {
2
+ interface Window {
3
+ ReactNativeWebView: {
4
+ postMessage: (body: string) => unknown;
5
+ };
6
+ webkit: {
7
+ messageHandlers: {
8
+ [key: string]: {
9
+ postMessage: (body: string) => unknown;
10
+ };
11
+ };
12
+ };
13
+ }
14
+ }
15
+ interface KeycloakMock {
16
+ email?: string;
17
+ username: string;
18
+ }
19
+
20
+ export type { KeycloakMock };
package/lib/types.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ declare global {
2
+ interface Window {
3
+ ReactNativeWebView: {
4
+ postMessage: (body: string) => unknown;
5
+ };
6
+ webkit: {
7
+ messageHandlers: {
8
+ [key: string]: {
9
+ postMessage: (body: string) => unknown;
10
+ };
11
+ };
12
+ };
13
+ }
14
+ }
15
+ interface KeycloakMock {
16
+ email?: string;
17
+ username: string;
18
+ }
19
+
20
+ export type { KeycloakMock };
package/lib/types.js ADDED
@@ -0,0 +1 @@
1
+ "use strict";require('./chunk-6F4PWJZI.js');
package/lib/types.mjs ADDED
@@ -0,0 +1 @@
1
+ import "./chunk-WBQAMGXK.mjs";