@multiplatform.one/keycloak 11.3.1 → 11.3.2
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.
- package/dist/cjs/index.cjs +48 -316
- package/dist/cjs/index.native.cjs +15 -365
- package/dist/esm/index.mjs +40 -313
- package/dist/esm/index.native.js +7 -372
- package/package.json +10 -10
package/dist/cjs/index.cjs
CHANGED
|
@@ -60,128 +60,8 @@ __export(index_exports, {
|
|
|
60
60
|
});
|
|
61
61
|
module.exports = __toCommonJS(index_exports);
|
|
62
62
|
|
|
63
|
-
// ../platform/src/platform/platformBase.ts
|
|
64
|
-
var import_constants = require("@tamagui/constants");
|
|
65
|
-
var platformOrder = [
|
|
66
|
-
"Ios",
|
|
67
|
-
"Android",
|
|
68
|
-
// Gnome outranks Native: the GTK target reports isNative (it is not a
|
|
69
|
-
// browser) but "gnome" is the precise answer callers want.
|
|
70
|
-
"Gnome",
|
|
71
|
-
"Native",
|
|
72
|
-
// Tauri outranks Desktop/Web the same way: the webview host reports isWeb
|
|
73
|
-
// and isDesktop, but "tauri" is the precise answer.
|
|
74
|
-
"Tauri",
|
|
75
|
-
"Desktop",
|
|
76
|
-
"ChromeExtension",
|
|
77
|
-
"FirefoxExtension",
|
|
78
|
-
"WebExtension",
|
|
79
|
-
"Next",
|
|
80
|
-
"Expo",
|
|
81
|
-
"Chrome",
|
|
82
|
-
"Firefox",
|
|
83
|
-
"Web",
|
|
84
|
-
"Browser",
|
|
85
|
-
"Client",
|
|
86
|
-
"Server",
|
|
87
|
-
"Iframe",
|
|
88
|
-
"Storybook"
|
|
89
|
-
];
|
|
90
|
-
var platformBase = {
|
|
91
|
-
isAndroid: false,
|
|
92
|
-
isBrowser: false,
|
|
93
|
-
isChrome: import_constants.isChrome,
|
|
94
|
-
isChromeExtension: false,
|
|
95
|
-
isClient: import_constants.isClient,
|
|
96
|
-
isDesktop: false,
|
|
97
|
-
isExpo: false,
|
|
98
|
-
isFirefox: false,
|
|
99
|
-
isFirefoxExtension: false,
|
|
100
|
-
isGnome: false,
|
|
101
|
-
isIframe: false,
|
|
102
|
-
isIos: false,
|
|
103
|
-
isNative: false,
|
|
104
|
-
isNext: false,
|
|
105
|
-
isServer: import_constants.isServer,
|
|
106
|
-
isStorybook: import_constants.isBrowser && typeof window.__STORYBOOK_ADDONS_PREVIEW === "object",
|
|
107
|
-
isTauri: false,
|
|
108
|
-
isTouchable: import_constants.isTouchable,
|
|
109
|
-
isWeb: import_constants.isWeb,
|
|
110
|
-
isWebExtension: false,
|
|
111
|
-
isWebTouchable: import_constants.isWebTouchable,
|
|
112
|
-
isWindowDefined: import_constants.isBrowser,
|
|
113
|
-
preciseName: "unknown",
|
|
114
|
-
broadName: "unknown"
|
|
115
|
-
};
|
|
116
|
-
function getPreciseName(platform2) {
|
|
117
|
-
const flags = platform2;
|
|
118
|
-
for (const name of platformOrder) {
|
|
119
|
-
if (flags[`is${name}`]) {
|
|
120
|
-
return `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
121
|
-
}
|
|
122
|
-
}
|
|
123
|
-
return "unknown";
|
|
124
|
-
}
|
|
125
|
-
function getBroadName(platform2) {
|
|
126
|
-
const flags = platform2;
|
|
127
|
-
for (const name of platformOrder.slice().reverse()) {
|
|
128
|
-
if (flags[`is${name}`]) {
|
|
129
|
-
return `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
130
|
-
}
|
|
131
|
-
}
|
|
132
|
-
return "unknown";
|
|
133
|
-
}
|
|
134
|
-
|
|
135
|
-
// ../platform/src/platform/index.ts
|
|
136
|
-
var isIframe = (() => {
|
|
137
|
-
if (!platformBase.isWindowDefined) return false;
|
|
138
|
-
try {
|
|
139
|
-
return window.self !== window.top;
|
|
140
|
-
} catch {
|
|
141
|
-
return true;
|
|
142
|
-
}
|
|
143
|
-
})();
|
|
144
|
-
var isWebExtension = !!(typeof chrome !== "undefined" && !!chrome?.runtime?.id || typeof browser !== "undefined" && !!browser?.runtime?.id);
|
|
145
|
-
var platform = {
|
|
146
|
-
...platformBase,
|
|
147
|
-
isChromeExtension: typeof chrome !== "undefined" && !!chrome?.runtime?.id,
|
|
148
|
-
isFirefoxExtension: typeof browser !== "undefined" && !!browser?.runtime?.id,
|
|
149
|
-
isIframe,
|
|
150
|
-
isWebExtension,
|
|
151
|
-
isBrowser: !!(platformBase.isWeb && platformBase.isWindowDefined && !isWebExtension),
|
|
152
|
-
isNext: platformBase.isWeb && (!platformBase.isWindowDefined || typeof window.__NEXT_DATA__ === "object"),
|
|
153
|
-
isFirefox: platformBase.isWindowDefined && !!(window?.navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1)
|
|
154
|
-
};
|
|
155
|
-
platform.preciseName = getPreciseName(platform);
|
|
156
|
-
platform.broadName = getBroadName(platform);
|
|
157
|
-
|
|
158
|
-
// ../platform/src/index.ts
|
|
159
|
-
var {
|
|
160
|
-
isAndroid,
|
|
161
|
-
isBrowser,
|
|
162
|
-
isChrome: isChrome2,
|
|
163
|
-
isChromeExtension,
|
|
164
|
-
isClient: isClient2,
|
|
165
|
-
isExpo,
|
|
166
|
-
isFirefox,
|
|
167
|
-
isFirefoxExtension,
|
|
168
|
-
isGnome,
|
|
169
|
-
isIframe: isIframe2,
|
|
170
|
-
isIos,
|
|
171
|
-
isNative,
|
|
172
|
-
isNext,
|
|
173
|
-
isServer: isServer2,
|
|
174
|
-
isStorybook,
|
|
175
|
-
isTauri,
|
|
176
|
-
isDesktop,
|
|
177
|
-
isTouchable: isTouchable2,
|
|
178
|
-
isWeb: isWeb2,
|
|
179
|
-
isWebExtension: isWebExtension2,
|
|
180
|
-
isWebTouchable: isWebTouchable2,
|
|
181
|
-
isWindowDefined: isWindowDefined2
|
|
182
|
-
} = platform;
|
|
183
|
-
|
|
184
63
|
// src/Authenticated.tsx
|
|
64
|
+
var import_platform6 = require("@multiplatform.one/platform");
|
|
185
65
|
var import_react9 = require("react");
|
|
186
66
|
var import_react_native = require("react-native");
|
|
187
67
|
|
|
@@ -199,95 +79,26 @@ function useAuthConfig() {
|
|
|
199
79
|
}
|
|
200
80
|
|
|
201
81
|
// src/hooks/useTokensFromQuery/index.ts
|
|
82
|
+
var import_platform = require("@multiplatform.one/platform");
|
|
202
83
|
function useTokensFromQuery() {
|
|
203
84
|
const { iframeSso } = useAuthConfig();
|
|
204
|
-
if (iframeSso || !
|
|
85
|
+
if (iframeSso || !import_platform.isIframe) return false;
|
|
205
86
|
const query = new URLSearchParams(
|
|
206
87
|
typeof window === "undefined" ? "" : window?.location?.search || ""
|
|
207
88
|
);
|
|
208
89
|
return typeof query.get("idToken") === "string" || typeof query.get("token") === "string" || typeof query.get("refreshToken") === "string";
|
|
209
90
|
}
|
|
210
91
|
|
|
211
|
-
// ../store/src/createStore.ts
|
|
212
|
-
var import_store2 = require("@tanstack/store");
|
|
213
|
-
|
|
214
|
-
// ../store/src/persist.ts
|
|
215
|
-
var import_store = require("@tanstack/store");
|
|
216
|
-
function createPersistStore(initialState, persistOptions) {
|
|
217
|
-
const { key, storage: storage2, serialize = JSON.stringify, deserialize = JSON.parse } = persistOptions;
|
|
218
|
-
let hydrated = false;
|
|
219
|
-
const store = new import_store.Store(initialState);
|
|
220
|
-
store.subscribe(() => {
|
|
221
|
-
if (hydrated) {
|
|
222
|
-
const serialized = serialize(store.state);
|
|
223
|
-
void Promise.resolve(storage2.setItem(key, serialized));
|
|
224
|
-
}
|
|
225
|
-
});
|
|
226
|
-
const rehydrate = async () => {
|
|
227
|
-
const raw = await Promise.resolve(storage2.getItem(key));
|
|
228
|
-
if (raw !== null) {
|
|
229
|
-
const deserialized = deserialize(raw);
|
|
230
|
-
store.setState(() => deserialized);
|
|
231
|
-
}
|
|
232
|
-
hydrated = true;
|
|
233
|
-
};
|
|
234
|
-
const clearPersistedState = async () => {
|
|
235
|
-
await Promise.resolve(storage2.removeItem(key));
|
|
236
|
-
};
|
|
237
|
-
void rehydrate();
|
|
238
|
-
const persistStore = store;
|
|
239
|
-
persistStore.rehydrate = rehydrate;
|
|
240
|
-
persistStore.clearPersistedState = clearPersistedState;
|
|
241
|
-
return persistStore;
|
|
242
|
-
}
|
|
243
|
-
|
|
244
|
-
// ../store/src/storage/index.ts
|
|
245
|
-
var noopStorage = {
|
|
246
|
-
getItem: () => null,
|
|
247
|
-
setItem: () => {
|
|
248
|
-
},
|
|
249
|
-
removeItem: () => {
|
|
250
|
-
}
|
|
251
|
-
};
|
|
252
|
-
function getStorage() {
|
|
253
|
-
if (typeof globalThis !== "undefined" && "localStorage" in globalThis && typeof globalThis.localStorage?.getItem === "function") {
|
|
254
|
-
return {
|
|
255
|
-
getItem: (name) => globalThis.localStorage.getItem(name) ?? null,
|
|
256
|
-
setItem: (name, value) => globalThis.localStorage.setItem(name, value),
|
|
257
|
-
removeItem: (name) => globalThis.localStorage.removeItem(name)
|
|
258
|
-
};
|
|
259
|
-
}
|
|
260
|
-
return noopStorage;
|
|
261
|
-
}
|
|
262
|
-
var storage = getStorage();
|
|
263
|
-
|
|
264
|
-
// ../store/src/createStore.ts
|
|
265
|
-
function createStore(initialState, options) {
|
|
266
|
-
if (options?.persist) {
|
|
267
|
-
return createPersistStore(initialState, {
|
|
268
|
-
key: options.name,
|
|
269
|
-
storage: options.storage ?? storage
|
|
270
|
-
});
|
|
271
|
-
}
|
|
272
|
-
return new import_store2.Store(initialState);
|
|
273
|
-
}
|
|
274
|
-
|
|
275
|
-
// ../store/src/index.ts
|
|
276
|
-
var import_store3 = require("@tanstack/store");
|
|
277
|
-
var import_react_store = require("@tanstack/react-store");
|
|
278
|
-
var import_react_store2 = require("@tanstack/react-store");
|
|
279
|
-
function useStore2(store, selector) {
|
|
280
|
-
return (0, import_react_store2.useStore)(store, selector ?? ((s) => s));
|
|
281
|
-
}
|
|
282
|
-
|
|
283
92
|
// src/state.ts
|
|
284
|
-
var
|
|
285
|
-
var
|
|
93
|
+
var import_store = require("@multiplatform.one/store");
|
|
94
|
+
var import_platform2 = require("@multiplatform.one/platform");
|
|
95
|
+
var persist = import_platform2.isIframe || !import_platform2.isBrowser && !import_platform2.isServer;
|
|
96
|
+
var authStore = (0, import_store.createStore)(
|
|
286
97
|
{ idToken: "", refreshToken: "", token: "" },
|
|
287
98
|
{ name: "auth", persist }
|
|
288
99
|
);
|
|
289
100
|
function useAuthStore() {
|
|
290
|
-
const state =
|
|
101
|
+
const state = (0, import_store.useStore)(authStore);
|
|
291
102
|
return {
|
|
292
103
|
...state,
|
|
293
104
|
setIdToken: (idToken) => authStore.setState((prev) => ({ ...prev, idToken })),
|
|
@@ -350,29 +161,25 @@ function useTokensFromStore() {
|
|
|
350
161
|
}
|
|
351
162
|
|
|
352
163
|
// src/keycloak/index.ts
|
|
164
|
+
var import_platform5 = require("@multiplatform.one/platform");
|
|
353
165
|
var import_react8 = require("react");
|
|
354
166
|
|
|
355
167
|
// src/betterAuth/client.ts
|
|
356
168
|
var import_react3 = require("better-auth/react");
|
|
357
169
|
var import_plugins = require("better-auth/client/plugins");
|
|
170
|
+
var import_platform3 = require("@multiplatform.one/platform");
|
|
358
171
|
var _client;
|
|
359
172
|
function getAuthClient(baseURL) {
|
|
360
173
|
if (_client) return _client;
|
|
361
174
|
_client = (0, import_react3.createAuthClient)({
|
|
362
|
-
baseURL: baseURL || (
|
|
175
|
+
baseURL: baseURL || (import_platform3.isWeb && typeof window !== "undefined" ? window.location.origin : ""),
|
|
363
176
|
plugins: [(0, import_plugins.genericOAuthClient)()]
|
|
364
177
|
});
|
|
365
178
|
return _client;
|
|
366
179
|
}
|
|
367
180
|
|
|
368
|
-
//
|
|
369
|
-
var
|
|
370
|
-
var ACCESS_TOKEN_RETRY_DELAYS_MS = [0, 400, 1e3];
|
|
371
|
-
function classifyAccessTokenResponse(status, body) {
|
|
372
|
-
if (status === 401 || status === 403) return "signed-out";
|
|
373
|
-
if (status === 400 && body?.code === FAILED_TO_GET_ACCESS_TOKEN) return "signed-out";
|
|
374
|
-
return "transient";
|
|
375
|
-
}
|
|
181
|
+
// src/frappeToken.ts
|
|
182
|
+
var import_access_token = require("@multiplatform.one/auth/access-token");
|
|
376
183
|
|
|
377
184
|
// src/betterAuth/accountSelection.ts
|
|
378
185
|
var validationErrorCode = "VALIDATION_ERROR";
|
|
@@ -443,7 +250,7 @@ async function fetchTokenOnce() {
|
|
|
443
250
|
return { status: response.status, body: payload };
|
|
444
251
|
});
|
|
445
252
|
if (res.status < 200 || res.status >= 300) {
|
|
446
|
-
return { ok: false, kind: classifyAccessTokenResponse(res.status, res.body) };
|
|
253
|
+
return { ok: false, kind: (0, import_access_token.classifyAccessTokenResponse)(res.status, res.body) };
|
|
447
254
|
}
|
|
448
255
|
const data = payload;
|
|
449
256
|
if (!data?.accessToken) {
|
|
@@ -460,7 +267,7 @@ async function fetchTokenOnce() {
|
|
|
460
267
|
}
|
|
461
268
|
async function fetchToken() {
|
|
462
269
|
let last = "transient";
|
|
463
|
-
for (const wait of ACCESS_TOKEN_RETRY_DELAYS_MS) {
|
|
270
|
+
for (const wait of import_access_token.ACCESS_TOKEN_RETRY_DELAYS_MS) {
|
|
464
271
|
if (wait) await sleep(wait);
|
|
465
272
|
const result = await fetchTokenOnce();
|
|
466
273
|
if (result.ok) {
|
|
@@ -534,10 +341,11 @@ function useAuthError() {
|
|
|
534
341
|
}
|
|
535
342
|
|
|
536
343
|
// src/session/index.ts
|
|
344
|
+
var import_platform4 = require("@multiplatform.one/platform");
|
|
537
345
|
var useSession = (_options) => {
|
|
538
346
|
return { session: null, status: "unauthenticated", error: useAuthError() };
|
|
539
347
|
};
|
|
540
|
-
if (isBrowser) {
|
|
348
|
+
if (import_platform4.isBrowser) {
|
|
541
349
|
useSession = (_options) => {
|
|
542
350
|
const client = getAuthClient();
|
|
543
351
|
const { data, isPending, error: sessionError } = client.useSession();
|
|
@@ -723,11 +531,11 @@ var Keycloak = class extends BaseKeycloak {
|
|
|
723
531
|
this._sync();
|
|
724
532
|
} else if (this._login) {
|
|
725
533
|
await this._login(options);
|
|
726
|
-
} else if (isBrowser && !
|
|
534
|
+
} else if (import_platform5.isBrowser && !import_platform5.isServer) {
|
|
727
535
|
const client = getAuthClient();
|
|
728
536
|
const result = await client.signIn.social({
|
|
729
537
|
provider: "keycloak",
|
|
730
|
-
callbackURL: options.redirectUri || (
|
|
538
|
+
callbackURL: options.redirectUri || (import_platform5.isWeb ? window.location.href : "")
|
|
731
539
|
});
|
|
732
540
|
if (result?.error) {
|
|
733
541
|
throw result.error instanceof Error ? result.error : new Error(result.error.message || "Sign-in failed");
|
|
@@ -756,12 +564,12 @@ var Keycloak = class extends BaseKeycloak {
|
|
|
756
564
|
}
|
|
757
565
|
window.location.href = `${origin}/api/auth/sign-out/sso?callbackURL=${encodeURIComponent(callbackURL)}`;
|
|
758
566
|
return;
|
|
759
|
-
} else if (isBrowser && !
|
|
567
|
+
} else if (import_platform5.isBrowser && !import_platform5.isServer) {
|
|
760
568
|
const client = getAuthClient();
|
|
761
569
|
await client.signOut({
|
|
762
570
|
fetchOptions: {
|
|
763
571
|
onSuccess: () => {
|
|
764
|
-
if (options.redirectUri &&
|
|
572
|
+
if (options.redirectUri && import_platform5.isWeb) window.location.href = options.redirectUri;
|
|
765
573
|
}
|
|
766
574
|
}
|
|
767
575
|
});
|
|
@@ -776,7 +584,7 @@ function useKeycloak() {
|
|
|
776
584
|
const { session, status } = useSession();
|
|
777
585
|
if (disabled) return null;
|
|
778
586
|
if (keycloak) return keycloak;
|
|
779
|
-
if (isStorybook) {
|
|
587
|
+
if (import_platform5.isStorybook) {
|
|
780
588
|
return new Keycloak(keycloakConfig, {
|
|
781
589
|
email: "storybook@example.com",
|
|
782
590
|
username: "storybook"
|
|
@@ -805,7 +613,7 @@ function Authenticated({
|
|
|
805
613
|
const keycloak = useKeycloak();
|
|
806
614
|
const tokensFromQuery = useTokensFromQuery();
|
|
807
615
|
(0, import_react9.useEffect)(() => {
|
|
808
|
-
if (!keycloak || !authConfig.iframeSso &&
|
|
616
|
+
if (!keycloak || !authConfig.iframeSso && import_platform6.isIframe || import_platform6.isServer || keycloak.authenticated || tokensFromQuery) {
|
|
809
617
|
return;
|
|
810
618
|
}
|
|
811
619
|
keycloak?.login({
|
|
@@ -826,86 +634,8 @@ function withAuthenticated(Component, options = {}) {
|
|
|
826
634
|
return (props) => /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Authenticated, { ...options, children: /* @__PURE__ */ (0, import_jsx_runtime.jsx)(Component, { ...props }) });
|
|
827
635
|
}
|
|
828
636
|
|
|
829
|
-
// ../logger/src/base.ts
|
|
830
|
-
var import_loglevel = __toESM(require("loglevel"));
|
|
831
|
-
var defaultLoggerConfig = {
|
|
832
|
-
name: "default",
|
|
833
|
-
type: "pretty",
|
|
834
|
-
level: true ? 1 /* Debug */ : 2 /* Info */
|
|
835
|
-
};
|
|
836
|
-
var BaseLogger = class {
|
|
837
|
-
constructor(config = {}) {
|
|
838
|
-
const { metadata, name, level } = typeof config === "string" ? { metadata: void 0, name: config, level: void 0 } : config;
|
|
839
|
-
this.metadata = metadata || {};
|
|
840
|
-
this.name = name || "default";
|
|
841
|
-
this.logger = name ? import_loglevel.default.getLogger(name) : import_loglevel.default;
|
|
842
|
-
if (level !== void 0) this.logger.setLevel(level);
|
|
843
|
-
this.transport = this.createTransport?.();
|
|
844
|
-
}
|
|
845
|
-
trace(...args) {
|
|
846
|
-
this.logger.trace(...args);
|
|
847
|
-
this.sendToTransport(0 /* Trace */, args);
|
|
848
|
-
}
|
|
849
|
-
debug(...args) {
|
|
850
|
-
this.logger.debug(...args);
|
|
851
|
-
this.sendToTransport(1 /* Debug */, args);
|
|
852
|
-
}
|
|
853
|
-
info(...args) {
|
|
854
|
-
this.logger.info(...args);
|
|
855
|
-
this.sendToTransport(2 /* Info */, args);
|
|
856
|
-
}
|
|
857
|
-
warn(...args) {
|
|
858
|
-
this.logger.warn(...args);
|
|
859
|
-
this.sendToTransport(3 /* Warn */, args);
|
|
860
|
-
}
|
|
861
|
-
error(...args) {
|
|
862
|
-
this.logger.error(...args);
|
|
863
|
-
this.sendToTransport(4 /* Error */, args);
|
|
864
|
-
}
|
|
865
|
-
log(...args) {
|
|
866
|
-
this.logger.debug(...args);
|
|
867
|
-
this.sendToTransport(1 /* Debug */, args);
|
|
868
|
-
}
|
|
869
|
-
sendToTransport(level, args) {
|
|
870
|
-
if (this.transport) {
|
|
871
|
-
this.transport.send({
|
|
872
|
-
level,
|
|
873
|
-
message: args[0],
|
|
874
|
-
args: args.slice(1),
|
|
875
|
-
platform: platform.preciseName,
|
|
876
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
877
|
-
});
|
|
878
|
-
}
|
|
879
|
-
}
|
|
880
|
-
getSubLogger(input) {
|
|
881
|
-
const subConfig = typeof input === "string" ? {
|
|
882
|
-
name: input,
|
|
883
|
-
metadata: this.metadata,
|
|
884
|
-
level: this.logger.getLevel()
|
|
885
|
-
} : {
|
|
886
|
-
...input,
|
|
887
|
-
metadata: { ...this.metadata, ...input.metadata }
|
|
888
|
-
};
|
|
889
|
-
return new this.constructor(subConfig);
|
|
890
|
-
}
|
|
891
|
-
};
|
|
892
|
-
|
|
893
|
-
// ../logger/src/index.ts
|
|
894
|
-
var Logger = class extends BaseLogger {
|
|
895
|
-
constructor(config = {}) {
|
|
896
|
-
const metadata = {
|
|
897
|
-
platform: platform.preciseName
|
|
898
|
-
};
|
|
899
|
-
super({
|
|
900
|
-
name: metadata.platform,
|
|
901
|
-
...typeof config === "string" ? { name: config } : config,
|
|
902
|
-
metadata
|
|
903
|
-
});
|
|
904
|
-
}
|
|
905
|
-
};
|
|
906
|
-
var logger = new Logger();
|
|
907
|
-
|
|
908
637
|
// src/provider/AfterAuth.tsx
|
|
638
|
+
var import_logger = require("@multiplatform.one/logger");
|
|
909
639
|
var import_react10 = require("react");
|
|
910
640
|
var import_jsx_runtime2 = require("react/jsx-runtime");
|
|
911
641
|
function AfterAuth({ children, loadingComponent: _loadingComponent }) {
|
|
@@ -933,27 +663,27 @@ function AfterAuth({ children, loadingComponent: _loadingComponent }) {
|
|
|
933
663
|
]);
|
|
934
664
|
(0, import_react10.useEffect)(() => {
|
|
935
665
|
if (authConfig.debug && keycloak?.token) {
|
|
936
|
-
logger.debug("token", keycloak.token);
|
|
666
|
+
import_logger.logger.debug("token", keycloak.token);
|
|
937
667
|
}
|
|
938
668
|
}, [authConfig.debug, keycloak?.token]);
|
|
939
669
|
(0, import_react10.useEffect)(() => {
|
|
940
670
|
if (authConfig.debug && keycloak?.idToken) {
|
|
941
|
-
logger.debug("idToken", keycloak.idToken);
|
|
671
|
+
import_logger.logger.debug("idToken", keycloak.idToken);
|
|
942
672
|
}
|
|
943
673
|
}, [authConfig.debug, keycloak?.idToken]);
|
|
944
674
|
(0, import_react10.useEffect)(() => {
|
|
945
675
|
if (authConfig.debug && keycloak?.refreshToken) {
|
|
946
|
-
logger.debug("refreshToken", keycloak.refreshToken);
|
|
676
|
+
import_logger.logger.debug("refreshToken", keycloak.refreshToken);
|
|
947
677
|
}
|
|
948
678
|
}, [authConfig.debug, keycloak?.refreshToken]);
|
|
949
679
|
(0, import_react10.useEffect)(() => {
|
|
950
680
|
if (authConfig.debug && keycloak?.authenticated) {
|
|
951
|
-
logger.debug("authenticated", keycloak.authenticated);
|
|
681
|
+
import_logger.logger.debug("authenticated", keycloak.authenticated);
|
|
952
682
|
}
|
|
953
683
|
}, [authConfig.debug, keycloak?.authenticated]);
|
|
954
684
|
(0, import_react10.useEffect)(() => {
|
|
955
685
|
if (authConfig.debug && keycloak === null) {
|
|
956
|
-
logger.debug("keycloak disabled");
|
|
686
|
+
import_logger.logger.debug("keycloak disabled");
|
|
957
687
|
}
|
|
958
688
|
}, [authConfig.debug, keycloak]);
|
|
959
689
|
(0, import_react10.useEffect)(() => watchKeycloakBearerTokenRevalidate(), []);
|
|
@@ -962,6 +692,8 @@ function AfterAuth({ children, loadingComponent: _loadingComponent }) {
|
|
|
962
692
|
|
|
963
693
|
// src/provider/authProvider/index.tsx
|
|
964
694
|
var import_keycloak_js = __toESM(require("@multiplatform.one/keycloak-js"));
|
|
695
|
+
var import_platform7 = require("@multiplatform.one/platform");
|
|
696
|
+
var import_logger2 = require("@multiplatform.one/logger");
|
|
965
697
|
var import_react11 = require("react");
|
|
966
698
|
|
|
967
699
|
// src/Loading.tsx
|
|
@@ -1004,7 +736,7 @@ function AuthProvider({
|
|
|
1004
736
|
}) {
|
|
1005
737
|
const { debug, messageHandlerKeys, iframeSso, messageOrigins } = useAuthConfig();
|
|
1006
738
|
const trustedOrigins = (0, import_react11.useMemo)(() => trustedMessageOrigins(messageOrigins), [messageOrigins]);
|
|
1007
|
-
const query = new URLSearchParams(
|
|
739
|
+
const query = new URLSearchParams(import_platform7.isWindowDefined ? window?.location?.search || "" : "");
|
|
1008
740
|
const authStore2 = useAuthStore();
|
|
1009
741
|
const [keycloak, setKeycloak] = (0, import_react11.useState)();
|
|
1010
742
|
const idTokenQuery = query.get("idToken");
|
|
@@ -1016,20 +748,20 @@ function AuthProvider({
|
|
|
1016
748
|
const [loadedMessagePosted, setLoadedMessagePosted] = (0, import_react11.useState)(false);
|
|
1017
749
|
const initialRefreshTokenQuery = (0, import_react11.useMemo)(
|
|
1018
750
|
() => validOrRefreshableToken(
|
|
1019
|
-
!iframeSso &&
|
|
751
|
+
!iframeSso && import_platform7.isIframe || typeof refreshTokenQuery === "string" ? refreshTokenQuery || true : void 0
|
|
1020
752
|
),
|
|
1021
753
|
[refreshTokenQuery, iframeSso]
|
|
1022
754
|
);
|
|
1023
755
|
const initialIdTokenQuery = (0, import_react11.useMemo)(
|
|
1024
756
|
() => validOrRefreshableToken(
|
|
1025
|
-
!iframeSso &&
|
|
757
|
+
!iframeSso && import_platform7.isIframe || typeof idTokenQuery === "string" ? idTokenQuery || true : void 0,
|
|
1026
758
|
initialRefreshTokenQuery
|
|
1027
759
|
),
|
|
1028
760
|
[idTokenQuery, initialRefreshTokenQuery, iframeSso]
|
|
1029
761
|
);
|
|
1030
762
|
const initialTokenQuery = (0, import_react11.useMemo)(
|
|
1031
763
|
() => validOrRefreshableToken(
|
|
1032
|
-
|
|
764
|
+
import_platform7.isIframe ? typeof tokenQuery === "string" ? tokenQuery || true : void 0 : void 0,
|
|
1033
765
|
initialRefreshTokenQuery
|
|
1034
766
|
),
|
|
1035
767
|
[tokenQuery, initialRefreshTokenQuery, iframeSso]
|
|
@@ -1040,7 +772,7 @@ function AuthProvider({
|
|
|
1040
772
|
idToken: initialIdTokenQuery
|
|
1041
773
|
});
|
|
1042
774
|
const authSource = (0, import_react11.useMemo)(() => {
|
|
1043
|
-
if (!iframeSso &&
|
|
775
|
+
if (!iframeSso && import_platform7.isIframe) {
|
|
1044
776
|
if (initialTokenQuery) return "query" /* Query */;
|
|
1045
777
|
return "store" /* Store */;
|
|
1046
778
|
}
|
|
@@ -1093,7 +825,7 @@ function AuthProvider({
|
|
|
1093
825
|
if (disabled || authSource !== "query" /* Query */ || tokens.token === true || tokens.refreshToken === true || tokens.idToken === true || loadedMessagePosted) {
|
|
1094
826
|
return;
|
|
1095
827
|
}
|
|
1096
|
-
if (debug) logger.debug("post message", JSON.stringify({ type: "LOADED" }));
|
|
828
|
+
if (debug) import_logger2.logger.debug("post message", JSON.stringify({ type: "LOADED" }));
|
|
1097
829
|
(messageHandlerKeys || []).forEach((key) => {
|
|
1098
830
|
window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
1099
831
|
});
|
|
@@ -1117,11 +849,11 @@ function AuthProvider({
|
|
|
1117
849
|
} catch {
|
|
1118
850
|
}
|
|
1119
851
|
}
|
|
1120
|
-
if (debug) logger.debug("received message", JSON.stringify(data));
|
|
852
|
+
if (debug) import_logger2.logger.debug("received message", JSON.stringify(data));
|
|
1121
853
|
const message = data;
|
|
1122
854
|
if (!message.type) return;
|
|
1123
855
|
if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
|
|
1124
|
-
if (debug) logger.debug("setting refresh token", message.payload);
|
|
856
|
+
if (debug) import_logger2.logger.debug("setting refresh token", message.payload);
|
|
1125
857
|
setTokens((tokens2) => ({
|
|
1126
858
|
...tokens2,
|
|
1127
859
|
refreshToken: validOrRefreshableToken(message.payload)
|
|
@@ -1131,7 +863,7 @@ function AuthProvider({
|
|
|
1131
863
|
}
|
|
1132
864
|
}
|
|
1133
865
|
if (debug) {
|
|
1134
|
-
logger.debug(
|
|
866
|
+
import_logger2.logger.debug(
|
|
1135
867
|
"listening for message",
|
|
1136
868
|
JSON.stringify({
|
|
1137
869
|
type: "REFRESH_TOKEN",
|
|
@@ -1156,11 +888,11 @@ function AuthProvider({
|
|
|
1156
888
|
} catch {
|
|
1157
889
|
}
|
|
1158
890
|
}
|
|
1159
|
-
if (debug) logger.debug("received message", JSON.stringify(data));
|
|
891
|
+
if (debug) import_logger2.logger.debug("received message", JSON.stringify(data));
|
|
1160
892
|
const message = data;
|
|
1161
893
|
if (!message.type) return;
|
|
1162
894
|
if (message.type.toUpperCase() === "TOKEN" && message.payload) {
|
|
1163
|
-
if (debug) logger.debug("setting token", message.payload);
|
|
895
|
+
if (debug) import_logger2.logger.debug("setting token", message.payload);
|
|
1164
896
|
setTokens((tokens2) => ({
|
|
1165
897
|
...tokens2,
|
|
1166
898
|
token: validOrRefreshableToken(message.payload, tokens2.refreshToken)
|
|
@@ -1170,7 +902,7 @@ function AuthProvider({
|
|
|
1170
902
|
}
|
|
1171
903
|
}
|
|
1172
904
|
if (debug) {
|
|
1173
|
-
logger.debug(
|
|
905
|
+
import_logger2.logger.debug(
|
|
1174
906
|
"listening for message",
|
|
1175
907
|
JSON.stringify({
|
|
1176
908
|
type: "TOKEN",
|
|
@@ -1195,11 +927,11 @@ function AuthProvider({
|
|
|
1195
927
|
} catch {
|
|
1196
928
|
}
|
|
1197
929
|
}
|
|
1198
|
-
if (debug) logger.debug("received message", JSON.stringify(data));
|
|
930
|
+
if (debug) import_logger2.logger.debug("received message", JSON.stringify(data));
|
|
1199
931
|
const message = data;
|
|
1200
932
|
if (!message.type) return;
|
|
1201
933
|
if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
|
|
1202
|
-
if (debug) logger.debug("setting id token", message.payload);
|
|
934
|
+
if (debug) import_logger2.logger.debug("setting id token", message.payload);
|
|
1203
935
|
setTokens((tokens2) => ({
|
|
1204
936
|
...tokens2,
|
|
1205
937
|
idToken: validOrRefreshableToken(message.payload, tokens2.refreshToken)
|
|
@@ -1209,7 +941,7 @@ function AuthProvider({
|
|
|
1209
941
|
}
|
|
1210
942
|
}
|
|
1211
943
|
if (debug) {
|
|
1212
|
-
logger.debug(
|
|
944
|
+
import_logger2.logger.debug(
|
|
1213
945
|
"listening for message",
|
|
1214
946
|
JSON.stringify({
|
|
1215
947
|
type: "ID_TOKEN",
|
|
@@ -1266,7 +998,7 @@ function AuthProvider({
|
|
|
1266
998
|
initOptions2.refreshToken = tokens.refreshToken;
|
|
1267
999
|
}
|
|
1268
1000
|
}
|
|
1269
|
-
if (!iframeSso &&
|
|
1001
|
+
if (!iframeSso && import_platform7.isIframe || tokens.token && !tokens.refreshToken) {
|
|
1270
1002
|
initOptions2.checkLoginIframe = false;
|
|
1271
1003
|
initOptions2.flow = "implicit";
|
|
1272
1004
|
initOptions2.onLoad = void 0;
|
|
@@ -1307,7 +1039,7 @@ function AuthProvider({
|
|
|
1307
1039
|
try {
|
|
1308
1040
|
await keycloakClient.updateToken(5);
|
|
1309
1041
|
} catch (err) {
|
|
1310
|
-
logger.warn(err);
|
|
1042
|
+
import_logger2.logger.warn(err);
|
|
1311
1043
|
setKeycloak(new Keycloak(keycloakConfig, keycloakClient));
|
|
1312
1044
|
}
|
|
1313
1045
|
};
|