@multiplatform.one/keycloak 11.3.0 → 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/esm/index.mjs
CHANGED
|
@@ -1,133 +1,5 @@
|
|
|
1
|
-
// ../platform/src/platform/platformBase.ts
|
|
2
|
-
import {
|
|
3
|
-
isBrowser as isWindowDefined,
|
|
4
|
-
isChrome,
|
|
5
|
-
isClient,
|
|
6
|
-
isServer,
|
|
7
|
-
isTouchable,
|
|
8
|
-
isWeb,
|
|
9
|
-
isWebTouchable
|
|
10
|
-
} from "@tamagui/constants";
|
|
11
|
-
var platformOrder = [
|
|
12
|
-
"Ios",
|
|
13
|
-
"Android",
|
|
14
|
-
// Gnome outranks Native: the GTK target reports isNative (it is not a
|
|
15
|
-
// browser) but "gnome" is the precise answer callers want.
|
|
16
|
-
"Gnome",
|
|
17
|
-
"Native",
|
|
18
|
-
// Tauri outranks Desktop/Web the same way: the webview host reports isWeb
|
|
19
|
-
// and isDesktop, but "tauri" is the precise answer.
|
|
20
|
-
"Tauri",
|
|
21
|
-
"Desktop",
|
|
22
|
-
"ChromeExtension",
|
|
23
|
-
"FirefoxExtension",
|
|
24
|
-
"WebExtension",
|
|
25
|
-
"Next",
|
|
26
|
-
"Expo",
|
|
27
|
-
"Chrome",
|
|
28
|
-
"Firefox",
|
|
29
|
-
"Web",
|
|
30
|
-
"Browser",
|
|
31
|
-
"Client",
|
|
32
|
-
"Server",
|
|
33
|
-
"Iframe",
|
|
34
|
-
"Storybook"
|
|
35
|
-
];
|
|
36
|
-
var platformBase = {
|
|
37
|
-
isAndroid: false,
|
|
38
|
-
isBrowser: false,
|
|
39
|
-
isChrome,
|
|
40
|
-
isChromeExtension: false,
|
|
41
|
-
isClient,
|
|
42
|
-
isDesktop: false,
|
|
43
|
-
isExpo: false,
|
|
44
|
-
isFirefox: false,
|
|
45
|
-
isFirefoxExtension: false,
|
|
46
|
-
isGnome: false,
|
|
47
|
-
isIframe: false,
|
|
48
|
-
isIos: false,
|
|
49
|
-
isNative: false,
|
|
50
|
-
isNext: false,
|
|
51
|
-
isServer,
|
|
52
|
-
isStorybook: isWindowDefined && typeof window.__STORYBOOK_ADDONS_PREVIEW === "object",
|
|
53
|
-
isTauri: false,
|
|
54
|
-
isTouchable,
|
|
55
|
-
isWeb,
|
|
56
|
-
isWebExtension: false,
|
|
57
|
-
isWebTouchable,
|
|
58
|
-
isWindowDefined,
|
|
59
|
-
preciseName: "unknown",
|
|
60
|
-
broadName: "unknown"
|
|
61
|
-
};
|
|
62
|
-
function getPreciseName(platform2) {
|
|
63
|
-
const flags = platform2;
|
|
64
|
-
for (const name of platformOrder) {
|
|
65
|
-
if (flags[`is${name}`]) {
|
|
66
|
-
return `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
67
|
-
}
|
|
68
|
-
}
|
|
69
|
-
return "unknown";
|
|
70
|
-
}
|
|
71
|
-
function getBroadName(platform2) {
|
|
72
|
-
const flags = platform2;
|
|
73
|
-
for (const name of platformOrder.slice().reverse()) {
|
|
74
|
-
if (flags[`is${name}`]) {
|
|
75
|
-
return `${name[0].toLowerCase()}${name.slice(1)}`;
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
return "unknown";
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
// ../platform/src/platform/index.ts
|
|
82
|
-
var isIframe = (() => {
|
|
83
|
-
if (!platformBase.isWindowDefined) return false;
|
|
84
|
-
try {
|
|
85
|
-
return window.self !== window.top;
|
|
86
|
-
} catch {
|
|
87
|
-
return true;
|
|
88
|
-
}
|
|
89
|
-
})();
|
|
90
|
-
var isWebExtension = !!(typeof chrome !== "undefined" && !!chrome?.runtime?.id || typeof browser !== "undefined" && !!browser?.runtime?.id);
|
|
91
|
-
var platform = {
|
|
92
|
-
...platformBase,
|
|
93
|
-
isChromeExtension: typeof chrome !== "undefined" && !!chrome?.runtime?.id,
|
|
94
|
-
isFirefoxExtension: typeof browser !== "undefined" && !!browser?.runtime?.id,
|
|
95
|
-
isIframe,
|
|
96
|
-
isWebExtension,
|
|
97
|
-
isBrowser: !!(platformBase.isWeb && platformBase.isWindowDefined && !isWebExtension),
|
|
98
|
-
isNext: platformBase.isWeb && (!platformBase.isWindowDefined || typeof window.__NEXT_DATA__ === "object"),
|
|
99
|
-
isFirefox: platformBase.isWindowDefined && !!(window?.navigator?.userAgent?.toLowerCase().indexOf("firefox") > -1)
|
|
100
|
-
};
|
|
101
|
-
platform.preciseName = getPreciseName(platform);
|
|
102
|
-
platform.broadName = getBroadName(platform);
|
|
103
|
-
|
|
104
|
-
// ../platform/src/index.ts
|
|
105
|
-
var {
|
|
106
|
-
isAndroid,
|
|
107
|
-
isBrowser,
|
|
108
|
-
isChrome: isChrome2,
|
|
109
|
-
isChromeExtension,
|
|
110
|
-
isClient: isClient2,
|
|
111
|
-
isExpo,
|
|
112
|
-
isFirefox,
|
|
113
|
-
isFirefoxExtension,
|
|
114
|
-
isGnome,
|
|
115
|
-
isIframe: isIframe2,
|
|
116
|
-
isIos,
|
|
117
|
-
isNative,
|
|
118
|
-
isNext,
|
|
119
|
-
isServer: isServer2,
|
|
120
|
-
isStorybook,
|
|
121
|
-
isTauri,
|
|
122
|
-
isDesktop,
|
|
123
|
-
isTouchable: isTouchable2,
|
|
124
|
-
isWeb: isWeb2,
|
|
125
|
-
isWebExtension: isWebExtension2,
|
|
126
|
-
isWebTouchable: isWebTouchable2,
|
|
127
|
-
isWindowDefined: isWindowDefined2
|
|
128
|
-
} = platform;
|
|
129
|
-
|
|
130
1
|
// src/Authenticated.tsx
|
|
2
|
+
import { isIframe as isIframe3, isServer as isServer3 } from "@multiplatform.one/platform";
|
|
131
3
|
import { useEffect } from "react";
|
|
132
4
|
import { Text } from "react-native";
|
|
133
5
|
|
|
@@ -145,95 +17,26 @@ function useAuthConfig() {
|
|
|
145
17
|
}
|
|
146
18
|
|
|
147
19
|
// src/hooks/useTokensFromQuery/index.ts
|
|
20
|
+
import { isIframe } from "@multiplatform.one/platform";
|
|
148
21
|
function useTokensFromQuery() {
|
|
149
22
|
const { iframeSso } = useAuthConfig();
|
|
150
|
-
if (iframeSso || !
|
|
23
|
+
if (iframeSso || !isIframe) return false;
|
|
151
24
|
const query = new URLSearchParams(
|
|
152
25
|
typeof window === "undefined" ? "" : window?.location?.search || ""
|
|
153
26
|
);
|
|
154
27
|
return typeof query.get("idToken") === "string" || typeof query.get("token") === "string" || typeof query.get("refreshToken") === "string";
|
|
155
28
|
}
|
|
156
29
|
|
|
157
|
-
// ../store/src/createStore.ts
|
|
158
|
-
import { Store as Store2 } from "@tanstack/store";
|
|
159
|
-
|
|
160
|
-
// ../store/src/persist.ts
|
|
161
|
-
import { Store } from "@tanstack/store";
|
|
162
|
-
function createPersistStore(initialState, persistOptions) {
|
|
163
|
-
const { key, storage: storage2, serialize = JSON.stringify, deserialize = JSON.parse } = persistOptions;
|
|
164
|
-
let hydrated = false;
|
|
165
|
-
const store = new Store(initialState);
|
|
166
|
-
store.subscribe(() => {
|
|
167
|
-
if (hydrated) {
|
|
168
|
-
const serialized = serialize(store.state);
|
|
169
|
-
void Promise.resolve(storage2.setItem(key, serialized));
|
|
170
|
-
}
|
|
171
|
-
});
|
|
172
|
-
const rehydrate = async () => {
|
|
173
|
-
const raw = await Promise.resolve(storage2.getItem(key));
|
|
174
|
-
if (raw !== null) {
|
|
175
|
-
const deserialized = deserialize(raw);
|
|
176
|
-
store.setState(() => deserialized);
|
|
177
|
-
}
|
|
178
|
-
hydrated = true;
|
|
179
|
-
};
|
|
180
|
-
const clearPersistedState = async () => {
|
|
181
|
-
await Promise.resolve(storage2.removeItem(key));
|
|
182
|
-
};
|
|
183
|
-
void rehydrate();
|
|
184
|
-
const persistStore = store;
|
|
185
|
-
persistStore.rehydrate = rehydrate;
|
|
186
|
-
persistStore.clearPersistedState = clearPersistedState;
|
|
187
|
-
return persistStore;
|
|
188
|
-
}
|
|
189
|
-
|
|
190
|
-
// ../store/src/storage/index.ts
|
|
191
|
-
var noopStorage = {
|
|
192
|
-
getItem: () => null,
|
|
193
|
-
setItem: () => {
|
|
194
|
-
},
|
|
195
|
-
removeItem: () => {
|
|
196
|
-
}
|
|
197
|
-
};
|
|
198
|
-
function getStorage() {
|
|
199
|
-
if (typeof globalThis !== "undefined" && "localStorage" in globalThis && typeof globalThis.localStorage?.getItem === "function") {
|
|
200
|
-
return {
|
|
201
|
-
getItem: (name) => globalThis.localStorage.getItem(name) ?? null,
|
|
202
|
-
setItem: (name, value) => globalThis.localStorage.setItem(name, value),
|
|
203
|
-
removeItem: (name) => globalThis.localStorage.removeItem(name)
|
|
204
|
-
};
|
|
205
|
-
}
|
|
206
|
-
return noopStorage;
|
|
207
|
-
}
|
|
208
|
-
var storage = getStorage();
|
|
209
|
-
|
|
210
|
-
// ../store/src/createStore.ts
|
|
211
|
-
function createStore(initialState, options) {
|
|
212
|
-
if (options?.persist) {
|
|
213
|
-
return createPersistStore(initialState, {
|
|
214
|
-
key: options.name,
|
|
215
|
-
storage: options.storage ?? storage
|
|
216
|
-
});
|
|
217
|
-
}
|
|
218
|
-
return new Store2(initialState);
|
|
219
|
-
}
|
|
220
|
-
|
|
221
|
-
// ../store/src/index.ts
|
|
222
|
-
import { Store as Store3, batch, createStore as createStore2 } from "@tanstack/store";
|
|
223
|
-
import { useStore } from "@tanstack/react-store";
|
|
224
|
-
import { useStore as tanstackUseStore } from "@tanstack/react-store";
|
|
225
|
-
function useStore2(store, selector) {
|
|
226
|
-
return tanstackUseStore(store, selector ?? ((s) => s));
|
|
227
|
-
}
|
|
228
|
-
|
|
229
30
|
// src/state.ts
|
|
230
|
-
|
|
31
|
+
import { createStore, useStore } from "@multiplatform.one/store";
|
|
32
|
+
import { isBrowser, isIframe as isIframe2, isServer } from "@multiplatform.one/platform";
|
|
33
|
+
var persist = isIframe2 || !isBrowser && !isServer;
|
|
231
34
|
var authStore = createStore(
|
|
232
35
|
{ idToken: "", refreshToken: "", token: "" },
|
|
233
36
|
{ name: "auth", persist }
|
|
234
37
|
);
|
|
235
38
|
function useAuthStore() {
|
|
236
|
-
const state =
|
|
39
|
+
const state = useStore(authStore);
|
|
237
40
|
return {
|
|
238
41
|
...state,
|
|
239
42
|
setIdToken: (idToken) => authStore.setState((prev) => ({ ...prev, idToken })),
|
|
@@ -296,29 +99,28 @@ function useTokensFromStore() {
|
|
|
296
99
|
}
|
|
297
100
|
|
|
298
101
|
// src/keycloak/index.ts
|
|
102
|
+
import { isBrowser as isBrowser3, isServer as isServer2, isStorybook, isWeb as isWeb2 } from "@multiplatform.one/platform";
|
|
299
103
|
import { useContext as useContext3 } from "react";
|
|
300
104
|
|
|
301
105
|
// src/betterAuth/client.ts
|
|
302
106
|
import { createAuthClient } from "better-auth/react";
|
|
303
107
|
import { genericOAuthClient } from "better-auth/client/plugins";
|
|
108
|
+
import { isWeb } from "@multiplatform.one/platform";
|
|
304
109
|
var _client;
|
|
305
110
|
function getAuthClient(baseURL) {
|
|
306
111
|
if (_client) return _client;
|
|
307
112
|
_client = createAuthClient({
|
|
308
|
-
baseURL: baseURL || (
|
|
113
|
+
baseURL: baseURL || (isWeb && typeof window !== "undefined" ? window.location.origin : ""),
|
|
309
114
|
plugins: [genericOAuthClient()]
|
|
310
115
|
});
|
|
311
116
|
return _client;
|
|
312
117
|
}
|
|
313
118
|
|
|
314
|
-
//
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
if (status === 400 && body?.code === FAILED_TO_GET_ACCESS_TOKEN) return "signed-out";
|
|
320
|
-
return "transient";
|
|
321
|
-
}
|
|
119
|
+
// src/frappeToken.ts
|
|
120
|
+
import {
|
|
121
|
+
ACCESS_TOKEN_RETRY_DELAYS_MS,
|
|
122
|
+
classifyAccessTokenResponse
|
|
123
|
+
} from "@multiplatform.one/auth/access-token";
|
|
322
124
|
|
|
323
125
|
// src/betterAuth/accountSelection.ts
|
|
324
126
|
var validationErrorCode = "VALIDATION_ERROR";
|
|
@@ -480,10 +282,11 @@ function useAuthError() {
|
|
|
480
282
|
}
|
|
481
283
|
|
|
482
284
|
// src/session/index.ts
|
|
285
|
+
import { isBrowser as isBrowser2 } from "@multiplatform.one/platform";
|
|
483
286
|
var useSession = (_options) => {
|
|
484
287
|
return { session: null, status: "unauthenticated", error: useAuthError() };
|
|
485
288
|
};
|
|
486
|
-
if (
|
|
289
|
+
if (isBrowser2) {
|
|
487
290
|
useSession = (_options) => {
|
|
488
291
|
const client = getAuthClient();
|
|
489
292
|
const { data, isPending, error: sessionError } = client.useSession();
|
|
@@ -669,7 +472,7 @@ var Keycloak = class extends BaseKeycloak {
|
|
|
669
472
|
this._sync();
|
|
670
473
|
} else if (this._login) {
|
|
671
474
|
await this._login(options);
|
|
672
|
-
} else if (
|
|
475
|
+
} else if (isBrowser3 && !isServer2) {
|
|
673
476
|
const client = getAuthClient();
|
|
674
477
|
const result = await client.signIn.social({
|
|
675
478
|
provider: "keycloak",
|
|
@@ -702,7 +505,7 @@ var Keycloak = class extends BaseKeycloak {
|
|
|
702
505
|
}
|
|
703
506
|
window.location.href = `${origin}/api/auth/sign-out/sso?callbackURL=${encodeURIComponent(callbackURL)}`;
|
|
704
507
|
return;
|
|
705
|
-
} else if (
|
|
508
|
+
} else if (isBrowser3 && !isServer2) {
|
|
706
509
|
const client = getAuthClient();
|
|
707
510
|
await client.signOut({
|
|
708
511
|
fetchOptions: {
|
|
@@ -751,7 +554,7 @@ function Authenticated({
|
|
|
751
554
|
const keycloak = useKeycloak();
|
|
752
555
|
const tokensFromQuery = useTokensFromQuery();
|
|
753
556
|
useEffect(() => {
|
|
754
|
-
if (!keycloak || !authConfig.iframeSso &&
|
|
557
|
+
if (!keycloak || !authConfig.iframeSso && isIframe3 || isServer3 || keycloak.authenticated || tokensFromQuery) {
|
|
755
558
|
return;
|
|
756
559
|
}
|
|
757
560
|
keycloak?.login({
|
|
@@ -772,86 +575,8 @@ function withAuthenticated(Component, options = {}) {
|
|
|
772
575
|
return (props) => /* @__PURE__ */ jsx(Authenticated, { ...options, children: /* @__PURE__ */ jsx(Component, { ...props }) });
|
|
773
576
|
}
|
|
774
577
|
|
|
775
|
-
// ../logger/src/base.ts
|
|
776
|
-
import log from "loglevel";
|
|
777
|
-
var defaultLoggerConfig = {
|
|
778
|
-
name: "default",
|
|
779
|
-
type: "pretty",
|
|
780
|
-
level: true ? 1 /* Debug */ : 2 /* Info */
|
|
781
|
-
};
|
|
782
|
-
var BaseLogger = class {
|
|
783
|
-
constructor(config = {}) {
|
|
784
|
-
const { metadata, name, level } = typeof config === "string" ? { metadata: void 0, name: config, level: void 0 } : config;
|
|
785
|
-
this.metadata = metadata || {};
|
|
786
|
-
this.name = name || "default";
|
|
787
|
-
this.logger = name ? log.getLogger(name) : log;
|
|
788
|
-
if (level !== void 0) this.logger.setLevel(level);
|
|
789
|
-
this.transport = this.createTransport?.();
|
|
790
|
-
}
|
|
791
|
-
trace(...args) {
|
|
792
|
-
this.logger.trace(...args);
|
|
793
|
-
this.sendToTransport(0 /* Trace */, args);
|
|
794
|
-
}
|
|
795
|
-
debug(...args) {
|
|
796
|
-
this.logger.debug(...args);
|
|
797
|
-
this.sendToTransport(1 /* Debug */, args);
|
|
798
|
-
}
|
|
799
|
-
info(...args) {
|
|
800
|
-
this.logger.info(...args);
|
|
801
|
-
this.sendToTransport(2 /* Info */, args);
|
|
802
|
-
}
|
|
803
|
-
warn(...args) {
|
|
804
|
-
this.logger.warn(...args);
|
|
805
|
-
this.sendToTransport(3 /* Warn */, args);
|
|
806
|
-
}
|
|
807
|
-
error(...args) {
|
|
808
|
-
this.logger.error(...args);
|
|
809
|
-
this.sendToTransport(4 /* Error */, args);
|
|
810
|
-
}
|
|
811
|
-
log(...args) {
|
|
812
|
-
this.logger.debug(...args);
|
|
813
|
-
this.sendToTransport(1 /* Debug */, args);
|
|
814
|
-
}
|
|
815
|
-
sendToTransport(level, args) {
|
|
816
|
-
if (this.transport) {
|
|
817
|
-
this.transport.send({
|
|
818
|
-
level,
|
|
819
|
-
message: args[0],
|
|
820
|
-
args: args.slice(1),
|
|
821
|
-
platform: platform.preciseName,
|
|
822
|
-
timestamp: (/* @__PURE__ */ new Date()).toISOString()
|
|
823
|
-
});
|
|
824
|
-
}
|
|
825
|
-
}
|
|
826
|
-
getSubLogger(input) {
|
|
827
|
-
const subConfig = typeof input === "string" ? {
|
|
828
|
-
name: input,
|
|
829
|
-
metadata: this.metadata,
|
|
830
|
-
level: this.logger.getLevel()
|
|
831
|
-
} : {
|
|
832
|
-
...input,
|
|
833
|
-
metadata: { ...this.metadata, ...input.metadata }
|
|
834
|
-
};
|
|
835
|
-
return new this.constructor(subConfig);
|
|
836
|
-
}
|
|
837
|
-
};
|
|
838
|
-
|
|
839
|
-
// ../logger/src/index.ts
|
|
840
|
-
var Logger = class extends BaseLogger {
|
|
841
|
-
constructor(config = {}) {
|
|
842
|
-
const metadata = {
|
|
843
|
-
platform: platform.preciseName
|
|
844
|
-
};
|
|
845
|
-
super({
|
|
846
|
-
name: metadata.platform,
|
|
847
|
-
...typeof config === "string" ? { name: config } : config,
|
|
848
|
-
metadata
|
|
849
|
-
});
|
|
850
|
-
}
|
|
851
|
-
};
|
|
852
|
-
var logger = new Logger();
|
|
853
|
-
|
|
854
578
|
// src/provider/AfterAuth.tsx
|
|
579
|
+
import { logger } from "@multiplatform.one/logger";
|
|
855
580
|
import { useEffect as useEffect2 } from "react";
|
|
856
581
|
import { Fragment as Fragment2, jsx as jsx2 } from "react/jsx-runtime";
|
|
857
582
|
function AfterAuth({ children, loadingComponent: _loadingComponent }) {
|
|
@@ -908,6 +633,8 @@ function AfterAuth({ children, loadingComponent: _loadingComponent }) {
|
|
|
908
633
|
|
|
909
634
|
// src/provider/authProvider/index.tsx
|
|
910
635
|
import KeycloakClient from "@multiplatform.one/keycloak-js";
|
|
636
|
+
import { isIframe as isIframe4, isWindowDefined } from "@multiplatform.one/platform";
|
|
637
|
+
import { logger as logger2 } from "@multiplatform.one/logger";
|
|
911
638
|
import { useCallback, useEffect as useEffect3, useMemo, useState } from "react";
|
|
912
639
|
|
|
913
640
|
// src/Loading.tsx
|
|
@@ -950,7 +677,7 @@ function AuthProvider({
|
|
|
950
677
|
}) {
|
|
951
678
|
const { debug, messageHandlerKeys, iframeSso, messageOrigins } = useAuthConfig();
|
|
952
679
|
const trustedOrigins = useMemo(() => trustedMessageOrigins(messageOrigins), [messageOrigins]);
|
|
953
|
-
const query = new URLSearchParams(
|
|
680
|
+
const query = new URLSearchParams(isWindowDefined ? window?.location?.search || "" : "");
|
|
954
681
|
const authStore2 = useAuthStore();
|
|
955
682
|
const [keycloak, setKeycloak] = useState();
|
|
956
683
|
const idTokenQuery = query.get("idToken");
|
|
@@ -962,20 +689,20 @@ function AuthProvider({
|
|
|
962
689
|
const [loadedMessagePosted, setLoadedMessagePosted] = useState(false);
|
|
963
690
|
const initialRefreshTokenQuery = useMemo(
|
|
964
691
|
() => validOrRefreshableToken(
|
|
965
|
-
!iframeSso &&
|
|
692
|
+
!iframeSso && isIframe4 || typeof refreshTokenQuery === "string" ? refreshTokenQuery || true : void 0
|
|
966
693
|
),
|
|
967
694
|
[refreshTokenQuery, iframeSso]
|
|
968
695
|
);
|
|
969
696
|
const initialIdTokenQuery = useMemo(
|
|
970
697
|
() => validOrRefreshableToken(
|
|
971
|
-
!iframeSso &&
|
|
698
|
+
!iframeSso && isIframe4 || typeof idTokenQuery === "string" ? idTokenQuery || true : void 0,
|
|
972
699
|
initialRefreshTokenQuery
|
|
973
700
|
),
|
|
974
701
|
[idTokenQuery, initialRefreshTokenQuery, iframeSso]
|
|
975
702
|
);
|
|
976
703
|
const initialTokenQuery = useMemo(
|
|
977
704
|
() => validOrRefreshableToken(
|
|
978
|
-
|
|
705
|
+
isIframe4 ? typeof tokenQuery === "string" ? tokenQuery || true : void 0 : void 0,
|
|
979
706
|
initialRefreshTokenQuery
|
|
980
707
|
),
|
|
981
708
|
[tokenQuery, initialRefreshTokenQuery, iframeSso]
|
|
@@ -986,7 +713,7 @@ function AuthProvider({
|
|
|
986
713
|
idToken: initialIdTokenQuery
|
|
987
714
|
});
|
|
988
715
|
const authSource = useMemo(() => {
|
|
989
|
-
if (!iframeSso &&
|
|
716
|
+
if (!iframeSso && isIframe4) {
|
|
990
717
|
if (initialTokenQuery) return "query" /* Query */;
|
|
991
718
|
return "store" /* Store */;
|
|
992
719
|
}
|
|
@@ -1039,7 +766,7 @@ function AuthProvider({
|
|
|
1039
766
|
if (disabled || authSource !== "query" /* Query */ || tokens.token === true || tokens.refreshToken === true || tokens.idToken === true || loadedMessagePosted) {
|
|
1040
767
|
return;
|
|
1041
768
|
}
|
|
1042
|
-
if (debug)
|
|
769
|
+
if (debug) logger2.debug("post message", JSON.stringify({ type: "LOADED" }));
|
|
1043
770
|
(messageHandlerKeys || []).forEach((key) => {
|
|
1044
771
|
window?.webkit?.messageHandlers?.[key]?.postMessage(JSON.stringify({ type: "LOADED" }));
|
|
1045
772
|
});
|
|
@@ -1063,11 +790,11 @@ function AuthProvider({
|
|
|
1063
790
|
} catch {
|
|
1064
791
|
}
|
|
1065
792
|
}
|
|
1066
|
-
if (debug)
|
|
793
|
+
if (debug) logger2.debug("received message", JSON.stringify(data));
|
|
1067
794
|
const message = data;
|
|
1068
795
|
if (!message.type) return;
|
|
1069
796
|
if (message.type.toUpperCase() === "REFRESH_TOKEN" && message.payload) {
|
|
1070
|
-
if (debug)
|
|
797
|
+
if (debug) logger2.debug("setting refresh token", message.payload);
|
|
1071
798
|
setTokens((tokens2) => ({
|
|
1072
799
|
...tokens2,
|
|
1073
800
|
refreshToken: validOrRefreshableToken(message.payload)
|
|
@@ -1077,7 +804,7 @@ function AuthProvider({
|
|
|
1077
804
|
}
|
|
1078
805
|
}
|
|
1079
806
|
if (debug) {
|
|
1080
|
-
|
|
807
|
+
logger2.debug(
|
|
1081
808
|
"listening for message",
|
|
1082
809
|
JSON.stringify({
|
|
1083
810
|
type: "REFRESH_TOKEN",
|
|
@@ -1102,11 +829,11 @@ function AuthProvider({
|
|
|
1102
829
|
} catch {
|
|
1103
830
|
}
|
|
1104
831
|
}
|
|
1105
|
-
if (debug)
|
|
832
|
+
if (debug) logger2.debug("received message", JSON.stringify(data));
|
|
1106
833
|
const message = data;
|
|
1107
834
|
if (!message.type) return;
|
|
1108
835
|
if (message.type.toUpperCase() === "TOKEN" && message.payload) {
|
|
1109
|
-
if (debug)
|
|
836
|
+
if (debug) logger2.debug("setting token", message.payload);
|
|
1110
837
|
setTokens((tokens2) => ({
|
|
1111
838
|
...tokens2,
|
|
1112
839
|
token: validOrRefreshableToken(message.payload, tokens2.refreshToken)
|
|
@@ -1116,7 +843,7 @@ function AuthProvider({
|
|
|
1116
843
|
}
|
|
1117
844
|
}
|
|
1118
845
|
if (debug) {
|
|
1119
|
-
|
|
846
|
+
logger2.debug(
|
|
1120
847
|
"listening for message",
|
|
1121
848
|
JSON.stringify({
|
|
1122
849
|
type: "TOKEN",
|
|
@@ -1141,11 +868,11 @@ function AuthProvider({
|
|
|
1141
868
|
} catch {
|
|
1142
869
|
}
|
|
1143
870
|
}
|
|
1144
|
-
if (debug)
|
|
871
|
+
if (debug) logger2.debug("received message", JSON.stringify(data));
|
|
1145
872
|
const message = data;
|
|
1146
873
|
if (!message.type) return;
|
|
1147
874
|
if (message.type.toUpperCase() === "ID_TOKEN" && message.payload) {
|
|
1148
|
-
if (debug)
|
|
875
|
+
if (debug) logger2.debug("setting id token", message.payload);
|
|
1149
876
|
setTokens((tokens2) => ({
|
|
1150
877
|
...tokens2,
|
|
1151
878
|
idToken: validOrRefreshableToken(message.payload, tokens2.refreshToken)
|
|
@@ -1155,7 +882,7 @@ function AuthProvider({
|
|
|
1155
882
|
}
|
|
1156
883
|
}
|
|
1157
884
|
if (debug) {
|
|
1158
|
-
|
|
885
|
+
logger2.debug(
|
|
1159
886
|
"listening for message",
|
|
1160
887
|
JSON.stringify({
|
|
1161
888
|
type: "ID_TOKEN",
|
|
@@ -1212,7 +939,7 @@ function AuthProvider({
|
|
|
1212
939
|
initOptions2.refreshToken = tokens.refreshToken;
|
|
1213
940
|
}
|
|
1214
941
|
}
|
|
1215
|
-
if (!iframeSso &&
|
|
942
|
+
if (!iframeSso && isIframe4 || tokens.token && !tokens.refreshToken) {
|
|
1216
943
|
initOptions2.checkLoginIframe = false;
|
|
1217
944
|
initOptions2.flow = "implicit";
|
|
1218
945
|
initOptions2.onLoad = void 0;
|
|
@@ -1253,7 +980,7 @@ function AuthProvider({
|
|
|
1253
980
|
try {
|
|
1254
981
|
await keycloakClient.updateToken(5);
|
|
1255
982
|
} catch (err) {
|
|
1256
|
-
|
|
983
|
+
logger2.warn(err);
|
|
1257
984
|
setKeycloak(new Keycloak(keycloakConfig, keycloakClient));
|
|
1258
985
|
}
|
|
1259
986
|
};
|