@shellui/core 0.7.0 → 0.8.1
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/LICENSE +21 -0
- package/README.md +3 -1
- package/package.json +2 -2
- package/schemas/shellui.config.schema.json +45 -2
- package/src/app.tsx +2 -0
- package/src/features/auth/AuthProvider.tsx +212 -97
- package/src/features/auth/appBackend/configSchema.spec.ts +1 -0
- package/src/features/auth/appBackend/frameAuth.ts +5 -0
- package/src/features/auth/backends/shellui.spec.ts +110 -0
- package/src/features/auth/backends/shellui.ts +47 -20
- package/src/features/auth/backends/types.ts +5 -0
- package/src/features/auth/hooks/useAuth.tsx +6 -1
- package/src/features/auth/types.ts +5 -0
- package/src/features/auth/utils/bffAuthClient.spec.ts +313 -0
- package/src/features/auth/utils/bffAuthClient.ts +171 -49
- package/src/features/auth/utils/buildSessionFromParams.ts +5 -2
- package/src/features/auth/utils/buildSessionFromTokenPayload.spec.ts +12 -0
- package/src/features/auth/utils/buildSessionFromTokenPayload.ts +3 -1
- package/src/features/auth/utils/canRestoreStoredSession.spec.ts +140 -4
- package/src/features/auth/utils/canRestoreStoredSession.ts +47 -0
- package/src/features/auth/utils/cliCallback.ts +5 -0
- package/src/features/auth/utils/identityBrowserLogout.spec.ts +185 -0
- package/src/features/auth/utils/identityBrowserLogout.ts +174 -0
- package/src/features/auth/utils/index.ts +21 -3
- package/src/features/auth/utils/isBffAuthEnabled.ts +10 -2
- package/src/features/auth/utils/normalizeAuthSettings.spec.ts +9 -0
- package/src/features/auth/utils/normalizeAuthSettings.ts +3 -1
- package/src/features/auth/utils/pkce.spec.ts +29 -1
- package/src/features/auth/utils/pkce.ts +106 -2
- package/src/features/config/types.ts +37 -5
- package/src/features/mcp/mcpActivityErrorCodeI18n.spec.ts +32 -0
- package/src/features/mcp/mcpActivityErrorCodeI18n.ts +30 -0
- package/src/features/mcp/mcpAgentActivityMerge.spec.ts +91 -0
- package/src/features/mcp/mcpAgentActivityMerge.ts +53 -0
- package/src/features/mcp/mcpAgentActivityPresentation.spec.ts +129 -0
- package/src/features/mcp/mcpAgentActivityPresentation.ts +201 -0
- package/src/features/mcp/mcpAgentsConnect.spec.ts +215 -0
- package/src/features/mcp/mcpAgentsConnect.ts +189 -0
- package/src/features/mcp/mcpToolActivityRegistry.spec.ts +9 -0
- package/src/features/mcp/mcpToolActivityRegistry.ts +20 -0
- package/src/features/mcp/mcpToolApprovalsApi.spec.ts +113 -0
- package/src/features/mcp/mcpToolApprovalsApi.ts +162 -0
- package/src/features/mcp/personalAgentsApi.spec.ts +661 -0
- package/src/features/mcp/personalAgentsApi.ts +697 -0
- package/src/features/settings/SettingsIcons.tsx +28 -0
- package/src/features/settings/SettingsRoutes.tsx +8 -0
- package/src/features/settings/SettingsView.tsx +90 -26
- package/src/features/settings/components/McpAgentActivitySection.spec.tsx +255 -0
- package/src/features/settings/components/McpAgentActivitySection.tsx +481 -0
- package/src/features/settings/components/McpAgents.spec.tsx +336 -0
- package/src/features/settings/components/McpAgents.tsx +654 -0
- package/src/features/settings/components/McpPendingApprovals.spec.tsx +201 -0
- package/src/features/settings/components/McpPendingApprovals.tsx +168 -0
- package/src/features/settings/components/McpPersonalStatusPrefetch.tsx +21 -0
- package/src/features/settings/hooks/useMcpPendingToolApprovals.ts +69 -0
- package/src/features/settings/hooks/useMcpPersonalStatus.ts +83 -0
- package/src/features/settings/utils/buildSettingsForPropagation.spec.ts +44 -1
- package/src/features/settings/utils/buildSettingsForPropagation.ts +30 -1
- package/src/features/settings/utils/isMcpAgentsSettingsEligible.spec.ts +25 -0
- package/src/features/settings/utils/isMcpAgentsSettingsEligible.ts +14 -0
- package/src/features/settings/utils/loadMcpPersonalStatus.spec.ts +76 -0
- package/src/features/settings/utils/loadMcpPersonalStatus.ts +84 -0
- package/src/features/settings/utils/mcpPersonalStatusCache.spec.ts +77 -0
- package/src/features/settings/utils/mcpPersonalStatusCache.ts +95 -0
- package/src/features/settings/utils/shouldShowMcpAgentsSettings.spec.ts +66 -0
- package/src/features/settings/utils/shouldShowMcpAgentsSettings.ts +16 -0
- package/src/features/storage/StorageBridge.paths.spec.ts +286 -0
- package/src/features/storage/StorageBridge.tsx +25 -5
- package/src/features/storage/resolveStorageBridgeTarget.spec.ts +51 -0
- package/src/features/storage/resolveStorageBridgeTarget.ts +24 -0
- package/src/i18n/translations/en/settings.json +201 -0
- package/src/i18n/translations/fr/settings.json +201 -0
- package/src/index.ts +1 -0
- package/src/service-worker/sw.ts +4 -2
|
@@ -16,24 +16,29 @@ import { isSilentAuthCallbackFrame } from './appBackend/silentSignIn';
|
|
|
16
16
|
import { createAuthBackend } from './backends';
|
|
17
17
|
import { AuthContext, type AuthContextValue, type OAuthCallbackResult } from './hooks/useAuth';
|
|
18
18
|
import type { AuthEvent, AuthSession, AuthUser, UserPreferences } from './types';
|
|
19
|
+
import { clearMcpPersonalStatusCache } from '../settings/utils/mcpPersonalStatusCache';
|
|
19
20
|
import {
|
|
20
21
|
AuthRequestError,
|
|
21
22
|
clearStoredAuthSession,
|
|
22
|
-
|
|
23
|
+
exchangeShellSessionCode,
|
|
23
24
|
getAccessTokenFromSdkSettings,
|
|
24
25
|
getAuthRequestErrorCode,
|
|
25
26
|
getUserFromSdkSettings,
|
|
27
|
+
hasPendingCliCallback,
|
|
26
28
|
hashHasOAuthTokens,
|
|
27
29
|
hasStoredAuthSession,
|
|
28
30
|
inferAccessPendingErrorCode,
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
isBffAuthExplicitlyDisabled,
|
|
32
|
+
isUnauthorizedRefreshError,
|
|
33
|
+
planStoredSessionBoot,
|
|
31
34
|
isSessionExpired,
|
|
32
35
|
isTokenAutoRefreshDisabled,
|
|
33
36
|
logoutBffAuthSession,
|
|
34
37
|
persistAuthSession,
|
|
35
38
|
readStoredAuthSession,
|
|
36
39
|
refreshBffAuthSession,
|
|
40
|
+
rememberHostCookieSession,
|
|
41
|
+
resolveBffAuthRoutes,
|
|
37
42
|
shareInFlight,
|
|
38
43
|
toAuthSessionFromSettingsUser,
|
|
39
44
|
type InFlightSlot,
|
|
@@ -54,6 +59,7 @@ import {
|
|
|
54
59
|
import { normalizeDesktopScheme } from './utils/desktopAuthCallback';
|
|
55
60
|
import type { DeleteAccountResultStatus, UpdateProfileResult } from './shellAccountRequests';
|
|
56
61
|
import { accessTokenRefreshDue } from './utils/accessTokenRefreshDue';
|
|
62
|
+
import { finishShellSignOut, resolveLogoutReturnTo } from './utils/identityBrowserLogout';
|
|
57
63
|
import { registerFrameSessionRefresher } from './utils/frameSessionRefresher';
|
|
58
64
|
|
|
59
65
|
const logger = getLogger('shellcore');
|
|
@@ -90,35 +96,67 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
90
96
|
const { config } = useConfig();
|
|
91
97
|
const { i18n } = useTranslation();
|
|
92
98
|
const tauriRuntime = useIsTauriRuntime();
|
|
93
|
-
const
|
|
99
|
+
const bffExplicitlyDisabled = isBffAuthExplicitlyDisabled(config.security);
|
|
100
|
+
const shelluiBackend = config.backend?.type === 'shellui';
|
|
101
|
+
/** Host routes answered the probe. The refresh token is not in page storage. */
|
|
102
|
+
const [hostCookieActive, setHostCookieActive] = useState(false);
|
|
103
|
+
/**
|
|
104
|
+
* Cookie refresh returned 401 while this tab still holds a refresh token from
|
|
105
|
+
* a path that does not use the host (URL fragment, legacy provider code).
|
|
106
|
+
* Later refreshes skip the host so they do not repeat that 401.
|
|
107
|
+
*/
|
|
108
|
+
const cookieRefreshSkippedRef = useRef(false);
|
|
94
109
|
const backend = useMemo(
|
|
95
110
|
() => createAuthBackend(config.backend),
|
|
96
111
|
[config.backend?.publishableKey, config.backend?.type, config.backend?.url],
|
|
97
112
|
);
|
|
98
113
|
|
|
114
|
+
const refreshUsesHostCookie = useCallback(async () => {
|
|
115
|
+
const ready = await resolveBffAuthRoutes({
|
|
116
|
+
backendType: shelluiBackend ? 'shellui' : config.backend?.type,
|
|
117
|
+
explicitlyDisabled: bffExplicitlyDisabled,
|
|
118
|
+
});
|
|
119
|
+
setHostCookieActive(ready);
|
|
120
|
+
return ready;
|
|
121
|
+
}, [bffExplicitlyDisabled, config.backend?.type, shelluiBackend]);
|
|
122
|
+
|
|
99
123
|
const commitAuthSession = useCallback(
|
|
100
|
-
async (
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
}
|
|
124
|
+
async (
|
|
125
|
+
nextSession: AuthSession,
|
|
126
|
+
options?: { hideRefreshToken?: boolean },
|
|
127
|
+
): Promise<AuthSession> => {
|
|
128
|
+
if (options?.hideRefreshToken) {
|
|
129
|
+
return rememberHostCookieSession(nextSession);
|
|
107
130
|
}
|
|
108
131
|
persistAuthSession(nextSession);
|
|
109
132
|
return nextSession;
|
|
110
133
|
},
|
|
111
|
-
[
|
|
134
|
+
[],
|
|
112
135
|
);
|
|
113
136
|
|
|
114
137
|
const refreshAuthSession = useCallback(
|
|
115
138
|
async (current: AuthSession, nowSeconds: number): Promise<AuthSession | null> => {
|
|
116
|
-
|
|
117
|
-
|
|
139
|
+
const useHost = (await refreshUsesHostCookie()) && !cookieRefreshSkippedRef.current;
|
|
140
|
+
if (!useHost) {
|
|
141
|
+
return backend.refreshAuthSession(current, nowSeconds);
|
|
142
|
+
}
|
|
143
|
+
try {
|
|
144
|
+
const viaCookie = await refreshBffAuthSession(current, nowSeconds);
|
|
145
|
+
if (!viaCookie) return null;
|
|
146
|
+
return rememberHostCookieSession(viaCookie);
|
|
147
|
+
} catch (err) {
|
|
148
|
+
// The page already holds a refresh token from a path the host does not
|
|
149
|
+
// exchange (fragment or legacy provider code). Refresh that token
|
|
150
|
+
// directly. Do not post it to the host.
|
|
151
|
+
const pageRefresh = current.refreshToken || readStoredAuthSession()?.refreshToken || '';
|
|
152
|
+
if (!isUnauthorizedRefreshError(err) || !pageRefresh) {
|
|
153
|
+
throw err;
|
|
154
|
+
}
|
|
155
|
+
cookieRefreshSkippedRef.current = true;
|
|
156
|
+
return backend.refreshAuthSession({ ...current, refreshToken: pageRefresh }, nowSeconds);
|
|
118
157
|
}
|
|
119
|
-
return backend.refreshAuthSession(current, nowSeconds);
|
|
120
158
|
},
|
|
121
|
-
[backend,
|
|
159
|
+
[backend, refreshUsesHostCookie],
|
|
122
160
|
);
|
|
123
161
|
|
|
124
162
|
/**
|
|
@@ -129,7 +167,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
129
167
|
const ensureFreshAccessToken = useCallback(async (): Promise<string | null> => {
|
|
130
168
|
const current = sessionRef.current;
|
|
131
169
|
if (!current?.accessToken) return null;
|
|
132
|
-
if (!
|
|
170
|
+
if (!hostCookieActive && !current.refreshToken) return current.accessToken;
|
|
133
171
|
|
|
134
172
|
const now = Math.floor(Date.now() / 1000);
|
|
135
173
|
if (!accessTokenRefreshDue(current.expiresAt, now)) return current.accessToken;
|
|
@@ -152,7 +190,11 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
152
190
|
try {
|
|
153
191
|
const next = await refreshAuthSession(current, now);
|
|
154
192
|
if (!next) return sessionRef.current?.accessToken ?? null;
|
|
155
|
-
|
|
193
|
+
if (next.refreshToken) {
|
|
194
|
+
persistAuthSession(next);
|
|
195
|
+
} else {
|
|
196
|
+
rememberHostCookieSession(next);
|
|
197
|
+
}
|
|
156
198
|
sessionRef.current = next;
|
|
157
199
|
setSession(next);
|
|
158
200
|
return next.accessToken;
|
|
@@ -160,6 +202,9 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
160
202
|
logger.error('Token refresh failed', { err });
|
|
161
203
|
const message = err instanceof Error ? err.message : '';
|
|
162
204
|
if (/\b401\b/.test(message)) {
|
|
205
|
+
// Refresh failed in this tab (including after another tab cleared the
|
|
206
|
+
// shared BFF cookie). Drop the local session only. The identity
|
|
207
|
+
// browser logout navigation belongs to the tab that called logout().
|
|
163
208
|
clearStoredAuthSession();
|
|
164
209
|
sessionRef.current = null;
|
|
165
210
|
setSession(null);
|
|
@@ -173,7 +218,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
173
218
|
|
|
174
219
|
refreshInFlightRef.current = flight.current;
|
|
175
220
|
return flight.current;
|
|
176
|
-
}, [
|
|
221
|
+
}, [hostCookieActive, refreshAuthSession]);
|
|
177
222
|
|
|
178
223
|
const [session, setSession] = useState<AuthSession | null>(null);
|
|
179
224
|
const [isLoading, setIsLoading] = useState(hasInitialSessionToResolve);
|
|
@@ -216,10 +261,11 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
216
261
|
if (sessionFromHash) {
|
|
217
262
|
if (!cancelled) {
|
|
218
263
|
try {
|
|
219
|
-
const committed = await commitAuthSession(sessionFromHash
|
|
264
|
+
const committed = await commitAuthSession(sessionFromHash);
|
|
220
265
|
setSession(committed);
|
|
221
266
|
} catch {
|
|
222
|
-
|
|
267
|
+
// Keep the refresh token so a reload can still restore this fragment session.
|
|
268
|
+
persistAuthSession(sessionFromHash, { storeRefreshToken: true });
|
|
223
269
|
setSession(sessionFromHash);
|
|
224
270
|
}
|
|
225
271
|
setAuthEvent('oauth_callback');
|
|
@@ -254,17 +300,6 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
254
300
|
return;
|
|
255
301
|
}
|
|
256
302
|
|
|
257
|
-
// A new tab has the shared profile but not the tab-scoped refresh token. Treat it as
|
|
258
|
-
// signed out instead of a signed-in session with no token. Keep storage: another tab
|
|
259
|
-
// may still own this session.
|
|
260
|
-
if (!canRestoreStoredSession(stored, bffAuthEnabled)) {
|
|
261
|
-
if (!cancelled) {
|
|
262
|
-
setSession(null);
|
|
263
|
-
setIsLoading(false);
|
|
264
|
-
}
|
|
265
|
-
return;
|
|
266
|
-
}
|
|
267
|
-
|
|
268
303
|
const applyRestoredSession = async (source: AuthSession) => {
|
|
269
304
|
try {
|
|
270
305
|
const restored = await shareInFlight(restoreRefreshSlot, () =>
|
|
@@ -281,60 +316,68 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
281
316
|
return;
|
|
282
317
|
}
|
|
283
318
|
// Persist even when cancelled so a rotated refresh token is not lost mid-remount.
|
|
284
|
-
|
|
319
|
+
if (restored.refreshToken) {
|
|
320
|
+
persistAuthSession(restored);
|
|
321
|
+
} else {
|
|
322
|
+
rememberHostCookieSession(restored);
|
|
323
|
+
}
|
|
285
324
|
if (!cancelled) {
|
|
286
325
|
setSession(restored);
|
|
287
326
|
setIsLoading(false);
|
|
288
327
|
}
|
|
289
|
-
} catch {
|
|
290
|
-
|
|
328
|
+
} catch (err) {
|
|
329
|
+
// 401: the BFF cookie or refresh token cannot restore this profile.
|
|
330
|
+
// Clear it even if this mount was cancelled, so login is not stuck on it.
|
|
331
|
+
if (!cancelled || isUnauthorizedRefreshError(err)) {
|
|
291
332
|
clearStoredAuthSession();
|
|
333
|
+
}
|
|
334
|
+
if (!cancelled) {
|
|
292
335
|
setSession(null);
|
|
293
336
|
setIsLoading(false);
|
|
294
337
|
}
|
|
295
338
|
}
|
|
296
339
|
};
|
|
297
340
|
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
if (!cancelled) {
|
|
301
|
-
setSession(stored);
|
|
302
|
-
setIsLoading(false);
|
|
303
|
-
}
|
|
304
|
-
return;
|
|
305
|
-
}
|
|
306
|
-
await applyRestoredSession(stored);
|
|
307
|
-
return;
|
|
308
|
-
}
|
|
341
|
+
const useHost = await refreshUsesHostCookie();
|
|
342
|
+
if (cancelled) return;
|
|
309
343
|
|
|
310
|
-
|
|
344
|
+
const plan = planStoredSessionBoot(stored, useHost, {
|
|
345
|
+
autoRefreshDisabled: isTokenAutoRefreshDisabled(),
|
|
346
|
+
});
|
|
347
|
+
|
|
348
|
+
// Profile with nothing to refresh (host routes absent, no refresh token).
|
|
349
|
+
// Drop it so the next paint is a normal login.
|
|
350
|
+
if (plan.action === 'clear') {
|
|
351
|
+
clearStoredAuthSession();
|
|
311
352
|
if (!cancelled) {
|
|
312
|
-
setSession(
|
|
353
|
+
setSession(null);
|
|
313
354
|
setIsLoading(false);
|
|
314
355
|
}
|
|
315
356
|
return;
|
|
316
357
|
}
|
|
317
358
|
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
359
|
+
if (plan.action === 'use') {
|
|
360
|
+
// Keep the expired session so apps can exercise 401 / re-auth flows locally.
|
|
361
|
+
if (isTokenAutoRefreshDisabled() && stored.accessToken && isSessionExpired(stored)) {
|
|
362
|
+
logger.info(
|
|
363
|
+
'Skipped session restore refresh because Develop → Disable token auto-refresh is on',
|
|
364
|
+
);
|
|
365
|
+
}
|
|
323
366
|
if (!cancelled) {
|
|
324
|
-
setSession(
|
|
367
|
+
setSession(plan.session);
|
|
325
368
|
setIsLoading(false);
|
|
326
369
|
}
|
|
327
370
|
return;
|
|
328
371
|
}
|
|
329
372
|
|
|
330
|
-
await applyRestoredSession(
|
|
373
|
+
await applyRestoredSession(plan.session);
|
|
331
374
|
};
|
|
332
375
|
|
|
333
376
|
void initializeSession();
|
|
334
377
|
return () => {
|
|
335
378
|
cancelled = true;
|
|
336
379
|
};
|
|
337
|
-
}, [backend,
|
|
380
|
+
}, [backend, commitAuthSession, refreshAuthSession, refreshUsesHostCookie]);
|
|
338
381
|
|
|
339
382
|
useEffect(() => {
|
|
340
383
|
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
@@ -345,7 +388,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
345
388
|
if (typeof window === 'undefined' || window.parent !== window || isLoading) {
|
|
346
389
|
return;
|
|
347
390
|
}
|
|
348
|
-
if (!session || (!
|
|
391
|
+
if (!session || (!hostCookieActive && !session.refreshToken)) {
|
|
349
392
|
return;
|
|
350
393
|
}
|
|
351
394
|
|
|
@@ -362,7 +405,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
362
405
|
window.clearInterval(intervalId);
|
|
363
406
|
stopResume();
|
|
364
407
|
};
|
|
365
|
-
}, [
|
|
408
|
+
}, [hostCookieActive, ensureFreshAccessToken, isLoading, session, session?.expiresAt]);
|
|
366
409
|
|
|
367
410
|
useEffect(() => {
|
|
368
411
|
if (typeof window === 'undefined' || window.parent === window) {
|
|
@@ -433,18 +476,21 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
433
476
|
);
|
|
434
477
|
|
|
435
478
|
const persistOAuthSession = useCallback(
|
|
436
|
-
async (nextSession: AuthSession) => {
|
|
437
|
-
const now = Math.floor(Date.now() / 1000);
|
|
479
|
+
async (nextSession: AuthSession, options?: { hideRefreshToken?: boolean }) => {
|
|
438
480
|
try {
|
|
439
|
-
const committed = await commitAuthSession(nextSession,
|
|
481
|
+
const committed = await commitAuthSession(nextSession, options);
|
|
440
482
|
setSession(committed);
|
|
441
483
|
} catch {
|
|
442
|
-
|
|
443
|
-
|
|
484
|
+
if (options?.hideRefreshToken) {
|
|
485
|
+
setSession(rememberHostCookieSession(nextSession));
|
|
486
|
+
} else {
|
|
487
|
+
persistAuthSession(nextSession, { storeRefreshToken: true });
|
|
488
|
+
setSession(nextSession);
|
|
489
|
+
}
|
|
444
490
|
}
|
|
445
491
|
setAuthEvent('oauth_callback');
|
|
446
492
|
},
|
|
447
|
-
[
|
|
493
|
+
[commitAuthSession],
|
|
448
494
|
);
|
|
449
495
|
|
|
450
496
|
const mapOAuthCallbackError = useCallback((err: unknown): OAuthCallbackResult => {
|
|
@@ -472,11 +518,22 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
472
518
|
setError(null);
|
|
473
519
|
setErrorCode(null);
|
|
474
520
|
const now = Math.floor(Date.now() / 1000);
|
|
475
|
-
|
|
521
|
+
// `shellui login` still needs the refresh token so it can hand it to the CLI.
|
|
522
|
+
const cliCallbackPending = hasPendingCliCallback();
|
|
523
|
+
const useBff = !cliCallbackPending && (await refreshUsesHostCookie());
|
|
524
|
+
const nextSession = await exchangeShellSessionCode({
|
|
525
|
+
useBff,
|
|
476
526
|
authCode,
|
|
477
527
|
redirectTo,
|
|
478
528
|
codeVerifier,
|
|
479
529
|
nowSeconds: now,
|
|
530
|
+
exchangeDirect: () =>
|
|
531
|
+
backend.exchangeOAuthSessionCode({
|
|
532
|
+
authCode,
|
|
533
|
+
redirectTo,
|
|
534
|
+
codeVerifier,
|
|
535
|
+
nowSeconds: now,
|
|
536
|
+
}),
|
|
480
537
|
});
|
|
481
538
|
if (!nextSession) {
|
|
482
539
|
const message = 'Unable to complete OAuth login.';
|
|
@@ -484,13 +541,19 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
484
541
|
setErrorCode(null);
|
|
485
542
|
return { ok: false, error: message, errorCode: null };
|
|
486
543
|
}
|
|
487
|
-
|
|
544
|
+
const cookieHoldsRefresh = useBff && !nextSession.refreshToken;
|
|
545
|
+
if (cookieHoldsRefresh) {
|
|
546
|
+
cookieRefreshSkippedRef.current = false;
|
|
547
|
+
} else if (useBff) {
|
|
548
|
+
setHostCookieActive(false);
|
|
549
|
+
}
|
|
550
|
+
await persistOAuthSession(nextSession, { hideRefreshToken: cookieHoldsRefresh });
|
|
488
551
|
return { ok: true };
|
|
489
552
|
} catch (err) {
|
|
490
553
|
return mapOAuthCallbackError(err);
|
|
491
554
|
}
|
|
492
555
|
},
|
|
493
|
-
[backend, mapOAuthCallbackError, persistOAuthSession],
|
|
556
|
+
[backend, mapOAuthCallbackError, persistOAuthSession, refreshUsesHostCookie],
|
|
494
557
|
);
|
|
495
558
|
|
|
496
559
|
const completeOAuthCallback = useCallback(
|
|
@@ -541,8 +604,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
541
604
|
setErrorCode(null);
|
|
542
605
|
return false;
|
|
543
606
|
}
|
|
544
|
-
const
|
|
545
|
-
const committed = await commitAuthSession(nextSession, now);
|
|
607
|
+
const committed = await commitAuthSession(nextSession);
|
|
546
608
|
setSession(committed);
|
|
547
609
|
return true;
|
|
548
610
|
} catch (err) {
|
|
@@ -624,7 +686,11 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
624
686
|
// Keep stored snapshot aligned with what we synced (JWT claims can lag the PUT).
|
|
625
687
|
nextSession = { ...nextSession, userPreferences: preferences };
|
|
626
688
|
if (typeof window !== 'undefined' && window.parent === window) {
|
|
627
|
-
|
|
689
|
+
if (nextSession.refreshToken) {
|
|
690
|
+
persistAuthSession(nextSession);
|
|
691
|
+
} else {
|
|
692
|
+
rememberHostCookieSession(nextSession);
|
|
693
|
+
}
|
|
628
694
|
}
|
|
629
695
|
setSession(nextSession);
|
|
630
696
|
}
|
|
@@ -632,7 +698,7 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
632
698
|
logger.error('Failed to sync user preferences to auth provider metadata', { err });
|
|
633
699
|
}
|
|
634
700
|
},
|
|
635
|
-
[backend,
|
|
701
|
+
[backend, refreshAuthSession],
|
|
636
702
|
);
|
|
637
703
|
|
|
638
704
|
const loadUserPreferences = useCallback(async () => {
|
|
@@ -644,28 +710,75 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
644
710
|
}
|
|
645
711
|
}, [backend, session]);
|
|
646
712
|
|
|
647
|
-
const logout = useCallback(
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
// Even if API sign-out fails, still clear local session.
|
|
655
|
-
}
|
|
713
|
+
const logout = useCallback(
|
|
714
|
+
async (options?: { returnTo?: string }) => {
|
|
715
|
+
const topLevel = typeof window !== 'undefined' && window.parent === window;
|
|
716
|
+
// The desktop webview does not hold the identity cookie (sign-in opens
|
|
717
|
+
// the system browser). Navigating it would leave the app.
|
|
718
|
+
const initiatedHere = topLevel && !isLiveTauriRuntime();
|
|
719
|
+
const current = sessionRef.current;
|
|
656
720
|
|
|
657
|
-
|
|
658
|
-
|
|
659
|
-
|
|
660
|
-
|
|
661
|
-
|
|
721
|
+
const navigated = await finishShellSignOut({
|
|
722
|
+
revoke: async () => {
|
|
723
|
+
try {
|
|
724
|
+
const useHost = await refreshUsesHostCookie();
|
|
725
|
+
if (useHost) {
|
|
726
|
+
await logoutBffAuthSession(current?.accessToken);
|
|
727
|
+
}
|
|
728
|
+
// A fragment or legacy session still has the refresh token in the page.
|
|
729
|
+
// The host never receives that token. Revoke it directly.
|
|
730
|
+
if (!useHost || current?.refreshToken) {
|
|
731
|
+
await backend.logout(current);
|
|
732
|
+
}
|
|
733
|
+
} catch {
|
|
734
|
+
// Even if API sign-out fails, still clear the local session.
|
|
735
|
+
}
|
|
736
|
+
try {
|
|
737
|
+
await endAppBackendSessions();
|
|
738
|
+
} catch {
|
|
739
|
+
// App-server sign-out is best effort. The shell session still clears.
|
|
740
|
+
}
|
|
741
|
+
},
|
|
742
|
+
clearLocal: () => {
|
|
743
|
+
clearStoredAuthSession();
|
|
744
|
+
clearMcpPersonalStatusCache();
|
|
745
|
+
sessionRef.current = null;
|
|
746
|
+
setSession(null);
|
|
747
|
+
setAuthEvent(null);
|
|
748
|
+
setError(null);
|
|
749
|
+
setErrorCode(null);
|
|
750
|
+
},
|
|
751
|
+
readBrowserLogoutUrl: async () => {
|
|
752
|
+
const resolve = backend.resolveIdentityBrowserLogoutUrl;
|
|
753
|
+
if (!resolve || typeof window === 'undefined') return null;
|
|
754
|
+
const returnTo = resolveLogoutReturnTo({
|
|
755
|
+
origin: window.location.origin,
|
|
756
|
+
pathname: window.location.pathname,
|
|
757
|
+
search: window.location.search,
|
|
758
|
+
navigation: config.navigation,
|
|
759
|
+
returnTo: options?.returnTo,
|
|
760
|
+
});
|
|
761
|
+
if (!returnTo) return null;
|
|
762
|
+
return resolve(returnTo);
|
|
763
|
+
},
|
|
764
|
+
navigate: (url) => {
|
|
765
|
+
window.location.replace(url);
|
|
766
|
+
},
|
|
767
|
+
initiatedHere,
|
|
768
|
+
});
|
|
662
769
|
|
|
663
|
-
|
|
664
|
-
|
|
665
|
-
|
|
666
|
-
|
|
667
|
-
|
|
668
|
-
|
|
770
|
+
if (!navigated && options?.returnTo && topLevel && typeof window !== 'undefined') {
|
|
771
|
+
const local = resolveLogoutReturnTo({
|
|
772
|
+
origin: window.location.origin,
|
|
773
|
+
pathname: window.location.pathname,
|
|
774
|
+
search: window.location.search,
|
|
775
|
+
returnTo: options.returnTo,
|
|
776
|
+
});
|
|
777
|
+
if (local) window.location.assign(local);
|
|
778
|
+
}
|
|
779
|
+
},
|
|
780
|
+
[backend, config.navigation, refreshUsesHostCookie],
|
|
781
|
+
);
|
|
669
782
|
|
|
670
783
|
useEffect(() => {
|
|
671
784
|
if (typeof window === 'undefined' || window.parent !== window) return;
|
|
@@ -734,12 +847,16 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
734
847
|
const current = sessionRef.current;
|
|
735
848
|
if (current) {
|
|
736
849
|
const next = { ...current, userName: saved.name };
|
|
737
|
-
|
|
850
|
+
if (next.refreshToken) {
|
|
851
|
+
persistAuthSession(next);
|
|
852
|
+
} else {
|
|
853
|
+
rememberHostCookieSession(next);
|
|
854
|
+
}
|
|
738
855
|
setSession(next);
|
|
739
856
|
}
|
|
740
857
|
return saved;
|
|
741
858
|
},
|
|
742
|
-
[backend,
|
|
859
|
+
[backend, session],
|
|
743
860
|
);
|
|
744
861
|
|
|
745
862
|
useEffect(() => {
|
|
@@ -890,10 +1007,8 @@ export const AuthProvider = ({ children }: { children: ReactNode }) => {
|
|
|
890
1007
|
okLabel: t('userAccount.deleteAccount.reauthAction'),
|
|
891
1008
|
cancelLabel: t('userAccount.deleteAccount.cancel'),
|
|
892
1009
|
onOk: () => {
|
|
893
|
-
void logout(
|
|
894
|
-
|
|
895
|
-
buildAuthUrlWithNext(urls.login, `${urls.settings}/user`),
|
|
896
|
-
);
|
|
1010
|
+
void logout({
|
|
1011
|
+
returnTo: buildAuthUrlWithNext(urls.login, `${urls.settings}/user`),
|
|
897
1012
|
});
|
|
898
1013
|
},
|
|
899
1014
|
});
|
|
@@ -29,6 +29,7 @@ describe('shellui.config schema app backend', () => {
|
|
|
29
29
|
expect(navigationItem.properties?.email).toBeTruthy();
|
|
30
30
|
expect(navigationItem.properties?.storage).toBeTruthy();
|
|
31
31
|
expect(navigationItem.properties?.hosting).toBeTruthy();
|
|
32
|
+
expect(navigationItem.properties?.aiService).toBeTruthy();
|
|
32
33
|
expect(navigationItem.properties?.safeForAuthToken).toBeTruthy();
|
|
33
34
|
expect(appBackend.additionalProperties).toBe(false);
|
|
34
35
|
expect(appBackend.required).toEqual(['url']);
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Settings } from '@shellui/sdk';
|
|
2
2
|
import type {
|
|
3
|
+
AiServiceConfig,
|
|
3
4
|
EmailConfig,
|
|
4
5
|
HostingConfig,
|
|
5
6
|
NavigationItem,
|
|
@@ -20,6 +21,7 @@ export type FrameServiceOverrides = {
|
|
|
20
21
|
storage?: StorageConfig | null;
|
|
21
22
|
email?: EmailConfig | null;
|
|
22
23
|
hosting?: HostingConfig | null;
|
|
24
|
+
aiService?: AiServiceConfig | null;
|
|
23
25
|
};
|
|
24
26
|
|
|
25
27
|
export type FrameAuthDelivery = {
|
|
@@ -101,6 +103,8 @@ function serviceOverrides(item: NavigationItem | null, failClosed: boolean): Fra
|
|
|
101
103
|
else if (failClosed) overrides.email = null;
|
|
102
104
|
if (item?.hosting !== undefined) overrides.hosting = item.hosting;
|
|
103
105
|
else if (failClosed) overrides.hosting = null;
|
|
106
|
+
if (item?.aiService !== undefined) overrides.aiService = item.aiService;
|
|
107
|
+
else if (failClosed) overrides.aiService = null;
|
|
104
108
|
return overrides;
|
|
105
109
|
}
|
|
106
110
|
|
|
@@ -148,6 +152,7 @@ export type FrameAuthPropagationOptions = {
|
|
|
148
152
|
storage?: StorageConfig | null;
|
|
149
153
|
email?: EmailConfig | null;
|
|
150
154
|
hosting?: HostingConfig | null;
|
|
155
|
+
aiService?: AiServiceConfig | null;
|
|
151
156
|
};
|
|
152
157
|
|
|
153
158
|
function toPropagationOptions(delivery: FrameAuthDelivery): FrameAuthPropagationOptions {
|