Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(auth): keep the desktop re-login modal reachable and stop the 14-day OIDC grant cap (#19245)

Inneid95aececfbcd
diff --git a/src/libs/oidc-provider/provider.test.ts b/src/libs/oidc-provider/provider.test.ts
index 8580b134640..ce518bb613f 100644
--- a/src/libs/oidc-provider/provider.test.ts
+++ b/src/libs/oidc-provider/provider.test.ts
@@ -116,7 +116,7 @@ describe('OIDC Provider - Market Client Integration', () => {
BackchannelAuthenticationRequest: 600,
ClientCredentials: 600,
DeviceCode: 600,
- Grant: 14 * 24 * 60 * 60,
+ Grant: 365 * 24 * 60 * 60,
IdToken: 3600,
Interaction: 3600,
RefreshToken: 30 * 24 * 60 * 60,
@@ -132,6 +132,23 @@ describe('OIDC Provider - Market Client Integration', () => {
vi.doUnmock('@/envs/app');
}, 10000);
+ it('keeps the grant alive longer than a rotating refresh token', async () => {
+ vi.doMock('@/envs/app', () => ({
+ appEnv: {
+ APP_URL: 'https://example.com',
+ MARKET_BASE_URL: undefined,
+ },
+ }));
+
+ const { oidcArtifactTTL } = await import('./provider');
+ const dayFifteen = 15 * 24 * 60 * 60;
+
+ expect(oidcArtifactTTL.Grant).toBeGreaterThan(dayFifteen);
+ expect(oidcArtifactTTL.Grant).toBeGreaterThanOrEqual(oidcArtifactTTL.RefreshToken);
+
+ vi.doUnmock('@/envs/app');
+ }, 10000);
+
it('should have createOIDCProvider function', async () => {
vi.doMock('@/envs/app', () => ({
appEnv: {
diff --git a/src/libs/oidc-provider/provider.ts b/src/libs/oidc-provider/provider.ts
index 172b83a8108..c000df0176f 100644
--- a/src/libs/oidc-provider/provider.ts
+++ b/src/libs/oidc-provider/provider.ts
@@ -30,7 +30,9 @@ export const oidcArtifactTTL = {
BackchannelAuthenticationRequest: 10 * MINUTE_SECONDS,
ClientCredentials: 10 * MINUTE_SECONDS,
DeviceCode: 10 * MINUTE_SECONDS,
- Grant: 14 * DAY_SECONDS,
+ // oidc-provider never extends Grant.exp on refresh, so this is the absolute cap on a
+ // signed-in session no matter how often the refresh token rotates.
+ Grant: 365 * DAY_SECONDS,
IdToken: HOUR_SECONDS,
Interaction: HOUR_SECONDS,
RefreshToken: 30 * DAY_SECONDS,
diff --git a/src/routes/(main)/_layout/DesktopAutoOidcOnFirstOpen.tsx b/src/routes/(main)/_layout/DesktopAutoOidcOnFirstOpen.tsx
index 1a2af92c948..d8920d18027 100644
--- a/src/routes/(main)/_layout/DesktopAutoOidcOnFirstOpen.tsx
+++ b/src/routes/(main)/_layout/DesktopAutoOidcOnFirstOpen.tsx
@@ -56,4 +56,6 @@ const DesktopAutoOidcOnFirstOpen = memo(() => {
return null;
});
+DesktopAutoOidcOnFirstOpen.displayName = 'DesktopAutoOidcOnFirstOpen';
+
export default DesktopAutoOidcOnFirstOpen;
diff --git a/src/routes/(main)/_layout/authMount.test.ts b/src/routes/(main)/_layout/authMount.test.ts
new file mode 100644
index 00000000000..bc4e8b23a08
--- /dev/null
+++ b/src/routes/(main)/_layout/authMount.test.ts
@@ -0,0 +1,92 @@
+import { Children, type FC, isValidElement, type ReactElement, type ReactNode } from 'react';
+import { describe, expect, it, vi } from 'vitest';
+
+const { nullComponent, passthrough } = vi.hoisted(() => ({
+ nullComponent: () => ({ default: () => null }),
+ passthrough: () => ({ default: ({ children }: { children?: unknown }) => children }),
+}));
+
+vi.mock('@/const/version', () => ({ isDesktop: true }));
+vi.mock('@/hooks/usePlatform', () => ({ usePlatform: () => ({ isPWA: false }) }));
+vi.mock('@/store/serverConfig', () => ({
+ featureFlagsSelectors: () => ({ showCloudPromotion: false }),
+ useServerConfigStore: (selector: (s: unknown) => unknown) => selector({}),
+}));
+vi.mock('@/libs/next/dynamic', () => ({ default: () => () => null }));
+vi.mock('@/features/Electron/shell', () => ({
+ useDesktopDocumentTitle: () => {},
+ useLastWorkspaceSlugSync: () => {},
+ useWindowUrlMirror: () => {},
+}));
+vi.mock('@/features/Electron/TabHost', () => ({
+ TabHost: () => null,
+ useSeedTabsOnBoot: () => {},
+}));
+vi.mock('@/features/ResourceManager/DndContextWrapper', () => ({ DndContextWrapper: () => null }));
+vi.mock('@/features/AlertBanner/CloudBanner', () => ({ BANNER_HEIGHT: 0, default: () => null }));
+vi.mock('@/features/RouteMeta', () => ({ RouteMetaBridge: () => null }));
+vi.mock('./style', () => ({ styles: {} }));
+vi.mock('react-router', () => ({ Outlet: () => null }));
+
+vi.mock('@/components/Skeleton/RouteSegment', nullComponent);
+vi.mock('@/features/DesktopBrowserGatewayBridge', nullComponent);
+vi.mock('@/features/DesktopFileMenuBridge', nullComponent);
+vi.mock('@/features/DesktopLayoutContainer', passthrough);
+vi.mock('@/features/DesktopNavigationBridge', nullComponent);
+vi.mock('@/features/Electron/ActiveConversationBridge', nullComponent);
+vi.mock('@/features/Electron/ScreenCapture/OverlayCaptureUploader', nullComponent);
+vi.mock('@/features/Electron/ScreenCapture/OverlayMessageDispatcher', nullComponent);
+vi.mock('@/features/Electron/ScreenCapture/OverlaySnapshotPublisher', nullComponent);
+vi.mock('@/features/Electron/system/ZoomHUD', nullComponent);
+vi.mock('@/features/Electron/titlebar/TabBar/TabCacheBridges', nullComponent);
+vi.mock('@/features/Electron/titlebar/TitleBar', nullComponent);
+vi.mock('@/features/HotkeyHelperPanel', nullComponent);
+vi.mock('@/features/NavPanel/Shell', nullComponent);
+vi.mock('@/layout/GlobalProvider/CmdkLazy', nullComponent);
+vi.mock('./RegisterHotkeys', nullComponent);
+vi.mock('../home', nullComponent);
+vi.mock('../home/_layout', passthrough);
+
+const nameOf = (type: unknown): string | undefined =>
+ (type as { displayName?: string; name?: string } | null)?.displayName ??
+ (type as { name?: string } | null)?.name;
+
+const findByName = (
+ node: ReactNode,
+ name: string,
+): ReactElement<{ children?: ReactNode }> | undefined => {
+ let hit: ReactElement<{ children?: ReactNode }> | undefined;
+ Children.forEach(node, (child) => {
+ if (hit || !isValidElement(child)) return;
+ if (nameOf(child.type) === name) {
+ hit = child as ReactElement<{ children?: ReactNode }>;
+ return;
+ }
+ hit = findByName((child.props as { children?: ReactNode }).children, name);
+ });
+ return hit;
+};
+
+const layouts = [
+ ['desktop', () => import('./index.desktop')],
+ ['web', () => import('./index')],
+] as const;
+
+describe.each(layouts)('main layout (%s)', (_name, load) => {
+ it(
+ 'keeps auth recovery outside WorkspaceContextSlot so a blocked shell cannot hide it',
+ { timeout: 20_000 },
+ async () => {
+ const { default: Layout } = await load();
+
+ const tree = await (Layout as FC)({});
+ const slot = findByName(tree, 'WorkspaceContextSlot');
+
+ expect(slot).toBeDefined();
+ for (const name of ['AuthRequiredModal', 'DesktopAutoOidcOnFirstOpen']) {
+ expect(findByName(tree, name)).toBeDefined();
+ expect(findByName(slot!.props.children, name)).toBeUndefined();
+ }
+ },
+ );
+});
diff --git a/src/routes/(main)/_layout/index.desktop.tsx b/src/routes/(main)/_layout/index.desktop.tsx
index fa47b50993f..4743f488f58 100644
--- a/src/routes/(main)/_layout/index.desktop.tsx
+++ b/src/routes/(main)/_layout/index.desktop.tsx
@@ -55,11 +55,12 @@ const Layout: FC = () => {
return (
<HotkeysProvider initiallyActiveScopes={[HotkeyScopeEnum.Global]}>
+ <DesktopAutoOidcOnFirstOpen />
+ <AuthRequiredModal />
<WorkspaceContextSlot>
<ActiveConversationBridge />
<TabCacheBridges />
<Suspense fallback={null}>
- <DesktopAutoOidcOnFirstOpen />
<DesktopNavigationBridge />
<DesktopFileMenuBridge />
<DesktopBrowserGatewayBridge />
@@ -68,7 +69,6 @@ const Layout: FC = () => {
<OverlayMessageDispatcher />
{showCloudPromotion && <CloudBanner />}
</Suspense>
- <AuthRequiredModal />
<ZoomHUD />
<Suspense fallback={null}>
diff --git a/src/routes/(main)/_layout/index.tsx b/src/routes/(main)/_layout/index.tsx
index 3ab59dd3dae..615b3854b79 100644
--- a/src/routes/(main)/_layout/index.tsx
+++ b/src/routes/(main)/_layout/index.tsx
@@ -48,11 +48,12 @@ const Layout: FC = () => {
return (
<HotkeysProvider initiallyActiveScopes={[HotkeyScopeEnum.Global]}>
+ {isDesktop && <DesktopAutoOidcOnFirstOpen />}
+ {isDesktop && <AuthRequiredModal />}
<WorkspaceContextSlot>
<RouteMetaBridge />
{isDesktop && <TabCacheBridges />}
<Suspense fallback={null}>
- {isDesktop && <DesktopAutoOidcOnFirstOpen />}
{isDesktop && <DesktopNavigationBridge />}
{isDesktop && <DesktopFileMenuBridge />}
{isDesktop && <DesktopBrowserGatewayBridge />}
@@ -61,7 +62,6 @@ const Layout: FC = () => {
{isDesktop && <OverlayMessageDispatcher />}
{showCloudPromotion && <CloudBanner />}
</Suspense>
- {isDesktop && <AuthRequiredModal />}
{isDesktop && <ZoomHUD />}
<Suspense fallback={null}>{isDesktop && <TitleBar />}</Suspense>