@multiplatform.one/keycloak 0.7.14 → 0.7.16

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 (155) hide show
  1. package/package.json +28 -28
  2. package/routes/index.d.ts +22 -0
  3. package/routes/index.js +22 -0
  4. package/src/Authenticated.tsx +27 -17
  5. package/src/authConfig.ts +3 -9
  6. package/src/hooks/index.ts +0 -3
  7. package/src/hooks/useTokensFromQuery/index.ts +1 -0
  8. package/src/hooks/useTokensFromState.ts +1 -1
  9. package/src/index.ts +3 -0
  10. package/src/{@types/coreJsPure.d.ts → keycloak/context.ts} +6 -11
  11. package/{lib/@types/expoKeycloakAuth.d.d.mts → src/keycloak/index.ts} +4 -7
  12. package/src/keycloak/keycloak.native.ts +148 -0
  13. package/src/keycloak/keycloak.ts +175 -0
  14. package/src/provider/AfterAuth.tsx +63 -0
  15. package/src/provider/{keycloakProvider.native.tsx → AuthProvider/AuthProvider.native.tsx} +8 -16
  16. package/src/provider/{keycloakProvider.tsx → AuthProvider/AuthProvider.tsx} +81 -94
  17. package/{lib/@types/expoKeycloakAuth.d.d.ts → src/provider/AuthProvider/index.ts} +4 -7
  18. package/src/provider/KeycloakProvider.tsx +53 -0
  19. package/src/{hooks/useCurrentRouteName/index.native.ts → provider/index.ts} +6 -11
  20. package/src/routes.ts +163 -0
  21. package/src/session/index.ts +22 -0
  22. package/src/session/session.native.ts +31 -0
  23. package/src/session/session.ts +68 -0
  24. package/src/{state/index.ts → state.ts} +5 -4
  25. package/src/{util.ts → token.ts} +25 -11
  26. package/src/types.ts +4 -1
  27. package/lib/@types/coreJsPure.d.d.mts +0 -2
  28. package/lib/@types/coreJsPure.d.d.ts +0 -2
  29. package/lib/@types/coreJsPure.d.js +0 -1
  30. package/lib/@types/coreJsPure.d.mjs +0 -0
  31. package/lib/@types/expoKeycloakAuth.d.js +0 -1
  32. package/lib/@types/expoKeycloakAuth.d.mjs +0 -0
  33. package/lib/Authenticated.d.mts +0 -33
  34. package/lib/Authenticated.d.ts +0 -33
  35. package/lib/Authenticated.js +0 -19
  36. package/lib/Authenticated.mjs +0 -20
  37. package/lib/authConfig.d.mts +0 -14
  38. package/lib/authConfig.d.ts +0 -14
  39. package/lib/authConfig.js +0 -8
  40. package/lib/authConfig.mjs +0 -9
  41. package/lib/chunk-2GUOEPFY.mjs +0 -0
  42. package/lib/chunk-3ZPHNEJL.js +0 -11
  43. package/lib/chunk-64PPU7Q3.mjs +0 -13
  44. package/lib/chunk-6NDWOV55.js +0 -1
  45. package/lib/chunk-7MTPH6XK.mjs +0 -26
  46. package/lib/chunk-A7UBOIAL.js +0 -13
  47. package/lib/chunk-AD6VPMID.mjs +0 -20
  48. package/lib/chunk-AUUZ6BI7.js +0 -78
  49. package/lib/chunk-AYKQVWMR.mjs +0 -0
  50. package/lib/chunk-BVB33X7V.mjs +0 -265
  51. package/lib/chunk-C2FNSVJO.js +0 -17
  52. package/lib/chunk-J4CCMILN.mjs +0 -41
  53. package/lib/chunk-K33RKJZX.js +0 -443
  54. package/lib/chunk-KLLABHIC.js +0 -13
  55. package/lib/chunk-L5HMOY4M.mjs +0 -18
  56. package/lib/chunk-MZ6E62HK.js +0 -33
  57. package/lib/chunk-NWRANDZ6.js +0 -98
  58. package/lib/chunk-NXTVYIBR.mjs +0 -11
  59. package/lib/chunk-OYWAYMFN.js +0 -17
  60. package/lib/chunk-RPUOO7AV.mjs +0 -10
  61. package/lib/chunk-RYM7KERK.mjs +0 -52
  62. package/lib/chunk-UBVYEZI3.js +0 -1
  63. package/lib/chunk-UHTKOFS6.mjs +0 -84
  64. package/lib/chunk-UL6L5ONI.js +0 -460
  65. package/lib/chunk-UOKDJT5L.mjs +0 -16
  66. package/lib/chunk-W5DJLFTQ.js +0 -56
  67. package/lib/chunk-WT5W6BSZ.js +0 -161
  68. package/lib/chunk-XEO3YXBM.js +0 -22
  69. package/lib/chunk-XO4W2SMN.mjs +0 -50
  70. package/lib/chunk-XVPWAAZ4.mjs +0 -76
  71. package/lib/chunk-Y4XMF3R6.mjs +0 -13
  72. package/lib/chunk-YGNNHTFE.js +0 -12
  73. package/lib/hooks/index.d.mts +0 -9
  74. package/lib/hooks/index.d.ts +0 -9
  75. package/lib/hooks/index.js +0 -23
  76. package/lib/hooks/index.mjs +0 -34
  77. package/lib/hooks/useAuthConfig.d.mts +0 -6
  78. package/lib/hooks/useAuthConfig.d.ts +0 -6
  79. package/lib/hooks/useAuthConfig.js +0 -8
  80. package/lib/hooks/useAuthConfig.mjs +0 -8
  81. package/lib/hooks/useCurrentRouteName/index.d.mts +0 -3
  82. package/lib/hooks/useCurrentRouteName/index.d.ts +0 -3
  83. package/lib/hooks/useCurrentRouteName/index.js +0 -7
  84. package/lib/hooks/useCurrentRouteName/index.mjs +0 -7
  85. package/lib/hooks/useCurrentRouteName/index.native.d.mts +0 -3
  86. package/lib/hooks/useCurrentRouteName/index.native.d.ts +0 -3
  87. package/lib/hooks/useCurrentRouteName/index.native.js +0 -14
  88. package/lib/hooks/useCurrentRouteName/index.native.mjs +0 -14
  89. package/lib/hooks/useKeycloak/index.d.mts +0 -46
  90. package/lib/hooks/useKeycloak/index.d.ts +0 -46
  91. package/lib/hooks/useKeycloak/index.js +0 -11
  92. package/lib/hooks/useKeycloak/index.mjs +0 -12
  93. package/lib/hooks/useKeycloak/useKeycloak.d.mts +0 -2
  94. package/lib/hooks/useKeycloak/useKeycloak.d.ts +0 -2
  95. package/lib/hooks/useKeycloak/useKeycloak.js +0 -10
  96. package/lib/hooks/useKeycloak/useKeycloak.mjs +0 -11
  97. package/lib/hooks/useKeycloak/useKeycloak.native.d.mts +0 -20
  98. package/lib/hooks/useKeycloak/useKeycloak.native.d.ts +0 -20
  99. package/lib/hooks/useKeycloak/useKeycloak.native.js +0 -80
  100. package/lib/hooks/useKeycloak/useKeycloak.native.mjs +0 -69
  101. package/lib/hooks/useLogin.d.mts +0 -3
  102. package/lib/hooks/useLogin.d.ts +0 -3
  103. package/lib/hooks/useLogin.js +0 -11
  104. package/lib/hooks/useLogin.mjs +0 -11
  105. package/lib/hooks/useTokensFromQuery/index.d.mts +0 -3
  106. package/lib/hooks/useTokensFromQuery/index.d.ts +0 -3
  107. package/lib/hooks/useTokensFromQuery/index.js +0 -7
  108. package/lib/hooks/useTokensFromQuery/index.mjs +0 -7
  109. package/lib/hooks/useTokensFromQuery/index.native.d.mts +0 -3
  110. package/lib/hooks/useTokensFromQuery/index.native.d.ts +0 -3
  111. package/lib/hooks/useTokensFromQuery/index.native.js +0 -10
  112. package/lib/hooks/useTokensFromQuery/index.native.mjs +0 -7
  113. package/lib/hooks/useTokensFromState.d.mts +0 -3
  114. package/lib/hooks/useTokensFromState.d.ts +0 -3
  115. package/lib/hooks/useTokensFromState.js +0 -9
  116. package/lib/hooks/useTokensFromState.mjs +0 -9
  117. package/lib/index.d.mts +0 -13
  118. package/lib/index.d.ts +0 -13
  119. package/lib/index.js +0 -34
  120. package/lib/index.mjs +0 -56
  121. package/lib/provider/afterAuth.d.mts +0 -29
  122. package/lib/provider/afterAuth.d.ts +0 -29
  123. package/lib/provider/afterAuth.js +0 -18
  124. package/lib/provider/afterAuth.mjs +0 -18
  125. package/lib/provider/index.d.mts +0 -39
  126. package/lib/provider/index.d.ts +0 -39
  127. package/lib/provider/index.js +0 -22
  128. package/lib/provider/index.mjs +0 -25
  129. package/lib/provider/keycloakProvider.d.mts +0 -42
  130. package/lib/provider/keycloakProvider.d.ts +0 -42
  131. package/lib/provider/keycloakProvider.js +0 -20
  132. package/lib/provider/keycloakProvider.mjs +0 -21
  133. package/lib/provider/keycloakProvider.native.d.mts +0 -29
  134. package/lib/provider/keycloakProvider.native.d.ts +0 -29
  135. package/lib/provider/keycloakProvider.native.js +0 -87
  136. package/lib/provider/keycloakProvider.native.mjs +0 -30
  137. package/lib/state/index.d.mts +0 -11
  138. package/lib/state/index.d.ts +0 -11
  139. package/lib/state/index.js +0 -7
  140. package/lib/state/index.mjs +0 -7
  141. package/lib/types.d.mts +0 -17
  142. package/lib/types.d.ts +0 -17
  143. package/lib/types.js +0 -8
  144. package/lib/types.mjs +0 -7
  145. package/lib/util.d.mts +0 -4
  146. package/lib/util.d.ts +0 -4
  147. package/lib/util.js +0 -8
  148. package/lib/util.mjs +0 -9
  149. package/src/hooks/useCurrentRouteName/index.ts +0 -34
  150. package/src/hooks/useKeycloak/index.ts +0 -47
  151. package/src/hooks/useKeycloak/useKeycloak.native.ts +0 -95
  152. package/src/hooks/useKeycloak/useKeycloak.ts +0 -106
  153. package/src/hooks/useLogin.ts +0 -47
  154. package/src/provider/afterAuth.tsx +0 -65
  155. package/src/provider/index.tsx +0 -117
@@ -1,443 +0,0 @@
1
- "use strict";
2
- function _array_like_to_array(arr, len) {
3
- if (len == null || len > arr.length) len = arr.length;
4
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
- return arr2;
6
- }
7
- function _array_with_holes(arr) {
8
- if (Array.isArray(arr)) return arr;
9
- }
10
- function _array_without_holes(arr) {
11
- if (Array.isArray(arr)) return _array_like_to_array(arr);
12
- }
13
- function _define_property(obj, key, value) {
14
- if (key in obj) {
15
- Object.defineProperty(obj, key, {
16
- value: value,
17
- enumerable: true,
18
- configurable: true,
19
- writable: true
20
- });
21
- } else {
22
- obj[key] = value;
23
- }
24
- return obj;
25
- }
26
- function _iterable_to_array(iter) {
27
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
28
- }
29
- function _iterable_to_array_limit(arr, i) {
30
- var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
31
- if (_i == null) return;
32
- var _arr = [];
33
- var _n = true;
34
- var _d = false;
35
- var _s, _e;
36
- try {
37
- for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
38
- _arr.push(_s.value);
39
- if (i && _arr.length === i) break;
40
- }
41
- } catch (err) {
42
- _d = true;
43
- _e = err;
44
- } finally{
45
- try {
46
- if (!_n && _i["return"] != null) _i["return"]();
47
- } finally{
48
- if (_d) throw _e;
49
- }
50
- }
51
- return _arr;
52
- }
53
- function _non_iterable_rest() {
54
- throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
55
- }
56
- function _non_iterable_spread() {
57
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
58
- }
59
- function _object_spread(target) {
60
- for(var i = 1; i < arguments.length; i++){
61
- var source = arguments[i] != null ? arguments[i] : {};
62
- var ownKeys = Object.keys(source);
63
- if (typeof Object.getOwnPropertySymbols === "function") {
64
- ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
65
- return Object.getOwnPropertyDescriptor(source, sym).enumerable;
66
- }));
67
- }
68
- ownKeys.forEach(function(key) {
69
- _define_property(target, key, source[key]);
70
- });
71
- }
72
- return target;
73
- }
74
- function _sliced_to_array(arr, i) {
75
- return _array_with_holes(arr) || _iterable_to_array_limit(arr, i) || _unsupported_iterable_to_array(arr, i) || _non_iterable_rest();
76
- }
77
- function _to_consumable_array(arr) {
78
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
79
- }
80
- function _unsupported_iterable_to_array(o, minLen) {
81
- if (!o) return;
82
- if (typeof o === "string") return _array_like_to_array(o, minLen);
83
- var n = Object.prototype.toString.call(o).slice(8, -1);
84
- if (n === "Object" && o.constructor) n = o.constructor.name;
85
- if (n === "Map" || n === "Set") return Array.from(n);
86
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
87
- }
88
- Object.defineProperty(exports, "__esModule", {
89
- value: true
90
- });
91
- function _interopRequireDefault(obj) {
92
- return obj && obj.__esModule ? obj : {
93
- default: obj
94
- };
95
- }
96
- function _optionalChain(ops) {
97
- var lastAccessLHS = undefined;
98
- var value = ops[0];
99
- var i = 1;
100
- while(i < ops.length){
101
- var op = ops[i];
102
- var fn = ops[i + 1];
103
- i += 2;
104
- if ((op === "optionalAccess" || op === "optionalCall") && value == null) {
105
- return undefined;
106
- }
107
- if (op === "access" || op === "optionalAccess") {
108
- lastAccessLHS = value;
109
- value = fn(value);
110
- } else if (op === "call" || op === "optionalCall") {
111
- var _value;
112
- value = fn(function() {
113
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
114
- args[_key] = arguments[_key];
115
- }
116
- return (_value = value).call.apply(_value, [
117
- lastAccessLHS
118
- ].concat(_to_consumable_array(args)));
119
- });
120
- lastAccessLHS = undefined;
121
- }
122
- }
123
- return value;
124
- }
125
- var _chunkW5DJLFTQjs = require("./chunk-W5DJLFTQ.js");
126
- var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
127
- var _chunkC2FNSVJOjs = require("./chunk-C2FNSVJO.js");
128
- var _chunkNWRANDZ6js = require("./chunk-NWRANDZ6.js");
129
- // src/provider/keycloakProvider.tsx
130
- var _keycloakjs = require("@bitspur/keycloak-js");
131
- var _keycloakjs2 = _interopRequireDefault(_keycloakjs);
132
- var _react = require("react");
133
- var _react2 = _interopRequireDefault(_react);
134
- var _multiplatformone = require("multiplatform.one");
135
- var _reactkeycloakweb = require("@bitspur/react-keycloak-web");
136
- var _reactkeycloakssr = require("@bitspur/react-keycloak-ssr");
137
- var _router = require("next/router");
138
- var logger = console;
139
- function KeycloakProvider(param) {
140
- var children = param.children, cookies = param.cookies, keycloakConfig = param.keycloakConfig, keycloakInitOptions = param.keycloakInitOptions, loadingComponent = param.loadingComponent, onEvent = param.onEvent, onTokens = param.onTokens;
141
- var _chunk3ZPHNEJLjs_useAuthConfig_call = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0), debug = _chunk3ZPHNEJLjs_useAuthConfig_call.debug, ensureFreshness = _chunk3ZPHNEJLjs_useAuthConfig_call.ensureFreshness, persist = _chunk3ZPHNEJLjs_useAuthConfig_call.persist, messageHandlerKeys = _chunk3ZPHNEJLjs_useAuthConfig_call.messageHandlerKeys, ssr = _chunk3ZPHNEJLjs_useAuthConfig_call.ssr;
142
- var authState = _chunkC2FNSVJOjs.useAuthState.call(void 0);
143
- var LoadingComponent = loadingComponent || function() {
144
- return /* @__PURE__ */ _react2.default.createElement(_react2.default.Fragment, null, debug ? "authenticating" : null);
145
- };
146
- var query = (_multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0) : {
147
- query: {}
148
- }).query;
149
- var _react_useState_call = _sliced_to_array(_react.useState.call(void 0, _chunkNWRANDZ6js.validToken.call(void 0, ensureFreshness && ("refreshToken" in query && (_optionalChain([
150
- query,
151
- "access",
152
- function(_) {
153
- return _.refreshToken;
154
- },
155
- "optionalAccess",
156
- function(_2) {
157
- return _2.toString;
158
- },
159
- "call",
160
- function(_3) {
161
- return _3();
162
- }
163
- ]) || true) || persist && authState.refreshToken) || false)), 2), refreshToken = _react_useState_call[0], setRefreshToken = _react_useState_call[1];
164
- var _react_useState_call1 = _sliced_to_array(_react.useState.call(void 0, _chunkNWRANDZ6js.validToken.call(void 0, "idToken" in query && (_optionalChain([
165
- query,
166
- "access",
167
- function(_4) {
168
- return _4.idToken;
169
- },
170
- "optionalAccess",
171
- function(_5) {
172
- return _5.toString;
173
- },
174
- "call",
175
- function(_6) {
176
- return _6();
177
- }
178
- ]) || true) || persist && authState.idToken || false, refreshToken)), 2), idToken = _react_useState_call1[0], setIdToken = _react_useState_call1[1];
179
- var _react_useState_call2 = _sliced_to_array(_react.useState.call(void 0, _chunkNWRANDZ6js.validToken.call(void 0, "token" in query && (_optionalChain([
180
- query,
181
- "access",
182
- function(_7) {
183
- return _7.token;
184
- },
185
- "optionalAccess",
186
- function(_8) {
187
- return _8.toString;
188
- },
189
- "call",
190
- function(_9) {
191
- return _9();
192
- }
193
- ]) || true) || persist && authState.token || false, refreshToken)), 2), token = _react_useState_call2[0], setToken = _react_useState_call2[1];
194
- _react.useEffect.call(void 0, function() {
195
- if (token !== true && refreshToken !== true && idToken !== true) return;
196
- if (debug) logger.debug("post message", JSON.stringify({
197
- type: "LOADED"
198
- }));
199
- (messageHandlerKeys || []).forEach(function(key) {
200
- _optionalChain([
201
- window,
202
- "optionalAccess",
203
- function(_10) {
204
- return _10.webkit;
205
- },
206
- "optionalAccess",
207
- function(_11) {
208
- return _11.messageHandlers;
209
- },
210
- "optionalAccess",
211
- function(_12) {
212
- return _12[key];
213
- },
214
- "optionalAccess",
215
- function(_13) {
216
- return _13.postMessage;
217
- },
218
- "call",
219
- function(_14) {
220
- return _14(JSON.stringify({
221
- type: "LOADED"
222
- }));
223
- }
224
- ]);
225
- });
226
- _optionalChain([
227
- window,
228
- "optionalAccess",
229
- function(_15) {
230
- return _15.ReactNativeWebView;
231
- },
232
- "optionalAccess",
233
- function(_16) {
234
- return _16.postMessage;
235
- },
236
- "call",
237
- function(_17) {
238
- return _17(JSON.stringify({
239
- type: "LOADED"
240
- }));
241
- }
242
- ]);
243
- _optionalChain([
244
- window,
245
- "optionalAccess",
246
- function(_18) {
247
- return _18.parent;
248
- },
249
- "optionalAccess",
250
- function(_19) {
251
- return _19.postMessage;
252
- },
253
- "call",
254
- function(_20) {
255
- return _20(JSON.stringify({
256
- type: "LOADED"
257
- }));
258
- }
259
- ]);
260
- }, []);
261
- _react.useEffect.call(void 0, function() {
262
- if (refreshToken !== true) return;
263
- var messageCallback = function(e) {
264
- var data = _optionalChain([
265
- e,
266
- "optionalAccess",
267
- function(_21) {
268
- return _21.data;
269
- }
270
- ]) || null;
271
- if (typeof data === "string") {
272
- try {
273
- data = JSON.parse(data);
274
- } catch (err) {}
275
- }
276
- if (debug) logger.debug("received message", JSON.stringify(data));
277
- var message = data;
278
- if (!message.type) return;
279
- if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
280
- if (debug) logger.debug("setting refresh token", message.payload);
281
- setRefreshToken(_chunkNWRANDZ6js.validToken.call(void 0, message.payload));
282
- window.removeEventListener("message", messageCallback);
283
- }
284
- };
285
- if (debug) {
286
- logger.debug("listening for message", JSON.stringify({
287
- type: "REFRESH_TOKEN",
288
- payload: "<some_refresh_token>"
289
- }));
290
- }
291
- window.addEventListener("message", messageCallback);
292
- return function() {
293
- window.removeEventListener("message", messageCallback);
294
- };
295
- }, []);
296
- _react.useEffect.call(void 0, function() {
297
- if (token !== true) return;
298
- var messageCallback = function(e) {
299
- var data = _optionalChain([
300
- e,
301
- "optionalAccess",
302
- function(_22) {
303
- return _22.data;
304
- }
305
- ]) || null;
306
- if (typeof data === "string") {
307
- try {
308
- data = JSON.parse(data);
309
- } catch (err) {}
310
- }
311
- if (debug) logger.debug("received message", JSON.stringify(data));
312
- var message = data;
313
- if (!message.type) return;
314
- if (message.type.toUpperCase() === "TOKEN" && message.payload) {
315
- if (debug) logger.debug("setting token", message.payload);
316
- setToken(_chunkNWRANDZ6js.validToken.call(void 0, message.payload, refreshToken));
317
- window.removeEventListener("message", messageCallback);
318
- }
319
- };
320
- if (debug) {
321
- logger.debug("listening for message", JSON.stringify({
322
- type: "TOKEN",
323
- payload: "<some_token>"
324
- }));
325
- }
326
- window.addEventListener("message", messageCallback);
327
- return function() {
328
- window.removeEventListener("message", messageCallback);
329
- };
330
- }, []);
331
- _react.useEffect.call(void 0, function() {
332
- if (idToken !== true) return;
333
- var messageCallback = function(e) {
334
- var data = _optionalChain([
335
- e,
336
- "optionalAccess",
337
- function(_23) {
338
- return _23.data;
339
- }
340
- ]) || null;
341
- if (typeof data === "string") {
342
- try {
343
- data = JSON.parse(data);
344
- } catch (err) {}
345
- }
346
- if (debug) logger.debug("received message", JSON.stringify(data));
347
- var message = data;
348
- if (!message.type) return;
349
- if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
350
- if (debug) logger.debug("setting id token", message.payload);
351
- setIdToken(_chunkNWRANDZ6js.validToken.call(void 0, message.payload, refreshToken));
352
- window.removeEventListener("message", messageCallback);
353
- }
354
- };
355
- if (debug) {
356
- logger.debug("listening for message", JSON.stringify({
357
- type: "ID_TOKEN",
358
- payload: "<some_id_token>"
359
- }));
360
- }
361
- window.addEventListener("message", messageCallback);
362
- return function() {
363
- window.removeEventListener("message", messageCallback);
364
- };
365
- }, []);
366
- var handleEvent = _react.useCallback.call(void 0, function(eventType, error) {
367
- if (error) {
368
- if (typeof error === "string") throw new Error(error);
369
- var err = new Error(error.error);
370
- err.errorDescription = error.error_description;
371
- throw err;
372
- }
373
- if (onEvent) onEvent(eventType, error);
374
- }, []);
375
- var keycloak = _react.useMemo.call(void 0, function() {
376
- return typeof window !== "undefined" && new (0, _keycloakjs2.default)({
377
- url: keycloakConfig.url,
378
- realm: keycloakConfig.realm,
379
- clientId: keycloakConfig.clientId
380
- });
381
- }, [
382
- keycloakInitOptions,
383
- token,
384
- refreshToken,
385
- idToken
386
- ]);
387
- var initOptions = _react.useMemo.call(void 0, function() {
388
- var initOptions2 = _object_spread({}, defaultKeycloakInitOptions, keycloakInitOptions);
389
- if (debug) initOptions2.enableLogging = true;
390
- if (token && typeof token === "string") {
391
- initOptions2.token = token;
392
- initOptions2.timeSkew = 0;
393
- if (idToken && typeof idToken === "string") initOptions2.idToken = idToken;
394
- if (refreshToken && typeof refreshToken === "string") initOptions2.refreshToken = refreshToken;
395
- }
396
- if (typeof window !== "undefined" && window.self !== window.top || token && !refreshToken) {
397
- initOptions2.checkLoginIframe = false;
398
- initOptions2.flow = "implicit";
399
- initOptions2.onLoad = void 0;
400
- }
401
- return initOptions2;
402
- }, [
403
- keycloakInitOptions,
404
- token,
405
- refreshToken,
406
- idToken
407
- ]);
408
- if (token === true || idToken === true || refreshToken === true) return /* @__PURE__ */ _react2.default.createElement(LoadingComponent, null);
409
- if (cookies && ssr) {
410
- return(// @ts-ignore
411
- /* @__PURE__ */ _react2.default.createElement(_reactkeycloakssr.SSRKeycloakProvider, {
412
- LoadingComponent: /* @__PURE__ */ _react2.default.createElement(LoadingComponent, null),
413
- autoRefreshToken: initOptions.checkLoginIframe,
414
- initOptions: initOptions,
415
- onEvent: handleEvent,
416
- onTokens: onTokens,
417
- persistor: _reactkeycloakssr.SSRCookies.call(void 0, cookies),
418
- keycloakConfig: {
419
- clientId: keycloakConfig.clientId,
420
- realm: keycloakConfig.realm,
421
- url: keycloakConfig.url
422
- }
423
- }, /* @__PURE__ */ _react2.default.createElement(_chunkW5DJLFTQjs.AfterAuth, null, children)));
424
- }
425
- if (!keycloak) return /* @__PURE__ */ _react2.default.createElement(LoadingComponent, null);
426
- return /* @__PURE__ */ _react2.default.createElement(_reactkeycloakweb.ReactKeycloakProvider, {
427
- LoadingComponent: /* @__PURE__ */ _react2.default.createElement(LoadingComponent, null),
428
- authClient: keycloak,
429
- autoRefreshToken: initOptions.checkLoginIframe,
430
- initOptions: initOptions,
431
- onEvent: handleEvent,
432
- onTokens: onTokens
433
- }, /* @__PURE__ */ _react2.default.createElement(_chunkW5DJLFTQjs.AfterAuth, null, children));
434
- }
435
- var defaultKeycloakInitOptions = {
436
- checkLoginIframe: true,
437
- checkLoginIframeInterval: 5,
438
- enableLogging: false,
439
- onLoad: "check-sso",
440
- pkceMethod: "S256"
441
- };
442
- exports.KeycloakProvider = KeycloakProvider;
443
- exports.defaultKeycloakInitOptions = defaultKeycloakInitOptions;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- }); // src/hooks/useTokensFromQuery/index.ts
5
- var _multiplatformone = require("multiplatform.one");
6
- var _router = require("next/router");
7
- function useTokensFromQuery() {
8
- var query = (_multiplatformone.MultiPlatform.isNext ? _router.useRouter.call(void 0) : {
9
- query: {}
10
- }).query;
11
- return "idToken" in query || "token" in query || "refreshToken" in query;
12
- }
13
- exports.useTokensFromQuery = useTokensFromQuery;
@@ -1,18 +0,0 @@
1
- // src/hooks/useCurrentRouteName/index.ts
2
- import { MultiPlatform } from "multiplatform.one";
3
- import { useRoute } from "@react-navigation/native";
4
- import { useRouter } from "next/router";
5
- function useCurrentRouteName() {
6
- if (MultiPlatform.isStorybook)
7
- return null;
8
- if (MultiPlatform.isNext) {
9
- const router = useRouter();
10
- return router.route;
11
- }
12
- const route = useRoute();
13
- return route.name;
14
- }
15
-
16
- export {
17
- useCurrentRouteName
18
- };
@@ -1,33 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- });
5
- var _chunkOYWAYMFNjs = require("./chunk-OYWAYMFN.js");
6
- var _chunkUL6L5ONIjs = require("./chunk-UL6L5ONI.js");
7
- var _chunk3ZPHNEJLjs = require("./chunk-3ZPHNEJL.js");
8
- // src/hooks/useLogin.ts
9
- var _multiplatformone = require("multiplatform.one");
10
- var _router = require("solito/router");
11
- function useLogin(loginRoute) {
12
- if (_multiplatformone.MultiPlatform.isStorybook) return function() {
13
- return null;
14
- };
15
- var keycloak = _chunkUL6L5ONIjs.useKeycloak.call(void 0);
16
- var authConfig = _chunk3ZPHNEJLjs.useAuthConfig.call(void 0);
17
- var currentRouteName = _chunkOYWAYMFNjs.useCurrentRouteName.call(void 0);
18
- var router = _router.useRouter.call(void 0);
19
- return function() {
20
- if (!loginRoute) loginRoute = authConfig.loginRoute;
21
- if (!loginRoute) {
22
- keycloak.login();
23
- return;
24
- }
25
- var url = new URL("x://".concat(loginRoute));
26
- var searchParams = new URLSearchParams(url.search);
27
- if (currentRouteName) searchParams.append("backTo", currentRouteName);
28
- var query = searchParams.toString();
29
- if (query.length) query = "?".concat(query);
30
- router.push("".concat(url.pathname.substring(2)).concat(query));
31
- };
32
- }
33
- exports.useLogin = useLogin;
@@ -1,98 +0,0 @@
1
- "use strict";
2
- function _array_like_to_array(arr, len) {
3
- if (len == null || len > arr.length) len = arr.length;
4
- for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
5
- return arr2;
6
- }
7
- function _array_without_holes(arr) {
8
- if (Array.isArray(arr)) return _array_like_to_array(arr);
9
- }
10
- function _instanceof(left, right) {
11
- if (right != null && typeof Symbol !== "undefined" && right[Symbol.hasInstance]) {
12
- return !!right[Symbol.hasInstance](left);
13
- } else {
14
- return left instanceof right;
15
- }
16
- }
17
- function _iterable_to_array(iter) {
18
- if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter);
19
- }
20
- function _non_iterable_spread() {
21
- throw new TypeError("Invalid attempt to spread non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
22
- }
23
- function _to_consumable_array(arr) {
24
- return _array_without_holes(arr) || _iterable_to_array(arr) || _unsupported_iterable_to_array(arr) || _non_iterable_spread();
25
- }
26
- function _unsupported_iterable_to_array(o, minLen) {
27
- if (!o) return;
28
- if (typeof o === "string") return _array_like_to_array(o, minLen);
29
- var n = Object.prototype.toString.call(o).slice(8, -1);
30
- if (n === "Object" && o.constructor) n = o.constructor.name;
31
- if (n === "Map" || n === "Set") return Array.from(n);
32
- if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _array_like_to_array(o, minLen);
33
- }
34
- Object.defineProperty(exports, "__esModule", {
35
- value: true
36
- });
37
- function _optionalChain(ops) {
38
- var lastAccessLHS = undefined;
39
- var value = ops[0];
40
- var i = 1;
41
- while(i < ops.length){
42
- var op = ops[i];
43
- var fn = ops[i + 1];
44
- i += 2;
45
- if ((op === "optionalAccess" || op === "optionalCall") && value == null) {
46
- return undefined;
47
- }
48
- if (op === "access" || op === "optionalAccess") {
49
- lastAccessLHS = value;
50
- value = fn(value);
51
- } else if (op === "call" || op === "optionalCall") {
52
- var _value;
53
- value = fn(function() {
54
- for(var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++){
55
- args[_key] = arguments[_key];
56
- }
57
- return (_value = value).call.apply(_value, [
58
- lastAccessLHS
59
- ].concat(_to_consumable_array(args)));
60
- });
61
- lastAccessLHS = undefined;
62
- }
63
- }
64
- return value;
65
- } // src/util.ts
66
- function validToken(token, refreshToken) {
67
- if (typeof token !== "string") return token;
68
- if (refreshToken) {
69
- if (refreshToken === true || isTokenValid(refreshToken)) return token;
70
- return false;
71
- }
72
- return isTokenValid(token) ? token : false;
73
- }
74
- function isTokenValid(token) {
75
- try {
76
- var exp = JSON.parse(Buffer.from(_optionalChain([
77
- token,
78
- "access",
79
- function(_) {
80
- return _.split;
81
- },
82
- "call",
83
- function(_2) {
84
- return _2(".");
85
- },
86
- "optionalAccess",
87
- function(_3) {
88
- return _3[1];
89
- }
90
- ]) || "", "base64").toString() || "{}").exp;
91
- return Math.floor(Date.now() / 1e3) <= exp;
92
- } catch (err) {
93
- if (_instanceof(err, SyntaxError)) return false;
94
- throw err;
95
- }
96
- }
97
- exports.validToken = validToken;
98
- exports.isTokenValid = isTokenValid;
@@ -1,11 +0,0 @@
1
- // src/hooks/useTokensFromQuery/index.ts
2
- import { MultiPlatform } from "multiplatform.one";
3
- import { useRouter } from "next/router";
4
- function useTokensFromQuery() {
5
- const { query } = MultiPlatform.isNext ? useRouter() : { query: {} };
6
- return "idToken" in query || "token" in query || "refreshToken" in query;
7
- }
8
-
9
- export {
10
- useTokensFromQuery
11
- };
@@ -1,17 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", {
3
- value: true
4
- }); // src/hooks/useCurrentRouteName/index.ts
5
- var _multiplatformone = require("multiplatform.one");
6
- var _native = require("@react-navigation/native");
7
- var _router = require("next/router");
8
- function useCurrentRouteName() {
9
- if (_multiplatformone.MultiPlatform.isStorybook) return null;
10
- if (_multiplatformone.MultiPlatform.isNext) {
11
- var router = _router.useRouter.call(void 0);
12
- return router.route;
13
- }
14
- var route = _native.useRoute.call(void 0);
15
- return route.name;
16
- }
17
- exports.useCurrentRouteName = useCurrentRouteName;
@@ -1,10 +0,0 @@
1
- var __defProp = Object.defineProperty;
2
- var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
- var __publicField = (obj, key, value) => {
4
- __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
5
- return value;
6
- };
7
-
8
- export {
9
- __publicField
10
- };