Skip to content

The open-source agent harness - the runtime layer that turns an LLM into a working agent.

refactor: enhance authentication flow and UI components (#114)

Sujai Kumar Gupta2601304f230a
diff --git a/packages/frontend/src/App.tsx b/packages/frontend/src/App.tsx
index 12a8f2421..435a75269 100644
--- a/packages/frontend/src/App.tsx
+++ b/packages/frontend/src/App.tsx
@@ -1,12 +1,13 @@
import { createTrueFoundryServer, TrueforgeUI, type SlotOverrides } from '@truefoundry/trueforge-ui';
import { useEffect, useMemo, useState } from 'react';
import { AuthErrorScreen } from './AuthErrorScreen';
-import { isLoggedOutSearch, parseAuthErrorReason } from './authStatusSearch';
+import { probeSession, type SessionState } from './authSession';
+import { parseAuthErrorReason } from './authStatusSearch';
import { getCapabilities, listModels } from './composerLists';
import { createConnectorCatalog } from './connectorCatalog';
+import { GetStartedScreen } from './GetStartedScreen';
import { createHarnessBuilderServer } from './harnessBuilderServer';
import { createHarnessChatServer, type HarnessAgentSpec } from './harnessServer';
-import { LoggedOutScreen } from './LoggedOutScreen';
import { LogoutButton } from './LogoutButton';
import { createModelProviderCatalog } from './modelProviderCatalog';
import { createSandboxProviderCatalog } from './sandboxProviderCatalog';
@@ -31,14 +32,29 @@ type BootState =
| { status: 'ready'; defaultAgentSpec: HarnessAgentSpec; openSettings: boolean };
export function App() {
- const search = window.location.search;
- const loggedOut = isLoggedOutSearch(search);
- const authError = parseAuthErrorReason(search);
- const skipBoot = loggedOut || authError != null;
+ const authError = parseAuthErrorReason(window.location.search);
+ const [session, setSession] = useState<SessionState | 'checking'>('checking');
const [boot, setBoot] = useState<BootState>({ status: 'loading' });
+ // Gate boot on a non-redirecting `/me` probe: unauthenticated users see the
+ // welcome screen instead of being bounced to login by the auth-aware fetch.
useEffect(() => {
- if (skipBoot) {
+ if (authError != null) {
+ return;
+ }
+ const state = { cancelled: false };
+ void probeSession().then(result => {
+ if (!state.cancelled) {
+ setSession(result);
+ }
+ });
+ return () => {
+ state.cancelled = true;
+ };
+ }, [authError]);
+
+ useEffect(() => {
+ if (session !== 'authenticated') {
return;
}
const state = { cancelled: false };
@@ -85,18 +101,22 @@ export function App() {
return () => {
state.cancelled = true;
};
- }, [skipBoot]);
+ }, [session]);
const overrides: SlotOverrides = useMemo(() => ({ ShellActionsActionSlot: LogoutButton }), []);
- if (loggedOut) {
- return <LoggedOutScreen />;
- }
-
if (authError != null) {
return <AuthErrorScreen reason={authError} />;
}
+ if (session === 'checking') {
+ return <div className="boot-screen">Loading application…</div>;
+ }
+
+ if (session === 'unauthenticated') {
+ return <GetStartedScreen />;
+ }
+
if (boot.status === 'error') {
return (
<div className="boot-screen" data-error="true">
diff --git a/packages/frontend/src/AuthErrorScreen.tsx b/packages/frontend/src/AuthErrorScreen.tsx
index 494d0fefe..8ed1f51d9 100644
--- a/packages/frontend/src/AuthErrorScreen.tsx
+++ b/packages/frontend/src/AuthErrorScreen.tsx
@@ -1,12 +1,20 @@
-import { AuthStatusCard } from './AuthStatusCard';
+import { BrandIcon } from '@truefoundry/trueforge-ui';
+import { AUTH_LOGIN_HREF } from './authFetch';
+import './authScreens.css';
-/** OIDC / login failure status. */
+/** OIDC / login failure status. Mirrors the welcome page layout. */
export function AuthErrorScreen({ reason }: { reason: string }) {
+ const message = reason === 'login_failed' ? 'We couldn’t complete sign-in. Please try again.' : reason;
return (
- <AuthStatusCard
- kind="error"
- title="Sign-in failed"
- description={reason === 'login_failed' ? 'We could not complete sign-in. Return home to try again.' : reason}
- />
+ <main className="auth-screen">
+ <div className="auth-screen-card">
+ <BrandIcon className="auth-screen-logo" />
+ <h1 className="auth-screen-title">Sign-in failed</h1>
+ <p className="auth-screen-message">{message}</p>
+ <a className="auth-screen-button" href={AUTH_LOGIN_HREF}>
+ Try again
+ </a>
+ </div>
+ </main>
);
}
diff --git a/packages/frontend/src/AuthStatusCard.css b/packages/frontend/src/AuthStatusCard.css
deleted file mode 100644
index f68e12d30..000000000
--- a/packages/frontend/src/AuthStatusCard.css
+++ /dev/null
@@ -1,74 +0,0 @@
-/* Shared by AuthErrorScreen / LoggedOutScreen — mirrors PostMcpOauthScreen layout. */
-
-.auth-status {
- min-height: 100dvh;
- display: flex;
- align-items: center;
- justify-content: center;
- padding: 1.5rem;
- background: var(--background);
- color: var(--foreground);
-}
-
-.auth-status-card {
- display: flex;
- width: 100%;
- max-width: 28rem;
- flex-direction: column;
- align-items: center;
- gap: 0.75rem;
- border: 1px solid color-mix(in srgb, var(--foreground) 12%, transparent);
- border-radius: 1rem;
- background: color-mix(in srgb, var(--background) 88%, var(--foreground));
- padding: 2rem;
- text-align: center;
- box-shadow: 0 1px 2px color-mix(in srgb, #000 20%, transparent);
-}
-
-.auth-status-icon {
- width: 4rem;
- height: 4rem;
- flex-shrink: 0;
-}
-
-.auth-status-icon--success {
- color: #4ade80;
-}
-
-.auth-status-icon--error {
- color: var(--destructive);
-}
-
-.auth-status-title {
- margin: 0;
- font-size: 1.5rem;
- font-weight: 600;
- line-height: 1.25;
- color: var(--foreground);
-}
-
-.auth-status-description {
- margin: 0;
- font-size: 0.875rem;
- line-height: 1.5rem;
- color: var(--muted-foreground);
-}
-
-.auth-status-home {
- margin-top: 0.75rem;
- display: inline-flex;
- min-height: 2.25rem;
- align-items: center;
- justify-content: center;
- border-radius: 0.5rem;
- padding: 0 1rem;
- background: var(--foreground);
- color: var(--background);
- font-size: 0.875rem;
- font-weight: 600;
- text-decoration: none;
-}
-
-.auth-status-home:hover {
- filter: brightness(0.92);
-}
diff --git a/packages/frontend/src/AuthStatusCard.tsx b/packages/frontend/src/AuthStatusCard.tsx
deleted file mode 100644
index 53aa5a8f6..000000000
--- a/packages/frontend/src/AuthStatusCard.tsx
+++ /dev/null
@@ -1,45 +0,0 @@
-import type { ReactNode } from 'react';
-import './AuthStatusCard.css';
-
-export type AuthStatusKind = 'success' | 'error';
-
-function StatusIcon({ kind }: { kind: AuthStatusKind }): ReactNode {
- if (kind === 'success') {
- return (
- <svg className="auth-status-icon auth-status-icon--success" viewBox="0 0 64 64" aria-hidden>
- <circle cx="32" cy="32" r="30" fill="none" stroke="currentColor" strokeWidth="3" />
- <path
- d="M18 33.5 27.5 43 46 22"
- fill="none"
- stroke="currentColor"
- strokeWidth="3.5"
- strokeLinecap="round"
- strokeLinejoin="round"
- />
- </svg>
- );
- }
-
- return (
- <svg className="auth-status-icon auth-status-icon--error" viewBox="0 0 64 64" aria-hidden>
- <circle cx="32" cy="32" r="30" fill="none" stroke="currentColor" strokeWidth="3" />
- <path d="M22 22 42 42M42 22 22 42" fill="none" stroke="currentColor" strokeWidth="3.5" strokeLinecap="round" />
- </svg>
- );
-}
-
-/** Centered card shell (same layout idea as {@link PostMcpOauthScreen}). */
-export function AuthStatusCard(params: { kind: AuthStatusKind; title: string; description: string }) {
- return (
- <main className="auth-status">
- <div className="auth-status-card">
- <StatusIcon kind={params.kind} />
- <h1 className="auth-status-title">{params.title}</h1>
- <p className="auth-status-description">{params.description}</p>
- <a className="auth-status-home" href="/">
- Go to home
- </a>
- </div>
- </main>
- );
-}
diff --git a/packages/frontend/src/GetStartedScreen.tsx b/packages/frontend/src/GetStartedScreen.tsx
new file mode 100644
index 000000000..3439b585a
--- /dev/null
+++ b/packages/frontend/src/GetStartedScreen.tsx
@@ -0,0 +1,27 @@
+import { BrandIcon } from '@truefoundry/trueforge-ui';
+import { AUTH_LOGIN_HREF } from './authFetch';
+import './authScreens.css';
+
+/**
+ * Pre-auth welcome gate. Rendered when the session probe (`/me`) is unauthenticated
+ * (OIDC configured but no session cookie yet). "Let's Get Started" starts OIDC login.
+ */
+export function GetStartedScreen() {
+ return (
+ <main className="auth-screen">
+ <div className="auth-screen-card">
+ <BrandIcon className="auth-screen-logo" />
+ <h1 className="auth-screen-title">Welcome to TrueForge</h1>
+ <button
+ type="button"
+ className="auth-screen-button"
+ onClick={() => {
+ window.location.assign(AUTH_LOGIN_HREF);
+ }}
+ >
+ Let&apos;s Get Started
+ </button>
+ </div>
+ </main>
+ );
+}
diff --git a/packages/frontend/src/LoggedOutScreen.tsx b/packages/frontend/src/LoggedOutScreen.tsx
deleted file mode 100644
index bb6890e23..000000000
--- a/packages/frontend/src/LoggedOutScreen.tsx
+++ /dev/null
@@ -1,12 +0,0 @@
-import { AuthStatusCard } from './AuthStatusCard';
-
-/** Post-logout confirmation (not an error). */
-export function LoggedOutScreen() {
- return (
- <AuthStatusCard
- kind="success"
- title="Signed out"
- description="Your session has ended. Return home to sign in again."
- />
- );
-}
diff --git a/packages/frontend/src/LogoutButton.css b/packages/frontend/src/LogoutButton.css
new file mode 100644
index 000000000..86eda96f0
--- /dev/null
+++ b/packages/frontend/src/LogoutButton.css
@@ -0,0 +1,50 @@
+/* Confirm dialog footer for the logout flow (rendered inside CenteredModal). */
+
+.harness-logout-confirm {
+ display: flex;
+ gap: 0.75rem;
+ padding: 1.25rem;
+}
+
+.harness-logout-cancel,
+.harness-logout-submit {
+ flex: 1 1 0;
+ display: inline-flex;
+ min-height: 2.5rem;
+ align-items: center;
+ justify-content: center;
+ border-radius: 0.625rem;
+ padding: 0 1rem;
+ font-size: 0.9375rem;
+ font-weight: 500;
+ letter-spacing: -0.005em;
+ cursor: pointer;
+ transition: opacity 0.15s ease;
+}
+
+.harness-logout-cancel {
+ border: 1px solid var(--border);
+ background: transparent;
+ color: var(--foreground);
+}
+
+.harness-logout-cancel:hover:not(:disabled) {
+ background: color-mix(in srgb, var(--foreground) 8%, transparent);
+}
+
+.harness-logout-submit {
+ border: 0;
+ background: var(--destructive);
+ color: var(--destructive-foreground, #fff);
+}
+
+.harness-logout-submit:hover:not(:disabled) {
+ opacity: 0.85;
+}
+
+.harness-logout-cancel:disabled,
+.harness-logout-submit:disabled {
+ opacity: 0.5;
+ cursor: default;
+ pointer-events: none;
+}
diff --git a/packages/frontend/src/LogoutButton.tsx b/packages/frontend/src/LogoutButton.tsx
index db636ae3e..9d313e1b1 100644
--- a/packages/frontend/src/LogoutButton.tsx
+++ b/packages/frontend/src/LogoutButton.tsx
@@ -1,7 +1,7 @@
-import { Icon } from '@truefoundry/trueforge-ui';
+import { CenteredModal, Icon } from '@truefoundry/trueforge-ui';
import { useEffect, useState } from 'react';
-import { AUTH_LOGGED_OUT_HREF } from './authFetch';
import { getCachedIsOidcConnectedSession, isOidcConnectedSession, logout } from './authSession';
+import './LogoutButton.css';
/**
* Icon button next to Settings (via `ShellActionsActionSlot` override).
@@ -10,6 +10,7 @@ import { getCachedIsOidcConnectedSession, isOidcConnectedSession, logout } from
*/
export function LogoutButton() {
const [visible, setVisible] = useState(() => getCachedIsOidcConnectedSession() === true);
+ const [confirmOpen, setConfirmOpen] = useState(false);
const [busy, setBusy] = useState(false);
useEffect(() => {
@@ -33,26 +34,58 @@ export function LogoutButton() {
return null;
}
+ const handleConfirm = () => {
+ if (busy) return;
+ setBusy(true);
+ void logout()
+ .then(() => {
+ // Land on the welcome gate (probe /me → unauthenticated → GetStartedScreen).
+ window.location.assign('/');
+ })
+ .catch(() => {
+ setBusy(false);
+ });
+ };
+
return (
- <button
- type="button"
- aria-label="Log out"
- title="Log out"
- disabled={busy}
- className="harness-logout"
- onClick={() => {
- if (busy) return;
- setBusy(true);
- void logout()
- .then(() => {
- window.location.assign(AUTH_LOGGED_OUT_HREF);
- })
- .catch(() => {
- setBusy(false);
- });
- }}
- >
- <Icon name="log-out" />
- </button>
+ <>
+ <button
+ type="button"
+ aria-label="Log out"
+ title="Log out"
+ className="harness-logout"
+ onClick={() => {
+ setConfirmOpen(true);
+ }}
+ >
+ <Icon name="log-out" />
+ </button>
+
+ <CenteredModal
+ open={confirmOpen}
+ onOpenChange={next => {
+ if (!busy) setConfirmOpen(next);
+ }}
+ title="Log out"
+ description="Sure to logout?"
+ contentSized
+ >
+ <div className="harness-logout-confirm">
+ <button
+ type="button"
+ className="harness-logout-cancel"
+ disabled={busy}
+ onClick={() => {
+ setConfirmOpen(false);
+ }}
+ >
+ Cancel
+ </button>
+ <button type="button" className="harness-logout-submit" disabled={busy} onClick={handleConfirm}>
+ {busy ? 'Logging out…' : 'Confirm'}
+ </button>
+ </div>
+ </CenteredModal>
+ </>
);
}
diff --git a/packages/frontend/src/authFetch.ts b/packages/frontend/src/authFetch.ts
index f43703000..8cc9c67c9 100644
--- a/packages/frontend/src/authFetch.ts
+++ b/packages/frontend/src/authFetch.ts
@@ -6,9 +6,6 @@
/** Browser entry for OIDC login (not available as an SDK method). */
export const AUTH_LOGIN_HREF = '/api/v1/auth/login';
-/** Post-logout landing (separate from login failure `?error=`). */
-export const AUTH_LOGGED_OUT_HREF = '/?logged_out';
-
export function createAuthAwareFetch(baseFetch: typeof fetch = globalThis.fetch.bind(globalThis)): typeof fetch {
let redirecting = false;
diff --git a/packages/frontend/src/authScreens.css b/packages/frontend/src/authScreens.css
new file mode 100644
index 000000000..074ab9006
--- /dev/null
+++ b/packages/frontend/src/authScreens.css
@@ -0,0 +1,69 @@
+/* Shared full-viewport layout for the pre-auth gate screens (welcome + error). */
+
+.auth-screen {
+ min-height: 100dvh;
+ display: flex;
+ align-items: center;
+ justify-content: center;
+ padding: 1.5rem;
+ background: var(--background);
+ color: var(--foreground);
+ font-family:
+ ui-sans-serif, system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, 'Apple Color Emoji',
+ 'Segoe UI Emoji';
+}
+
+.auth-screen-card {
+ display: flex;
+ flex-direction: column;
+ align-items: center;
+ gap: 1rem;
+ max-width: 22rem;
+ text-align: center;
+}
+
+.auth-screen-logo {
+ width: 2.25rem;
+ height: 2.25rem;
+ flex-shrink: 0;
+ color: var(--muted-foreground);
+}
+
+.auth-screen-title {
+ margin: 0;
+ font-size: 1.375rem;
+ font-weight: 500;
+ letter-spacing: -0.01em;
+ line-height: 1.3;
+ color: var(--foreground);
+}
+
+.auth-screen-message {
+ margin: 0;
+ font-size: 0.9375rem;
+ line-height: 1.5;
+ color: var(--muted-foreground);
+}
+
+.auth-screen-button {
+ margin-top: 0.25rem;
+ display: inline-flex;
+ min-height: 2.5rem;
+ align-items: center;
+ justify-content: center;
+ border: 0;
+ border-radius: 0.625rem;
+ padding: 0 1.5rem;
+ background: var(--foreground);
+ color: var(--background);
+ font-size: 0.9375rem;
+ font-weight: 500;
+ letter-spacing: -0.005em;
+ text-decoration: none;
+ cursor: pointer;
+ transition: opacity 0.15s ease;
+}
+
+.auth-screen-button:hover {
+ opacity: 0.85;
+}
diff --git a/packages/frontend/src/authSession.ts b/packages/frontend/src/authSession.ts
index f8fb09d1e..aa3e2bd54 100644
--- a/packages/frontend/src/authSession.ts
+++ b/packages/frontend/src/authSession.ts
@@ -3,10 +3,13 @@
* Login is not on the SDK (browser redirect to `/api/v1/auth/login`).
*/
import type { TrueForge, TrueForgeApi } from 'trueforge-sdk';
-import { harnessClient } from './harnessClient';
+import { harnessClient, harnessProbeClient } from './harnessClient';
export type MeResponse = TrueForgeApi.MeResponse;
+/** Result of the pre-boot session probe. */
+export type SessionState = 'authenticated' | 'unauthenticated';
+
/** Last successful me() OIDC check — survives remounts of host chrome. */
let cachedIsOidcConnected: boolean | undefined;
@@ -33,3 +36,18 @@ export async function isOidcConnectedSession(client: TrueForge = harnessClient):
export async function logout(client: TrueForge = harnessClient): Promise<void> {
await client.auth.logout();
}
+
+/**
+ * Pre-boot gate: GET `/me` without the 401→login redirect.
+ * Any failure (e.g. OIDC configured but no session cookie yet) is treated as
+ * unauthenticated so the app can render the welcome / "Let's Get Started" screen
+ * rather than bouncing to login before the user asks for it.
+ */
+export async function probeSession(client: TrueForge = harnessProbeClient): Promise<SessionState> {
+ try {
+ await client.auth.me();
+ return 'authenticated';
+ } catch {
+ return 'unauthenticated';
+ }
+}
diff --git a/packages/frontend/src/authStatusSearch.ts b/packages/frontend/src/authStatusSearch.ts
index f8a4fefac..ae420378e 100644
--- a/packages/frontend/src/authStatusSearch.ts
+++ b/packages/frontend/src/authStatusSearch.ts
@@ -1,8 +1,3 @@
-/** True when the URL is a logout landing (`/?logged_out`). */
-export function isLoggedOutSearch(search: string): boolean {
- return new URLSearchParams(search).has('logged_out');
-}
-
/** Reads `/?error=<reason>` from OIDC login failures. Returns null when not an error landing. */
export function parseAuthErrorReason(search: string): string | null {
const reason = new URLSearchParams(search).get('error')?.trim();
diff --git a/packages/frontend/src/harnessClient.ts b/packages/frontend/src/harnessClient.ts
index 4489175c9..c7037df3e 100644
--- a/packages/frontend/src/harnessClient.ts
+++ b/packages/frontend/src/harnessClient.ts
@@ -24,3 +24,14 @@ export function createHarnessClient(options: CreateHarnessClientOptions = {}): T
/** Default browser client — Vite proxies `/api/*` to the Harness server. */
export const harnessClient = createHarnessClient();
+
+/**
+ * Client for the pre-boot session probe. Unlike {@link harnessClient} it does NOT
+ * redirect on 401, so the welcome gate can observe the unauthenticated state
+ * (OIDC configured but no session cookie yet) and render "Let's Get Started"
+ * instead of bouncing straight to the login flow.
+ */
+export const harnessProbeClient = new TrueForge({
+ baseUrl: DEFAULT_BASE_URL,
+ fetch: globalThis.fetch.bind(globalThis),
+});
diff --git a/packages/frontend/tests/authFetch.test.ts b/packages/frontend/tests/authFetch.test.ts
index 76aaa5f40..85f19c257 100644
--- a/packages/frontend/tests/authFetch.test.ts
+++ b/packages/frontend/tests/authFetch.test.ts
@@ -1,7 +1,7 @@
import assert from 'node:assert/strict';
import { describe, it } from 'node:test';
-import { AUTH_LOGGED_OUT_HREF, AUTH_LOGIN_HREF, createAuthAwareFetch } from '../src/authFetch';
-import { isLoggedOutSearch, parseAuthErrorReason } from '../src/authStatusSearch';
+import { AUTH_LOGIN_HREF, createAuthAwareFetch } from '../src/authFetch';
+import { parseAuthErrorReason } from '../src/authStatusSearch';
describe('createAuthAwareFetch', () => {
it('passes through non-401 responses', async () => {
@@ -51,21 +51,14 @@ describe('createAuthAwareFetch', () => {
}
});
- it('exports browser auth entry paths', () => {
+ it('exports browser auth entry path', () => {
assert.equal(AUTH_LOGIN_HREF, '/api/v1/auth/login');
- assert.equal(AUTH_LOGGED_OUT_HREF, '/?logged_out');
});
});
describe('auth status landings', () => {
- it('detects logout landing separately from errors', () => {
- assert.equal(isLoggedOutSearch('?logged_out'), true);
- assert.equal(isLoggedOutSearch('?logged_out='), true);
- assert.equal(isLoggedOutSearch('?error=login_failed'), false);
- });
-
it('reads error reason for sign-in failures', () => {
assert.equal(parseAuthErrorReason('?error=access_denied'), 'access_denied');
- assert.equal(parseAuthErrorReason('?logged_out'), null);
+ assert.equal(parseAuthErrorReason('?other=1'), null);
});
});
diff --git a/packages/frontend/tests/authSession.test.ts b/packages/frontend/tests/authSession.test.ts
index 5e064238c..14e4c3fea 100644
--- a/packages/frontend/tests/authSession.test.ts
+++ b/packages/frontend/tests/authSession.test.ts
@@ -5,6 +5,7 @@ import {
getCachedIsOidcConnectedSession,
isOidcConnectedSession,
logout,
+ probeSession,
resetOidcSessionCacheForTests,
} from '../src/authSession';
@@ -58,4 +59,13 @@ describe('authSession', () => {
);
assert.equal(called, true);
});
+
+ it('probeSession reports authenticated when me() resolves', async () => {
+ assert.equal(await probeSession(createClient({ type: 'default' })), 'authenticated');
+ assert.equal(await probeSession(createClient({ type: 'oidc-connected' })), 'authenticated');
+ });
+
+ it('probeSession reports unauthenticated when me() throws', async () => {
+ assert.equal(await probeSession(createClient({ meError: new Error('401') })), 'unauthenticated');
+ });
});
diff --git a/packages/server/src/apis/auth.ts b/packages/server/src/apis/auth.ts
index f534cd2a7..1edf85be5 100644
--- a/packages/server/src/apis/auth.ts
+++ b/packages/server/src/apis/auth.ts
@@ -51,14 +51,11 @@ export function createAuthRouter(params: { oidcClient: Configuration | undefined
clearAuthCookie({ context: c, name: OAUTH_STATE_COOKIE });
if (pending?.state !== query.state || query.error || !query.code) {
+ // Only reflect a non-empty IdP `error_description` when the IdP returned an error.
+ // No fallback to the `error` code — blank/missing descriptions use the default.
+ // Our own validation failures (state mismatch / missing code) stay generic too.
const description = query.error_description?.trim();
- const errorCode = query.error?.trim();
- let reason = 'login_failed';
- if (description) {
- reason = description;
- } else if (errorCode) {
- reason = errorCode;
- }
+ const reason = query.error && description ? description : 'login_failed';
return c.redirect(oauthErrorRedirect(reason), 302);
}
diff --git a/packages/server/tests/unit/apis/auth.test.ts b/packages/server/tests/unit/apis/auth.test.ts
index 422d60257..c58860f58 100644
--- a/packages/server/tests/unit/apis/auth.test.ts
+++ b/packages/server/tests/unit/apis/auth.test.ts
@@ -263,6 +263,35 @@ describe('auth router (OIDC configured)', () => {
expect(res.headers.get('location')).toBe('/?error=user%20cancelled');
});
+ it('GET /callback uses login_failed when the IdP error has no description', async () => {
+ const res = await createAuthRouter({ oidcClient, logger }).request('/callback?state=any&error=access_denied', {
+ redirect: 'manual',
+ });
+ expect(res.status).toBe(302);
+ expect(res.headers.get('location')).toBe('/?error=login_failed');
+ });
+
+ it('GET /callback uses login_failed when the IdP error description is blank', async () => {
+ const res = await createAuthRouter({ oidcClient, logger }).request(
+ '/callback?state=any&error=access_denied&error_description=%20%20',
+ { redirect: 'manual' },
+ );
+ expect(res.status).toBe(302);
+ expect(res.headers.get('location')).toBe('/?error=login_failed');
+ });
+
+ it('GET /callback ignores a crafted error_description when the IdP did not return an error', async () => {
+ // No `error` code → this is our own validation failure, so the attacker-supplied
+ // description must not be reflected; the reason stays generic.
+ const crafted = 'Your%20account%20is%20compromised%2C%20call%201-800-EVIL';
+ const res = await createAuthRouter({ oidcClient, logger }).request(
+ `/callback?state=any&error_description=${crafted}`,
+ { redirect: 'manual' },
+ );
+ expect(res.status).toBe(302);
+ expect(res.headers.get('location')).toBe('/?error=login_failed');
+ });
+
it('GET /callback redirects home with error when state mismatches', async () => {
const res = await createAuthRouter({ oidcClient, logger }).request('/callback?code=abc&state=wrong', {
redirect: 'manual',