@multiplatform.one/keycloak 1.0.1 → 1.0.3

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 (169) hide show
  1. package/package.json +32 -34
  2. package/routes/index.d.ts +1 -1
  3. package/routes/index.js +1 -1
  4. package/src/Authenticated.tsx +12 -13
  5. package/src/apollo.ts +1 -1
  6. package/src/authConfig.ts +2 -0
  7. package/src/hooks/useTokensFromQuery/index.ts +2 -0
  8. package/src/hooks/useTokensFromState.ts +2 -2
  9. package/{lib/@types/expoKeycloakAuth.d.d.mts → src/keycloak/config.ts} +17 -6
  10. package/src/keycloak/context.ts +3 -1
  11. package/src/keycloak/index.ts +1 -0
  12. package/src/keycloak/keycloak.native.ts +49 -15
  13. package/src/keycloak/keycloak.ts +66 -11
  14. package/src/provider/AfterAuth.tsx +2 -0
  15. package/src/provider/AuthProvider/AuthProvider.native.tsx +159 -6
  16. package/src/provider/AuthProvider/AuthProvider.tsx +66 -43
  17. package/src/provider/KeycloakProvider.tsx +12 -2
  18. package/src/routes.ts +54 -20
  19. package/src/session/session.ts +4 -15
  20. package/src/token.ts +13 -5
  21. package/lib/@types/expoKeycloakAuth.d.d.ts +0 -25
  22. package/lib/@types/expoKeycloakAuth.d.js +0 -1
  23. package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
  24. package/lib/Authenticated.d.mts +0 -32
  25. package/lib/Authenticated.d.ts +0 -32
  26. package/lib/Authenticated.js +0 -20
  27. package/lib/Authenticated.mjs +0 -20
  28. package/lib/apollo.d.mts +0 -7
  29. package/lib/apollo.d.ts +0 -7
  30. package/lib/apollo.js +0 -15
  31. package/lib/apollo.mjs +0 -15
  32. package/lib/authConfig.d.mts +0 -12
  33. package/lib/authConfig.d.ts +0 -12
  34. package/lib/authConfig.js +0 -9
  35. package/lib/authConfig.mjs +0 -9
  36. package/lib/chunk-267L3NLO.mjs +0 -53
  37. package/lib/chunk-2L5TXBDK.mjs +0 -7
  38. package/lib/chunk-2VDDEPLF.js +0 -27
  39. package/lib/chunk-2VGMJ7WP.js +0 -34
  40. package/lib/chunk-32AVT4GA.js +0 -9
  41. package/lib/chunk-3KAZ37SK.mjs +0 -51
  42. package/lib/chunk-3ZTSLDX7.js +0 -13
  43. package/lib/chunk-5CWGWY74.mjs +0 -28
  44. package/lib/chunk-6F4PWJZI.js +0 -1
  45. package/lib/chunk-6FRYV4MK.mjs +0 -27
  46. package/lib/chunk-6Q4DC5JX.mjs +0 -50
  47. package/lib/chunk-7NZPJ2EN.mjs +0 -161
  48. package/lib/chunk-A2V2S4HP.js +0 -22
  49. package/lib/chunk-BUZONXAW.js +0 -1
  50. package/lib/chunk-HH32BME2.mjs +0 -0
  51. package/lib/chunk-HTWZLBA4.mjs +0 -13
  52. package/lib/chunk-I5FNGKQ6.js +0 -16
  53. package/lib/chunk-JAFUI2JQ.mjs +0 -9
  54. package/lib/chunk-JPQI72HR.mjs +0 -0
  55. package/lib/chunk-K2FTCH55.js +0 -50
  56. package/lib/chunk-KWNIT4G4.mjs +0 -34
  57. package/lib/chunk-L3HTVJ4B.mjs +0 -13
  58. package/lib/chunk-MDAAMGTE.js +0 -1
  59. package/lib/chunk-NCIQ66UP.js +0 -51
  60. package/lib/chunk-NWZCPYQP.js +0 -161
  61. package/lib/chunk-OAUYHIWG.mjs +0 -0
  62. package/lib/chunk-OBB23GPX.mjs +0 -0
  63. package/lib/chunk-P57PW2II.js +0 -11
  64. package/lib/chunk-S5HUGQLF.js +0 -28
  65. package/lib/chunk-TUJRPTZE.js +0 -13
  66. package/lib/chunk-UESWAK47.mjs +0 -0
  67. package/lib/chunk-UKSHA3X3.mjs +0 -16
  68. package/lib/chunk-VFQKAKK4.js +0 -245
  69. package/lib/chunk-VPYXLUMD.js +0 -53
  70. package/lib/chunk-VS4M7GMO.js +0 -1
  71. package/lib/chunk-W4PGLIAZ.mjs +0 -245
  72. package/lib/chunk-WBQAMGXK.mjs +0 -0
  73. package/lib/chunk-WMH347OL.mjs +0 -22
  74. package/lib/chunk-WS4IMGVL.js +0 -1
  75. package/lib/chunk-YACGLW5Q.js +0 -7
  76. package/lib/chunk-ZCBD6HWK.js +0 -1
  77. package/lib/chunk-ZFXKCRJC.mjs +0 -11
  78. package/lib/hooks/index.d.mts +0 -5
  79. package/lib/hooks/index.d.ts +0 -5
  80. package/lib/hooks/index.js +0 -19
  81. package/lib/hooks/index.mjs +0 -19
  82. package/lib/hooks/useAuthConfig.d.mts +0 -6
  83. package/lib/hooks/useAuthConfig.d.ts +0 -6
  84. package/lib/hooks/useAuthConfig.js +0 -8
  85. package/lib/hooks/useAuthConfig.mjs +0 -8
  86. package/lib/hooks/useTokensFromQuery/index.d.mts +0 -3
  87. package/lib/hooks/useTokensFromQuery/index.d.ts +0 -3
  88. package/lib/hooks/useTokensFromQuery/index.js +0 -7
  89. package/lib/hooks/useTokensFromQuery/index.mjs +0 -7
  90. package/lib/hooks/useTokensFromQuery/index.native.d.mts +0 -3
  91. package/lib/hooks/useTokensFromQuery/index.native.d.ts +0 -3
  92. package/lib/hooks/useTokensFromQuery/index.native.js +0 -7
  93. package/lib/hooks/useTokensFromQuery/index.native.mjs +0 -7
  94. package/lib/hooks/useTokensFromState.d.mts +0 -3
  95. package/lib/hooks/useTokensFromState.d.ts +0 -3
  96. package/lib/hooks/useTokensFromState.js +0 -9
  97. package/lib/hooks/useTokensFromState.mjs +0 -9
  98. package/lib/index.d.mts +0 -18
  99. package/lib/index.d.ts +0 -18
  100. package/lib/index.js +0 -70
  101. package/lib/index.mjs +0 -70
  102. package/lib/keycloak/context.d.mts +0 -12
  103. package/lib/keycloak/context.d.ts +0 -12
  104. package/lib/keycloak/context.js +0 -7
  105. package/lib/keycloak/context.mjs +0 -7
  106. package/lib/keycloak/index.d.mts +0 -7
  107. package/lib/keycloak/index.d.ts +0 -7
  108. package/lib/keycloak/index.js +0 -14
  109. package/lib/keycloak/index.mjs +0 -14
  110. package/lib/keycloak/keycloak.d.mts +0 -37
  111. package/lib/keycloak/keycloak.d.ts +0 -37
  112. package/lib/keycloak/keycloak.js +0 -13
  113. package/lib/keycloak/keycloak.mjs +0 -13
  114. package/lib/keycloak/keycloak.native.d.mts +0 -33
  115. package/lib/keycloak/keycloak.native.d.ts +0 -33
  116. package/lib/keycloak/keycloak.native.js +0 -134
  117. package/lib/keycloak/keycloak.native.mjs +0 -134
  118. package/lib/provider/AfterAuth.d.mts +0 -28
  119. package/lib/provider/AfterAuth.d.ts +0 -28
  120. package/lib/provider/AfterAuth.js +0 -18
  121. package/lib/provider/AfterAuth.mjs +0 -18
  122. package/lib/provider/AuthProvider/AuthProvider.d.mts +0 -37
  123. package/lib/provider/AuthProvider/AuthProvider.d.ts +0 -37
  124. package/lib/provider/AuthProvider/AuthProvider.js +0 -19
  125. package/lib/provider/AuthProvider/AuthProvider.mjs +0 -19
  126. package/lib/provider/AuthProvider/AuthProvider.native.d.mts +0 -29
  127. package/lib/provider/AuthProvider/AuthProvider.native.d.ts +0 -29
  128. package/lib/provider/AuthProvider/AuthProvider.native.js +0 -25
  129. package/lib/provider/AuthProvider/AuthProvider.native.mjs +0 -25
  130. package/lib/provider/AuthProvider/index.d.mts +0 -4
  131. package/lib/provider/AuthProvider/index.d.ts +0 -4
  132. package/lib/provider/AuthProvider/index.js +0 -20
  133. package/lib/provider/AuthProvider/index.mjs +0 -20
  134. package/lib/provider/KeycloakProvider.d.mts +0 -34
  135. package/lib/provider/KeycloakProvider.d.ts +0 -34
  136. package/lib/provider/KeycloakProvider.js +0 -21
  137. package/lib/provider/KeycloakProvider.mjs +0 -21
  138. package/lib/provider/index.d.mts +0 -8
  139. package/lib/provider/index.d.ts +0 -8
  140. package/lib/provider/index.js +0 -28
  141. package/lib/provider/index.mjs +0 -28
  142. package/lib/routes.d.mts +0 -27
  143. package/lib/routes.d.ts +0 -27
  144. package/lib/routes.js +0 -127
  145. package/lib/routes.mjs +0 -127
  146. package/lib/session/index.d.mts +0 -3
  147. package/lib/session/index.d.ts +0 -3
  148. package/lib/session/index.js +0 -10
  149. package/lib/session/index.mjs +0 -10
  150. package/lib/session/session.d.mts +0 -18
  151. package/lib/session/session.d.ts +0 -18
  152. package/lib/session/session.js +0 -9
  153. package/lib/session/session.mjs +0 -9
  154. package/lib/session/session.native.d.mts +0 -8
  155. package/lib/session/session.native.d.ts +0 -8
  156. package/lib/session/session.native.js +0 -13
  157. package/lib/session/session.native.mjs +0 -13
  158. package/lib/state.d.mts +0 -12
  159. package/lib/state.d.ts +0 -12
  160. package/lib/state.js +0 -9
  161. package/lib/state.mjs +0 -9
  162. package/lib/token.d.mts +0 -17
  163. package/lib/token.d.ts +0 -17
  164. package/lib/token.js +0 -9
  165. package/lib/token.mjs +0 -9
  166. package/lib/types.d.mts +0 -20
  167. package/lib/types.d.ts +0 -20
  168. package/lib/types.js +0 -1
  169. package/lib/types.mjs +0 -1
@@ -1,161 +0,0 @@
1
- import {
2
- getSession,
3
- useSession
4
- } from "./chunk-KWNIT4G4.mjs";
5
- import {
6
- KeycloakContext
7
- } from "./chunk-2L5TXBDK.mjs";
8
-
9
- // src/keycloak/keycloak.ts
10
- import { MultiPlatform } from "multiplatform.one";
11
- import { jwtDecode } from "jwt-decode";
12
- import { signIn, signOut } from "next-auth/react";
13
- import { useContext } from "react";
14
- var Keycloak = class {
15
- token;
16
- idToken;
17
- refreshToken;
18
- _idTokenParsed;
19
- _refreshTokenParsed;
20
- _tokenParsed;
21
- keycloakClient;
22
- mock;
23
- constructor(input, idToken, refreshToken) {
24
- if (typeof input === "string") {
25
- this.token = input;
26
- this.idToken = idToken;
27
- this.refreshToken = refreshToken;
28
- } else if (typeof input === "object") {
29
- if (typeof input.init === "function") {
30
- this.keycloakClient = input;
31
- } else if (input.accessToken) {
32
- const session = input;
33
- this.token = session.accessToken;
34
- this.idToken = session.idToken;
35
- this.refreshToken = session.refreshToken;
36
- } else {
37
- this.mock = input;
38
- }
39
- }
40
- if (this.token && !this._tokenParsed)
41
- this._tokenParsed = jwtDecode(this.token);
42
- if (this.idToken && !this._idTokenParsed)
43
- this._idTokenParsed = jwtDecode(this.idToken);
44
- if (this.refreshToken && !this._refreshTokenParsed) {
45
- this._refreshTokenParsed = jwtDecode(this.refreshToken);
46
- }
47
- }
48
- get tokenParsed() {
49
- if (this.keycloakClient)
50
- return this.keycloakClient.tokenParsed;
51
- return this._tokenParsed;
52
- }
53
- get idTokenParsed() {
54
- if (this.keycloakClient)
55
- return this.keycloakClient.idTokenParsed;
56
- return this._idTokenParsed;
57
- }
58
- get refreshTokenParsed() {
59
- if (this.keycloakClient)
60
- return this.keycloakClient.refreshTokenParsed;
61
- return this._refreshTokenParsed;
62
- }
63
- get clientId() {
64
- if (this.keycloakClient)
65
- return this.keycloakClient.clientId;
66
- return this.tokenParsed?.azp;
67
- }
68
- get email() {
69
- if (this.keycloakClient)
70
- return this.keycloakClient.tokenParsed?.email;
71
- if (this.mock)
72
- return this.mock.email;
73
- return this.tokenParsed?.email;
74
- }
75
- get realm() {
76
- if (this.keycloakClient)
77
- return this.keycloakClient.realm;
78
- return this.tokenParsed?.iss?.split("/").pop();
79
- }
80
- get realmAccess() {
81
- if (this.keycloakClient)
82
- return this.keycloakClient.realmAccess;
83
- return this.tokenParsed?.realm_access;
84
- }
85
- get resourceAccess() {
86
- if (this.keycloakClient)
87
- return this.keycloakClient.resourceAccess;
88
- return this.tokenParsed?.resource_access;
89
- }
90
- get sessionId() {
91
- if (this.keycloakClient)
92
- return this.keycloakClient.sessionId;
93
- return this.tokenParsed?.session_state;
94
- }
95
- get subject() {
96
- if (this.keycloakClient)
97
- return this.keycloakClient.subject;
98
- return this.tokenParsed?.sub;
99
- }
100
- get username() {
101
- if (this.mock)
102
- return this.mock.username;
103
- return this.tokenParsed?.preferred_username;
104
- }
105
- async login(options = {}) {
106
- if (this.keycloakClient) {
107
- await this.keycloakClient.login(options);
108
- } else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
109
- await signIn("keycloak", {
110
- callbackUrl: options.redirectUri
111
- });
112
- }
113
- }
114
- async logout(options = {}) {
115
- if (this.keycloakClient) {
116
- await this.keycloakClient.logout(options);
117
- } else if (MultiPlatform.isNext && !MultiPlatform.isServer) {
118
- await fetch("/api/auth/logout", { method: "GET" });
119
- await signOut({
120
- callbackUrl: options.redirectUri
121
- });
122
- }
123
- }
124
- get authenticated() {
125
- if (this.mock)
126
- return true;
127
- if (this.keycloakClient)
128
- return !!this.keycloakClient.authenticated;
129
- if (!this.tokenParsed?.exp || !this.idToken)
130
- return false;
131
- return this.tokenParsed.exp > Date.now() / 1e3;
132
- }
133
- };
134
- function useKeycloak() {
135
- const keycloak = useContext(KeycloakContext);
136
- if (keycloak)
137
- return keycloak;
138
- const { session, status } = useSession();
139
- if (MultiPlatform.isStorybook) {
140
- return new Keycloak({
141
- email: "storybook@example.com",
142
- username: "storybook"
143
- });
144
- } else if (status === "unauthenticated") {
145
- return new Keycloak();
146
- } else if (status === "authenticated" && session?.accessToken) {
147
- return new Keycloak(session);
148
- }
149
- }
150
- async function getKeycloak(options, req, res) {
151
- const session = await getSession(options, req, res);
152
- if (session?.accessToken)
153
- return new Keycloak(session);
154
- return new Keycloak();
155
- }
156
-
157
- export {
158
- Keycloak,
159
- useKeycloak,
160
- getKeycloak
161
- };
@@ -1,22 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/state.ts
2
- var _zustand = require('multiplatform.one/zustand');
3
- var _multiplatformone = require('multiplatform.one');
4
- var persist = _multiplatformone.MultiPlatform.isIframe || !_multiplatformone.MultiPlatform.isNext && !_multiplatformone.MultiPlatform.isServer;
5
- var { useStore } = _zustand.createStateStore.call(void 0,
6
- "auth",
7
- {
8
- idToken: "",
9
- refreshToken: "",
10
- token: ""
11
- },
12
- void 0,
13
- { persist }
14
- );
15
- function useAuthState() {
16
- return useStore();
17
- }
18
-
19
-
20
-
21
-
22
- exports.persist = persist; exports.useAuthState = useAuthState;
@@ -1 +0,0 @@
1
- "use strict";
File without changes
@@ -1,13 +0,0 @@
1
- import {
2
- AuthConfigContext
3
- } from "./chunk-JAFUI2JQ.mjs";
4
-
5
- // src/hooks/useAuthConfig.ts
6
- import { useContext } from "react";
7
- function useAuthConfig() {
8
- return useContext(AuthConfigContext);
9
- }
10
-
11
- export {
12
- useAuthConfig
13
- };
@@ -1,16 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunkA2V2S4HPjs = require('./chunk-A2V2S4HP.js');
4
-
5
-
6
- var _chunk2VDDEPLFjs = require('./chunk-2VDDEPLF.js');
7
-
8
- // src/hooks/useTokensFromState.ts
9
- function useTokensFromState() {
10
- const authState = _chunkA2V2S4HPjs.useAuthState.call(void 0, );
11
- return !!_chunk2VDDEPLFjs.validToken.call(void 0, authState.token, authState.refreshToken);
12
- }
13
-
14
-
15
-
16
- exports.useTokensFromState = useTokensFromState;
@@ -1,9 +0,0 @@
1
- // src/authConfig.ts
2
- import { createContext } from "react";
3
- var defaultAuthConfig = {};
4
- var AuthConfigContext = createContext(defaultAuthConfig);
5
-
6
- export {
7
- defaultAuthConfig,
8
- AuthConfigContext
9
- };
File without changes
@@ -1,50 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
-
3
- var _chunkTUJRPTZEjs = require('./chunk-TUJRPTZE.js');
4
-
5
-
6
- var _chunk3ZTSLDX7js = require('./chunk-3ZTSLDX7.js');
7
-
8
-
9
- var _chunkI5FNGKQ6js = require('./chunk-I5FNGKQ6.js');
10
-
11
-
12
- var _chunkNWZCPYQPjs = require('./chunk-NWZCPYQP.js');
13
-
14
- // src/Authenticated.tsx
15
- var _react = require('react'); var _react2 = _interopRequireDefault(_react);
16
- var _multiplatformone = require('multiplatform.one');
17
- function Authenticated({ children, disabled, loggedOutComponent, loadingComponent }) {
18
- const authConfig = _chunk3ZTSLDX7js.useAuthConfig.call(void 0, );
19
- const keycloak = _chunkNWZCPYQPjs.useKeycloak.call(void 0, );
20
- const tokensFromQuery = _chunkTUJRPTZEjs.useTokensFromQuery.call(void 0, );
21
- const tokensFromState = _chunkI5FNGKQ6js.useTokensFromState.call(void 0, );
22
- _react.useEffect.call(void 0, () => {
23
- if (!keycloak || _multiplatformone.MultiPlatform.isIframe || _multiplatformone.MultiPlatform.isServer || keycloak.authenticated || tokensFromQuery || tokensFromState) {
24
- return;
25
- }
26
- keycloak.login({
27
- redirectUri: authConfig.loginRedirectUri
28
- });
29
- }, [keycloak]);
30
- if (typeof disabled === "undefined")
31
- disabled = authConfig.disabled;
32
- if (disabled)
33
- return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
34
- if (typeof keycloak === "undefined") {
35
- const LoadingComponent = loadingComponent;
36
- return LoadingComponent ? /* @__PURE__ */ _react2.default.createElement(LoadingComponent, null) : /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, authConfig.debug ? "loading" : null);
37
- }
38
- if (keycloak.authenticated)
39
- return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
40
- const LoggedOutComponent = loggedOutComponent;
41
- return LoggedOutComponent ? /* @__PURE__ */ _react2.default.createElement(LoggedOutComponent, null) : /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, authConfig.debug ? "not authenticated" : null);
42
- }
43
- function withAuthenticated(Component) {
44
- return (props) => /* @__PURE__ */ _react2.default.createElement(Authenticated, null, /* @__PURE__ */ _react2.default.createElement(Component, { ...props }));
45
- }
46
-
47
-
48
-
49
-
50
- exports.Authenticated = Authenticated; exports.withAuthenticated = withAuthenticated;
@@ -1,34 +0,0 @@
1
- // src/session/session.ts
2
- import { MultiPlatform } from "multiplatform.one";
3
- import { useSession as useNextSession, getSession as getNextSession } from "next-auth/react";
4
- var _getServerSession;
5
- async function getSession(options, req, res) {
6
- if (MultiPlatform.isServer) {
7
- if (typeof _getServerSession === "function")
8
- return _getServerSession(options, req, res);
9
- const getSession2 = (await import("next-auth")).getServerSession;
10
- _getServerSession = (options2, req2, res2) => {
11
- return req2 && res2 ? getSession2(req2, res2, options2) : getSession2(options2);
12
- };
13
- return _getServerSession(options, req, res);
14
- }
15
- return getNextSession(options);
16
- }
17
- var useSession = (options) => {
18
- return {};
19
- };
20
- if (MultiPlatform.isNext) {
21
- useSession = (options) => {
22
- const nextSession = useNextSession(options);
23
- return {
24
- update: nextSession.update,
25
- status: nextSession.status,
26
- session: nextSession.data
27
- };
28
- };
29
- }
30
-
31
- export {
32
- getSession,
33
- useSession
34
- };
@@ -1,13 +0,0 @@
1
- // src/hooks/useTokensFromQuery/index.ts
2
- import { MultiPlatform } from "multiplatform.one";
3
- import { useRouter } from "next/router";
4
- function useTokensFromQuery() {
5
- if (!MultiPlatform.isIframe)
6
- return false;
7
- const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
8
- return "idToken" in query || "token" in query || "refreshToken" in query;
9
- }
10
-
11
- export {
12
- useTokensFromQuery
13
- };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,51 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; }
2
-
3
- var _chunk3ZTSLDX7js = require('./chunk-3ZTSLDX7.js');
4
-
5
-
6
- var _chunkNWZCPYQPjs = require('./chunk-NWZCPYQP.js');
7
-
8
-
9
-
10
- var _chunkA2V2S4HPjs = require('./chunk-A2V2S4HP.js');
11
-
12
- // src/provider/AfterAuth.tsx
13
- var _react = require('react'); var _react2 = _interopRequireDefault(_react);
14
- var logger = console;
15
- function AfterAuth({ children }) {
16
- const authConfig = _chunk3ZTSLDX7js.useAuthConfig.call(void 0, );
17
- const authState = _chunkA2V2S4HPjs.useAuthState.call(void 0, );
18
- const keycloak = _chunkNWZCPYQPjs.useKeycloak.call(void 0, );
19
- _react.useEffect.call(void 0, () => {
20
- if (!_chunkA2V2S4HPjs.persist || !_optionalChain([keycloak, 'optionalAccess', _ => _.authenticated]))
21
- return;
22
- if (keycloak.token) {
23
- authState.setToken(keycloak.token);
24
- if (keycloak.idToken)
25
- authState.setIdToken(keycloak.idToken);
26
- if (keycloak.refreshToken)
27
- authState.setRefreshToken(keycloak.refreshToken);
28
- }
29
- }, [_optionalChain([keycloak, 'optionalAccess', _2 => _2.authenticated]), _optionalChain([keycloak, 'optionalAccess', _3 => _3.token]), _optionalChain([keycloak, 'optionalAccess', _4 => _4.idToken]), _optionalChain([keycloak, 'optionalAccess', _5 => _5.refreshToken])]);
30
- _react.useEffect.call(void 0, () => {
31
- if (authConfig.debug && _optionalChain([keycloak, 'optionalAccess', _6 => _6.token]))
32
- logger.debug("token", keycloak.token);
33
- }, [_optionalChain([keycloak, 'optionalAccess', _7 => _7.token])]);
34
- _react.useEffect.call(void 0, () => {
35
- if (authConfig.debug && _optionalChain([keycloak, 'optionalAccess', _8 => _8.idToken]))
36
- logger.debug("idToken", keycloak.idToken);
37
- }, [_optionalChain([keycloak, 'optionalAccess', _9 => _9.idToken])]);
38
- _react.useEffect.call(void 0, () => {
39
- if (authConfig.debug && _optionalChain([keycloak, 'optionalAccess', _10 => _10.refreshToken]))
40
- logger.debug("refreshToken", keycloak.refreshToken);
41
- }, [_optionalChain([keycloak, 'optionalAccess', _11 => _11.refreshToken])]);
42
- _react.useEffect.call(void 0, () => {
43
- if (authConfig.debug && _optionalChain([keycloak, 'optionalAccess', _12 => _12.authenticated]))
44
- logger.debug("authenticated", keycloak.authenticated);
45
- }, [_optionalChain([keycloak, 'optionalAccess', _13 => _13.authenticated])]);
46
- return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, children);
47
- }
48
-
49
-
50
-
51
- exports.AfterAuth = AfterAuth;
@@ -1,161 +0,0 @@
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; }
2
-
3
-
4
- var _chunk2VGMJ7WPjs = require('./chunk-2VGMJ7WP.js');
5
-
6
-
7
- var _chunkYACGLW5Qjs = require('./chunk-YACGLW5Q.js');
8
-
9
- // src/keycloak/keycloak.ts
10
- var _multiplatformone = require('multiplatform.one');
11
- var _jwtdecode = require('jwt-decode');
12
- var _react = require('next-auth/react');
13
- var _react3 = require('react');
14
- var Keycloak = class {
15
-
16
-
17
-
18
-
19
-
20
-
21
-
22
-
23
- constructor(input, idToken, refreshToken) {
24
- if (typeof input === "string") {
25
- this.token = input;
26
- this.idToken = idToken;
27
- this.refreshToken = refreshToken;
28
- } else if (typeof input === "object") {
29
- if (typeof input.init === "function") {
30
- this.keycloakClient = input;
31
- } else if (input.accessToken) {
32
- const session = input;
33
- this.token = session.accessToken;
34
- this.idToken = session.idToken;
35
- this.refreshToken = session.refreshToken;
36
- } else {
37
- this.mock = input;
38
- }
39
- }
40
- if (this.token && !this._tokenParsed)
41
- this._tokenParsed = _jwtdecode.jwtDecode.call(void 0, this.token);
42
- if (this.idToken && !this._idTokenParsed)
43
- this._idTokenParsed = _jwtdecode.jwtDecode.call(void 0, this.idToken);
44
- if (this.refreshToken && !this._refreshTokenParsed) {
45
- this._refreshTokenParsed = _jwtdecode.jwtDecode.call(void 0, this.refreshToken);
46
- }
47
- }
48
- get tokenParsed() {
49
- if (this.keycloakClient)
50
- return this.keycloakClient.tokenParsed;
51
- return this._tokenParsed;
52
- }
53
- get idTokenParsed() {
54
- if (this.keycloakClient)
55
- return this.keycloakClient.idTokenParsed;
56
- return this._idTokenParsed;
57
- }
58
- get refreshTokenParsed() {
59
- if (this.keycloakClient)
60
- return this.keycloakClient.refreshTokenParsed;
61
- return this._refreshTokenParsed;
62
- }
63
- get clientId() {
64
- if (this.keycloakClient)
65
- return this.keycloakClient.clientId;
66
- return _optionalChain([this, 'access', _ => _.tokenParsed, 'optionalAccess', _2 => _2.azp]);
67
- }
68
- get email() {
69
- if (this.keycloakClient)
70
- return _optionalChain([this, 'access', _3 => _3.keycloakClient, 'access', _4 => _4.tokenParsed, 'optionalAccess', _5 => _5.email]);
71
- if (this.mock)
72
- return this.mock.email;
73
- return _optionalChain([this, 'access', _6 => _6.tokenParsed, 'optionalAccess', _7 => _7.email]);
74
- }
75
- get realm() {
76
- if (this.keycloakClient)
77
- return this.keycloakClient.realm;
78
- return _optionalChain([this, 'access', _8 => _8.tokenParsed, 'optionalAccess', _9 => _9.iss, 'optionalAccess', _10 => _10.split, 'call', _11 => _11("/"), 'access', _12 => _12.pop, 'call', _13 => _13()]);
79
- }
80
- get realmAccess() {
81
- if (this.keycloakClient)
82
- return this.keycloakClient.realmAccess;
83
- return _optionalChain([this, 'access', _14 => _14.tokenParsed, 'optionalAccess', _15 => _15.realm_access]);
84
- }
85
- get resourceAccess() {
86
- if (this.keycloakClient)
87
- return this.keycloakClient.resourceAccess;
88
- return _optionalChain([this, 'access', _16 => _16.tokenParsed, 'optionalAccess', _17 => _17.resource_access]);
89
- }
90
- get sessionId() {
91
- if (this.keycloakClient)
92
- return this.keycloakClient.sessionId;
93
- return _optionalChain([this, 'access', _18 => _18.tokenParsed, 'optionalAccess', _19 => _19.session_state]);
94
- }
95
- get subject() {
96
- if (this.keycloakClient)
97
- return this.keycloakClient.subject;
98
- return _optionalChain([this, 'access', _20 => _20.tokenParsed, 'optionalAccess', _21 => _21.sub]);
99
- }
100
- get username() {
101
- if (this.mock)
102
- return this.mock.username;
103
- return _optionalChain([this, 'access', _22 => _22.tokenParsed, 'optionalAccess', _23 => _23.preferred_username]);
104
- }
105
- async login(options = {}) {
106
- if (this.keycloakClient) {
107
- await this.keycloakClient.login(options);
108
- } else if (_multiplatformone.MultiPlatform.isNext && !_multiplatformone.MultiPlatform.isServer) {
109
- await _react.signIn.call(void 0, "keycloak", {
110
- callbackUrl: options.redirectUri
111
- });
112
- }
113
- }
114
- async logout(options = {}) {
115
- if (this.keycloakClient) {
116
- await this.keycloakClient.logout(options);
117
- } else if (_multiplatformone.MultiPlatform.isNext && !_multiplatformone.MultiPlatform.isServer) {
118
- await fetch("/api/auth/logout", { method: "GET" });
119
- await _react.signOut.call(void 0, {
120
- callbackUrl: options.redirectUri
121
- });
122
- }
123
- }
124
- get authenticated() {
125
- if (this.mock)
126
- return true;
127
- if (this.keycloakClient)
128
- return !!this.keycloakClient.authenticated;
129
- if (!_optionalChain([this, 'access', _24 => _24.tokenParsed, 'optionalAccess', _25 => _25.exp]) || !this.idToken)
130
- return false;
131
- return this.tokenParsed.exp > Date.now() / 1e3;
132
- }
133
- };
134
- function useKeycloak() {
135
- const keycloak = _react3.useContext.call(void 0, _chunkYACGLW5Qjs.KeycloakContext);
136
- if (keycloak)
137
- return keycloak;
138
- const { session, status } = _chunk2VGMJ7WPjs.useSession.call(void 0, );
139
- if (_multiplatformone.MultiPlatform.isStorybook) {
140
- return new Keycloak({
141
- email: "storybook@example.com",
142
- username: "storybook"
143
- });
144
- } else if (status === "unauthenticated") {
145
- return new Keycloak();
146
- } else if (status === "authenticated" && _optionalChain([session, 'optionalAccess', _26 => _26.accessToken])) {
147
- return new Keycloak(session);
148
- }
149
- }
150
- async function getKeycloak(options, req, res) {
151
- const session = await _chunk2VGMJ7WPjs.getSession.call(void 0, options, req, res);
152
- if (_optionalChain([session, 'optionalAccess', _27 => _27.accessToken]))
153
- return new Keycloak(session);
154
- return new Keycloak();
155
- }
156
-
157
-
158
-
159
-
160
-
161
- exports.Keycloak = Keycloak; exports.useKeycloak = useKeycloak; exports.getKeycloak = getKeycloak;
File without changes
File without changes
@@ -1,11 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, {
2
- get: (a, b) => (typeof require !== "undefined" ? require : a)[b]
3
- }) : x)(function(x) {
4
- if (typeof require !== "undefined")
5
- return require.apply(this, arguments);
6
- throw Error('Dynamic require of "' + x + '" is not supported');
7
- });
8
-
9
-
10
-
11
- exports.__require = __require;
@@ -1,28 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
2
-
3
- var _chunkVFQKAKK4js = require('./chunk-VFQKAKK4.js');
4
-
5
-
6
- var _chunk32AVT4GAjs = require('./chunk-32AVT4GA.js');
7
-
8
- // src/provider/KeycloakProvider.tsx
9
- var _react = require('react'); var _react2 = _interopRequireDefault(_react);
10
- function KeycloakProvider({ children, debug, realm, clientId, baseUrl, session }) {
11
- const authConfig = _react.useMemo.call(void 0, () => ({ debug }), [debug]);
12
- return /* @__PURE__ */ _react2.default.createElement(_chunk32AVT4GAjs.AuthConfigContext.Provider, { value: authConfig }, /* @__PURE__ */ _react2.default.createElement(
13
- _chunkVFQKAKK4js.AuthProvider,
14
- {
15
- sessionProvider: { session },
16
- keycloakConfig: {
17
- realm: realm || "main",
18
- clientId: clientId || "app",
19
- url: baseUrl
20
- }
21
- },
22
- children
23
- ));
24
- }
25
-
26
-
27
-
28
- exports.KeycloakProvider = KeycloakProvider;
@@ -1,13 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/hooks/useTokensFromQuery/index.ts
2
- var _multiplatformone = require('multiplatform.one');
3
- var _router = require('next/router');
4
- function useTokensFromQuery() {
5
- if (!_multiplatformone.MultiPlatform.isIframe)
6
- return false;
7
- const { query } = _multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0, ) : { query: {} };
8
- return "idToken" in query || "token" in query || "refreshToken" in query;
9
- }
10
-
11
-
12
-
13
- exports.useTokensFromQuery = useTokensFromQuery;
File without changes
@@ -1,16 +0,0 @@
1
- import {
2
- useAuthState
3
- } from "./chunk-WMH347OL.mjs";
4
- import {
5
- validToken
6
- } from "./chunk-6FRYV4MK.mjs";
7
-
8
- // src/hooks/useTokensFromState.ts
9
- function useTokensFromState() {
10
- const authState = useAuthState();
11
- return !!validToken(authState.token, authState.refreshToken);
12
- }
13
-
14
- export {
15
- useTokensFromState
16
- };