@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,245 +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 _chunkNCIQ66UPjs = require('./chunk-NCIQ66UP.js');
4
-
5
-
6
- var _chunk3ZTSLDX7js = require('./chunk-3ZTSLDX7.js');
7
-
8
-
9
- var _chunkNWZCPYQPjs = require('./chunk-NWZCPYQP.js');
10
-
11
-
12
- var _chunkYACGLW5Qjs = require('./chunk-YACGLW5Q.js');
13
-
14
-
15
-
16
- var _chunkA2V2S4HPjs = require('./chunk-A2V2S4HP.js');
17
-
18
-
19
- var _chunk2VDDEPLFjs = require('./chunk-2VDDEPLF.js');
20
-
21
- // src/provider/AuthProvider/AuthProvider.tsx
22
- var _keycloakjs = require('keycloak-js'); var _keycloakjs2 = _interopRequireDefault(_keycloakjs);
23
- var _react = require('react'); var _react2 = _interopRequireDefault(_react);
24
- var _multiplatformone = require('multiplatform.one');
25
- var _react3 = require('next-auth/react');
26
- var _router = require('next/router');
27
- var logger = console;
28
- function AuthProvider({ children, sessionProvider, keycloakInitOptions, keycloakConfig }) {
29
- const { debug, messageHandlerKeys } = _chunk3ZTSLDX7js.useAuthConfig.call(void 0, );
30
- const { query } = _multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0, ) : { query: {} };
31
- const authState = _chunkA2V2S4HPjs.useAuthState.call(void 0, );
32
- const [keycloak, setKeycloak] = _react.useState.call(void 0, );
33
- const [refreshToken, setRefreshToken] = _react.useState.call(void 0,
34
- _chunk2VDDEPLFjs.validToken.call(void 0,
35
- _multiplatformone.MultiPlatform.isIframe ? "refreshToken" in query && (_optionalChain([query, 'access', _ => _.refreshToken, 'optionalAccess', _2 => _2.toString, 'call', _3 => _3()]) || true) || _chunkA2V2S4HPjs.persist && authState.refreshToken || false : void 0
36
- )
37
- );
38
- const [token, setToken] = _react.useState.call(void 0,
39
- _chunk2VDDEPLFjs.validToken.call(void 0,
40
- _multiplatformone.MultiPlatform.isIframe ? "token" in query && (_optionalChain([query, 'access', _4 => _4.token, 'optionalAccess', _5 => _5.toString, 'call', _6 => _6()]) || true) || _chunkA2V2S4HPjs.persist && authState.token || false : void 0,
41
- refreshToken
42
- )
43
- );
44
- const [idToken, setIdToken] = _react.useState.call(void 0,
45
- _chunk2VDDEPLFjs.validToken.call(void 0,
46
- _multiplatformone.MultiPlatform.isIframe ? "idToken" in query && (_optionalChain([query, 'access', _7 => _7.idToken, 'optionalAccess', _8 => _8.toString, 'call', _9 => _9()]) || true) || _chunkA2V2S4HPjs.persist && authState.idToken || false : void 0,
47
- refreshToken
48
- )
49
- );
50
- _react.useEffect.call(void 0, () => {
51
- if (token !== true && refreshToken !== true && idToken !== true)
52
- return;
53
- if (debug)
54
- logger.debug("post message", JSON.stringify({ type: "LOADED" }));
55
- (messageHandlerKeys || []).forEach((key) => {
56
- _optionalChain([window, 'optionalAccess', _10 => _10.webkit, 'optionalAccess', _11 => _11.messageHandlers, 'optionalAccess', _12 => _12[key], 'optionalAccess', _13 => _13.postMessage, 'call', _14 => _14(JSON.stringify({ type: "LOADED" }))]);
57
- });
58
- _optionalChain([window, 'optionalAccess', _15 => _15.ReactNativeWebView, 'optionalAccess', _16 => _16.postMessage, 'call', _17 => _17(JSON.stringify({ type: "LOADED" }))]);
59
- _optionalChain([window, 'optionalAccess', _18 => _18.parent, 'optionalAccess', _19 => _19.postMessage, 'call', _20 => _20(JSON.stringify({ type: "LOADED" }))]);
60
- }, []);
61
- _react.useEffect.call(void 0, () => {
62
- if (refreshToken !== true)
63
- return;
64
- const messageCallback = (e) => {
65
- let data = _optionalChain([e, 'optionalAccess', _21 => _21.data]) || null;
66
- if (typeof data === "string") {
67
- try {
68
- data = JSON.parse(data);
69
- } catch (err) {
70
- }
71
- }
72
- if (debug)
73
- logger.debug("received message", JSON.stringify(data));
74
- const message = data;
75
- if (!message.type)
76
- return;
77
- if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
78
- if (debug)
79
- logger.debug("setting refresh token", message.payload);
80
- setRefreshToken(_chunk2VDDEPLFjs.validToken.call(void 0, message.payload));
81
- window.removeEventListener("message", messageCallback);
82
- }
83
- };
84
- if (debug) {
85
- logger.debug(
86
- "listening for message",
87
- JSON.stringify({
88
- type: "REFRESH_TOKEN",
89
- payload: "<some_refresh_token>"
90
- })
91
- );
92
- }
93
- window.addEventListener("message", messageCallback);
94
- return () => {
95
- window.removeEventListener("message", messageCallback);
96
- };
97
- }, []);
98
- _react.useEffect.call(void 0, () => {
99
- if (token !== true)
100
- return;
101
- const messageCallback = (e) => {
102
- let data = _optionalChain([e, 'optionalAccess', _22 => _22.data]) || null;
103
- if (typeof data === "string") {
104
- try {
105
- data = JSON.parse(data);
106
- } catch (err) {
107
- }
108
- }
109
- if (debug)
110
- logger.debug("received message", JSON.stringify(data));
111
- const message = data;
112
- if (!message.type)
113
- return;
114
- if (message.type.toUpperCase() === "TOKEN" && message.payload) {
115
- if (debug)
116
- logger.debug("setting token", message.payload);
117
- setToken(_chunk2VDDEPLFjs.validToken.call(void 0, message.payload, refreshToken));
118
- window.removeEventListener("message", messageCallback);
119
- }
120
- };
121
- if (debug) {
122
- logger.debug(
123
- "listening for message",
124
- JSON.stringify({
125
- type: "TOKEN",
126
- payload: "<some_token>"
127
- })
128
- );
129
- }
130
- window.addEventListener("message", messageCallback);
131
- return () => {
132
- window.removeEventListener("message", messageCallback);
133
- };
134
- }, []);
135
- _react.useEffect.call(void 0, () => {
136
- if (idToken !== true)
137
- return;
138
- const messageCallback = (e) => {
139
- let data = _optionalChain([e, 'optionalAccess', _23 => _23.data]) || null;
140
- if (typeof data === "string") {
141
- try {
142
- data = JSON.parse(data);
143
- } catch (err) {
144
- }
145
- }
146
- if (debug)
147
- logger.debug("received message", JSON.stringify(data));
148
- const message = data;
149
- if (!message.type)
150
- return;
151
- if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
152
- if (debug)
153
- logger.debug("setting id token", message.payload);
154
- setIdToken(_chunk2VDDEPLFjs.validToken.call(void 0, message.payload, refreshToken));
155
- window.removeEventListener("message", messageCallback);
156
- }
157
- };
158
- if (debug) {
159
- logger.debug(
160
- "listening for message",
161
- JSON.stringify({
162
- type: "ID_TOKEN",
163
- payload: "<some_id_token>"
164
- })
165
- );
166
- }
167
- window.addEventListener("message", messageCallback);
168
- return () => {
169
- window.removeEventListener("message", messageCallback);
170
- };
171
- }, []);
172
- const keycloakClient = _react.useMemo.call(void 0,
173
- () => _multiplatformone.MultiPlatform.isIframe && keycloakConfig ? new (0, _keycloakjs2.default)({
174
- url: keycloakConfig.url,
175
- realm: keycloakConfig.realm,
176
- clientId: keycloakConfig.clientId
177
- }) : void 0,
178
- [keycloakInitOptions, keycloakConfig, token, refreshToken, idToken]
179
- );
180
- const initOptions = _react.useMemo.call(void 0, () => {
181
- if (!_multiplatformone.MultiPlatform.isIframe)
182
- return;
183
- const initOptions2 = {
184
- ...defaultKeycloakInitOptions,
185
- ...keycloakInitOptions
186
- };
187
- if (debug)
188
- initOptions2.enableLogging = true;
189
- if (token && typeof token === "string") {
190
- initOptions2.token = token;
191
- initOptions2.timeSkew = 0;
192
- if (idToken && typeof idToken === "string")
193
- initOptions2.idToken = idToken;
194
- if (refreshToken && typeof refreshToken === "string")
195
- initOptions2.refreshToken = refreshToken;
196
- }
197
- if (typeof window !== "undefined" && window.self !== window.top || token && !refreshToken) {
198
- initOptions2.checkLoginIframe = false;
199
- initOptions2.flow = "implicit";
200
- initOptions2.onLoad = void 0;
201
- }
202
- return initOptions2;
203
- }, [keycloakInitOptions, token, idToken, refreshToken]);
204
- _react.useEffect.call(void 0, () => {
205
- function onError() {
206
- if (keycloakClient && initOptions)
207
- setKeycloak(new (0, _chunkNWZCPYQPjs.Keycloak)(keycloakClient));
208
- }
209
- function onUpdate() {
210
- if (keycloakClient && initOptions)
211
- setKeycloak(new (0, _chunkNWZCPYQPjs.Keycloak)(keycloakClient));
212
- }
213
- if (keycloakClient && initOptions) {
214
- (async () => {
215
- keycloakClient.onAuthError = onError;
216
- keycloakClient.onAuthLogout = onUpdate;
217
- keycloakClient.onAuthRefreshError = onError;
218
- keycloakClient.onAuthRefreshSuccess = onUpdate;
219
- keycloakClient.onAuthSuccess = onUpdate;
220
- keycloakClient.onReady = onUpdate;
221
- keycloakClient.onTokenExpired = async () => {
222
- try {
223
- await keycloakClient.updateToken(5);
224
- } catch (err) {
225
- setKeycloak(new (0, _chunkNWZCPYQPjs.Keycloak)());
226
- }
227
- };
228
- const authenticated = await keycloakClient.init(initOptions);
229
- setKeycloak(new (0, _chunkNWZCPYQPjs.Keycloak)(authenticated ? keycloakClient : void 0));
230
- })();
231
- }
232
- }, []);
233
- return /* @__PURE__ */ _react2.default.createElement(_react3.SessionProvider, { ...sessionProvider }, /* @__PURE__ */ _react2.default.createElement(_chunkYACGLW5Qjs.KeycloakContext.Provider, { value: keycloak }, /* @__PURE__ */ _react2.default.createElement(_chunkNCIQ66UPjs.AfterAuth, null, children)));
234
- }
235
- var defaultKeycloakInitOptions = {
236
- checkLoginIframe: true,
237
- checkLoginIframeInterval: 5,
238
- enableLogging: false,
239
- onLoad: "check-sso",
240
- pkceMethod: "S256"
241
- };
242
-
243
-
244
-
245
- exports.AuthProvider = AuthProvider;
@@ -1,53 +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
- var _chunkNWZCPYQPjs = require('./chunk-NWZCPYQP.js');
4
-
5
- // src/apollo.ts
6
- var _client = require('@apollo/client');
7
- function useAuthQuery(query, options) {
8
- const keycloak = _chunkNWZCPYQPjs.useKeycloak.call(void 0, );
9
- return _client.useQuery.call(void 0, query, {
10
- ...options,
11
- skip: _optionalChain([options, 'optionalAccess', _ => _.skip]) || !_optionalChain([keycloak, 'optionalAccess', _2 => _2.authenticated]) || !keycloak.token,
12
- context: {
13
- ..._optionalChain([options, 'optionalAccess', _3 => _3.context]),
14
- headers: {
15
- ..._optionalChain([options, 'optionalAccess', _4 => _4.context, 'optionalAccess', _5 => _5.headers]) || {},
16
- authorization: `Bearer ${_optionalChain([keycloak, 'optionalAccess', _6 => _6.token])}`
17
- }
18
- }
19
- });
20
- }
21
- function useAuthMutation(mutation, options) {
22
- const keycloak = _chunkNWZCPYQPjs.useKeycloak.call(void 0, );
23
- return _client.useMutation.call(void 0, mutation, {
24
- ...options,
25
- context: {
26
- ..._optionalChain([options, 'optionalAccess', _7 => _7.context]),
27
- headers: {
28
- ..._optionalChain([options, 'optionalAccess', _8 => _8.context, 'optionalAccess', _9 => _9.headers]) || {},
29
- authorization: `Bearer ${_optionalChain([keycloak, 'optionalAccess', _10 => _10.token])}`
30
- }
31
- }
32
- });
33
- }
34
- function useAuthSubscription(subscription, options) {
35
- const keycloak = _chunkNWZCPYQPjs.useKeycloak.call(void 0, );
36
- return _client.useSubscription.call(void 0, subscription, {
37
- ...options,
38
- skip: _optionalChain([options, 'optionalAccess', _11 => _11.skip]) || !_optionalChain([keycloak, 'optionalAccess', _12 => _12.authenticated]) || !keycloak.token,
39
- context: {
40
- ..._optionalChain([options, 'optionalAccess', _13 => _13.context]),
41
- headers: {
42
- ..._optionalChain([options, 'optionalAccess', _14 => _14.context, 'optionalAccess', _15 => _15.headers]) || {},
43
- authorization: `Bearer ${_optionalChain([keycloak, 'optionalAccess', _16 => _16.token])}`
44
- }
45
- }
46
- });
47
- }
48
-
49
-
50
-
51
-
52
-
53
- exports.useAuthQuery = useAuthQuery; exports.useAuthMutation = useAuthMutation; exports.useAuthSubscription = useAuthSubscription;
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,245 +0,0 @@
1
- import {
2
- AfterAuth
3
- } from "./chunk-3KAZ37SK.mjs";
4
- import {
5
- useAuthConfig
6
- } from "./chunk-HTWZLBA4.mjs";
7
- import {
8
- Keycloak
9
- } from "./chunk-7NZPJ2EN.mjs";
10
- import {
11
- KeycloakContext
12
- } from "./chunk-2L5TXBDK.mjs";
13
- import {
14
- persist,
15
- useAuthState
16
- } from "./chunk-WMH347OL.mjs";
17
- import {
18
- validToken
19
- } from "./chunk-6FRYV4MK.mjs";
20
-
21
- // src/provider/AuthProvider/AuthProvider.tsx
22
- import KeycloakClient from "keycloak-js";
23
- import React, { useEffect, useMemo, useState } from "react";
24
- import { MultiPlatform } from "multiplatform.one";
25
- import { SessionProvider } from "next-auth/react";
26
- import { useRouter } from "next/router";
27
- var logger = console;
28
- function AuthProvider({ children, sessionProvider, keycloakInitOptions, keycloakConfig }) {
29
- const { debug, messageHandlerKeys } = useAuthConfig();
30
- const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
31
- const authState = useAuthState();
32
- const [keycloak, setKeycloak] = useState();
33
- const [refreshToken, setRefreshToken] = useState(
34
- validToken(
35
- MultiPlatform.isIframe ? "refreshToken" in query && (query.refreshToken?.toString() || true) || persist && authState.refreshToken || false : void 0
36
- )
37
- );
38
- const [token, setToken] = useState(
39
- validToken(
40
- MultiPlatform.isIframe ? "token" in query && (query.token?.toString() || true) || persist && authState.token || false : void 0,
41
- refreshToken
42
- )
43
- );
44
- const [idToken, setIdToken] = useState(
45
- validToken(
46
- MultiPlatform.isIframe ? "idToken" in query && (query.idToken?.toString() || true) || persist && authState.idToken || false : void 0,
47
- refreshToken
48
- )
49
- );
50
- useEffect(() => {
51
- if (token !== true && refreshToken !== true && idToken !== true)
52
- return;
53
- if (debug)
54
- logger.debug("post message", JSON.stringify({ type: "LOADED" }));
55
- (messageHandlerKeys || []).forEach((key) => {
56
- window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: "LOADED" }));
57
- });
58
- window?.ReactNativeWebView?.postMessage(JSON.stringify({ type: "LOADED" }));
59
- window?.parent?.postMessage(JSON.stringify({ type: "LOADED" }));
60
- }, []);
61
- useEffect(() => {
62
- if (refreshToken !== true)
63
- return;
64
- const messageCallback = (e) => {
65
- let data = e?.data || null;
66
- if (typeof data === "string") {
67
- try {
68
- data = JSON.parse(data);
69
- } catch (err) {
70
- }
71
- }
72
- if (debug)
73
- logger.debug("received message", JSON.stringify(data));
74
- const message = data;
75
- if (!message.type)
76
- return;
77
- if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
78
- if (debug)
79
- logger.debug("setting refresh token", message.payload);
80
- setRefreshToken(validToken(message.payload));
81
- window.removeEventListener("message", messageCallback);
82
- }
83
- };
84
- if (debug) {
85
- logger.debug(
86
- "listening for message",
87
- JSON.stringify({
88
- type: "REFRESH_TOKEN",
89
- payload: "<some_refresh_token>"
90
- })
91
- );
92
- }
93
- window.addEventListener("message", messageCallback);
94
- return () => {
95
- window.removeEventListener("message", messageCallback);
96
- };
97
- }, []);
98
- useEffect(() => {
99
- if (token !== true)
100
- return;
101
- const messageCallback = (e) => {
102
- let data = e?.data || null;
103
- if (typeof data === "string") {
104
- try {
105
- data = JSON.parse(data);
106
- } catch (err) {
107
- }
108
- }
109
- if (debug)
110
- logger.debug("received message", JSON.stringify(data));
111
- const message = data;
112
- if (!message.type)
113
- return;
114
- if (message.type.toUpperCase() === "TOKEN" && message.payload) {
115
- if (debug)
116
- logger.debug("setting token", message.payload);
117
- setToken(validToken(message.payload, refreshToken));
118
- window.removeEventListener("message", messageCallback);
119
- }
120
- };
121
- if (debug) {
122
- logger.debug(
123
- "listening for message",
124
- JSON.stringify({
125
- type: "TOKEN",
126
- payload: "<some_token>"
127
- })
128
- );
129
- }
130
- window.addEventListener("message", messageCallback);
131
- return () => {
132
- window.removeEventListener("message", messageCallback);
133
- };
134
- }, []);
135
- useEffect(() => {
136
- if (idToken !== true)
137
- return;
138
- const messageCallback = (e) => {
139
- let data = e?.data || null;
140
- if (typeof data === "string") {
141
- try {
142
- data = JSON.parse(data);
143
- } catch (err) {
144
- }
145
- }
146
- if (debug)
147
- logger.debug("received message", JSON.stringify(data));
148
- const message = data;
149
- if (!message.type)
150
- return;
151
- if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
152
- if (debug)
153
- logger.debug("setting id token", message.payload);
154
- setIdToken(validToken(message.payload, refreshToken));
155
- window.removeEventListener("message", messageCallback);
156
- }
157
- };
158
- if (debug) {
159
- logger.debug(
160
- "listening for message",
161
- JSON.stringify({
162
- type: "ID_TOKEN",
163
- payload: "<some_id_token>"
164
- })
165
- );
166
- }
167
- window.addEventListener("message", messageCallback);
168
- return () => {
169
- window.removeEventListener("message", messageCallback);
170
- };
171
- }, []);
172
- const keycloakClient = useMemo(
173
- () => MultiPlatform.isIframe && keycloakConfig ? new KeycloakClient({
174
- url: keycloakConfig.url,
175
- realm: keycloakConfig.realm,
176
- clientId: keycloakConfig.clientId
177
- }) : void 0,
178
- [keycloakInitOptions, keycloakConfig, token, refreshToken, idToken]
179
- );
180
- const initOptions = useMemo(() => {
181
- if (!MultiPlatform.isIframe)
182
- return;
183
- const initOptions2 = {
184
- ...defaultKeycloakInitOptions,
185
- ...keycloakInitOptions
186
- };
187
- if (debug)
188
- initOptions2.enableLogging = true;
189
- if (token && typeof token === "string") {
190
- initOptions2.token = token;
191
- initOptions2.timeSkew = 0;
192
- if (idToken && typeof idToken === "string")
193
- initOptions2.idToken = idToken;
194
- if (refreshToken && typeof refreshToken === "string")
195
- initOptions2.refreshToken = refreshToken;
196
- }
197
- if (typeof window !== "undefined" && window.self !== window.top || token && !refreshToken) {
198
- initOptions2.checkLoginIframe = false;
199
- initOptions2.flow = "implicit";
200
- initOptions2.onLoad = void 0;
201
- }
202
- return initOptions2;
203
- }, [keycloakInitOptions, token, idToken, refreshToken]);
204
- useEffect(() => {
205
- function onError() {
206
- if (keycloakClient && initOptions)
207
- setKeycloak(new Keycloak(keycloakClient));
208
- }
209
- function onUpdate() {
210
- if (keycloakClient && initOptions)
211
- setKeycloak(new Keycloak(keycloakClient));
212
- }
213
- if (keycloakClient && initOptions) {
214
- (async () => {
215
- keycloakClient.onAuthError = onError;
216
- keycloakClient.onAuthLogout = onUpdate;
217
- keycloakClient.onAuthRefreshError = onError;
218
- keycloakClient.onAuthRefreshSuccess = onUpdate;
219
- keycloakClient.onAuthSuccess = onUpdate;
220
- keycloakClient.onReady = onUpdate;
221
- keycloakClient.onTokenExpired = async () => {
222
- try {
223
- await keycloakClient.updateToken(5);
224
- } catch (err) {
225
- setKeycloak(new Keycloak());
226
- }
227
- };
228
- const authenticated = await keycloakClient.init(initOptions);
229
- setKeycloak(new Keycloak(authenticated ? keycloakClient : void 0));
230
- })();
231
- }
232
- }, []);
233
- return /* @__PURE__ */ React.createElement(SessionProvider, { ...sessionProvider }, /* @__PURE__ */ React.createElement(KeycloakContext.Provider, { value: keycloak }, /* @__PURE__ */ React.createElement(AfterAuth, null, children)));
234
- }
235
- var defaultKeycloakInitOptions = {
236
- checkLoginIframe: true,
237
- checkLoginIframeInterval: 5,
238
- enableLogging: false,
239
- onLoad: "check-sso",
240
- pkceMethod: "S256"
241
- };
242
-
243
- export {
244
- AuthProvider
245
- };
File without changes
@@ -1,22 +0,0 @@
1
- // src/state.ts
2
- import { createStateStore } from "multiplatform.one/zustand";
3
- import { MultiPlatform } from "multiplatform.one";
4
- var persist = MultiPlatform.isIframe || !MultiPlatform.isNext && !MultiPlatform.isServer;
5
- var { useStore } = createStateStore(
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
- export {
20
- persist,
21
- useAuthState
22
- };
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,7 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});// src/keycloak/context.ts
2
- var _react = require('react');
3
- var KeycloakContext = _react.createContext.call(void 0, void 0);
4
-
5
-
6
-
7
- exports.KeycloakContext = KeycloakContext;
@@ -1 +0,0 @@
1
- "use strict";
@@ -1,11 +0,0 @@
1
- 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
- export {
10
- __require
11
- };
@@ -1,5 +0,0 @@
1
- export { useAuthConfig } from './useAuthConfig.mjs';
2
- export { useTokensFromQuery } from './useTokensFromQuery/index.mjs';
3
- export { useTokensFromState } from './useTokensFromState.mjs';
4
- import '../authConfig.mjs';
5
- import 'react';
@@ -1,5 +0,0 @@
1
- export { useAuthConfig } from './useAuthConfig.js';
2
- export { useTokensFromQuery } from './useTokensFromQuery/index.js';
3
- export { useTokensFromState } from './useTokensFromState.js';
4
- import '../authConfig.js';
5
- import 'react';
@@ -1,19 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});require('../chunk-ZCBD6HWK.js');
2
-
3
-
4
- var _chunkTUJRPTZEjs = require('../chunk-TUJRPTZE.js');
5
-
6
-
7
- var _chunk3ZTSLDX7js = require('../chunk-3ZTSLDX7.js');
8
-
9
-
10
- var _chunkI5FNGKQ6js = require('../chunk-I5FNGKQ6.js');
11
- require('../chunk-32AVT4GA.js');
12
- require('../chunk-A2V2S4HP.js');
13
- require('../chunk-2VDDEPLF.js');
14
- require('../chunk-P57PW2II.js');
15
-
16
-
17
-
18
-
19
- exports.useAuthConfig = _chunk3ZTSLDX7js.useAuthConfig; exports.useTokensFromQuery = _chunkTUJRPTZEjs.useTokensFromQuery; exports.useTokensFromState = _chunkI5FNGKQ6js.useTokensFromState;
@@ -1,19 +0,0 @@
1
- import "../chunk-HH32BME2.mjs";
2
- import {
3
- useTokensFromQuery
4
- } from "../chunk-L3HTVJ4B.mjs";
5
- import {
6
- useAuthConfig
7
- } from "../chunk-HTWZLBA4.mjs";
8
- import {
9
- useTokensFromState
10
- } from "../chunk-UKSHA3X3.mjs";
11
- import "../chunk-JAFUI2JQ.mjs";
12
- import "../chunk-WMH347OL.mjs";
13
- import "../chunk-6FRYV4MK.mjs";
14
- import "../chunk-ZFXKCRJC.mjs";
15
- export {
16
- useAuthConfig,
17
- useTokensFromQuery,
18
- useTokensFromState
19
- };
@@ -1,6 +0,0 @@
1
- import { AuthConfig } from '../authConfig.mjs';
2
- import 'react';
3
-
4
- declare function useAuthConfig(): AuthConfig;
5
-
6
- export { useAuthConfig };
@@ -1,6 +0,0 @@
1
- import { AuthConfig } from '../authConfig.js';
2
- import 'react';
3
-
4
- declare function useAuthConfig(): AuthConfig;
5
-
6
- export { useAuthConfig };
@@ -1,8 +0,0 @@
1
- "use strict";Object.defineProperty(exports, "__esModule", {value: true});
2
-
3
- var _chunk3ZTSLDX7js = require('../chunk-3ZTSLDX7.js');
4
- require('../chunk-32AVT4GA.js');
5
- require('../chunk-P57PW2II.js');
6
-
7
-
8
- exports.useAuthConfig = _chunk3ZTSLDX7js.useAuthConfig;