From a195b50245bdb9d0b47b2d7a2f9157b3a52bb335 Mon Sep 17 00:00:00 2001 From: Tom Gringauz <17593920+tomgrin10@users.noreply.github.com> Date: Mon, 12 Oct 2026 09:05:45 +0000 Subject: [PATCH] Keep manual OAuth sign-in available during reconnect errors --- docs/features/oauth-authentication.md | 10 +++ frontend/src/components/ServerCard.vue | 5 ++ frontend/src/utils/oauthActions.ts | 14 ++++ frontend/src/views/ServerDetail.vue | 8 +- .../tests/unit/oauth-manual-signin.spec.ts | 78 +++++++++++++++++++ 5 files changed, 112 insertions(+), 3 deletions(-) create mode 100644 frontend/src/utils/oauthActions.ts create mode 100644 frontend/tests/unit/oauth-manual-signin.spec.ts diff --git a/docs/features/oauth-authentication.md b/docs/features/oauth-authentication.md index 03e84a95e..b838daf50 100644 --- a/docs/features/oauth-authentication.md +++ b/docs/features/oauth-authentication.md @@ -166,6 +166,16 @@ actionable **Sign-in** state: is quarantined, but its tools stay blocked until you **Approve** the server. The panel makes both gates explicit. +### Switching accounts and retrying sign-in + +To switch accounts or recover an OAuth error, use **Sign in again** in the +server card’s **More actions** menu or the detail page’s **Actions** menu. +For an OAuth-capable upstream this remains available during reconnect attempts +and generic timeout errors, even when the health panel does not suggest login. +After logout it is labelled **Sign in**. Select the intended account/workspace +at the provider; if the provider reuses its own browser session, switch that +account before starting sign-in again. + ## CLI Commands ### Start Authentication diff --git a/frontend/src/components/ServerCard.vue b/frontend/src/components/ServerCard.vue index a9cd9ebf9..5c8f735e5 100644 --- a/frontend/src/components/ServerCard.vue +++ b/frontend/src/components/ServerCard.vue @@ -110,6 +110,9 @@
  • +
  • + +
  • -
  • -
  • @@ -1604,6 +1604,7 @@ import { refName } from '@/utils/secretRef' import { isTerminalScanStatus, decideScanReconcile, finalizeToastKind } from '@/utils/scanState' import { selectQuarantinedTools } from '@/utils/toolQuarantine' import { oauthSignInState, healthStatusLabel, healthActionLabel, healthStatusText } from '@/utils/health' +import { canStartOAuthLogin } from '@/utils/oauthActions' import type { HealthStatusValue } from '@/types/contracts' import { describeIsolation } from '@/utils/isolationState' import { computeToolDiffSections } from '@/utils/toolDiff' @@ -1824,6 +1825,7 @@ const logTail = ref(100) const isHttpProtocol = computed(() => { return server.value?.protocol === 'http' || server.value?.protocol === 'streamable-http' }) +const canSignIn = computed(() => !!server.value && canStartOAuthLogin(server.value)) // Suggested action from unified health status const healthAction = computed(() => { diff --git a/frontend/tests/unit/oauth-manual-signin.spec.ts b/frontend/tests/unit/oauth-manual-signin.spec.ts new file mode 100644 index 000000000..be30a6dae --- /dev/null +++ b/frontend/tests/unit/oauth-manual-signin.spec.ts @@ -0,0 +1,78 @@ +import { beforeEach, describe, expect, it, vi } from 'vitest' +import { mount, flushPromises } from '@vue/test-utils' +import { createPinia, setActivePinia } from 'pinia' +import { createRouter, createWebHistory } from 'vue-router' +import ServerCard from '@/components/ServerCard.vue' +import ServerDetail from '@/views/ServerDetail.vue' +import { useServersStore } from '@/stores/servers' +import { canStartOAuthLogin } from '@/utils/oauthActions' +import type { Server } from '@/types' + +let server: Server +vi.mock('@/services/api', () => { + const ok = (data: unknown = {}) => Promise.resolve({ success: true, data }) + return { default: { + getServers: vi.fn(() => ok({ servers: [server] })), + getToolApprovals: vi.fn(() => ok({ tools: [], count: 0 })), + getToolDiff: vi.fn(() => ok({})), + getServerTools: vi.fn(() => ok({ tools: [] })), + getSecurityOverview: vi.fn(() => ok({ scanners_enabled: 0, docker_available: true })), + listScanners: vi.fn(() => ok([])), + getScanReport: vi.fn(() => Promise.resolve({ success: false, error: 'no report' })), + getScanStatus: vi.fn(() => ok({ status: 'completed' })), + getServerLogs: vi.fn(() => ok({ logs: [] })), + } } +}) + +beforeEach(() => { + setActivePinia(createPinia()) + server = { + name: 'notion', protocol: 'http', url: 'https://mcp.notion.com/mcp', + enabled: true, connected: false, connecting: true, authenticated: true, + tool_count: 0, oauth: { client_id: 'test' }, + last_error: 'OAuth authorization during MCP init failed: context deadline exceeded', + health: { level: 'unhealthy', admin_state: 'enabled', summary: 'OAuth error', action: 'restart', actions: ['restart', 'view_logs'] }, + } as Server +}) + +describe('manual OAuth sign-in', () => { + it('stays available while reconnecting and after a timeout or logout', () => { + expect(canStartOAuthLogin(server)).toBe(true) + expect(canStartOAuthLogin({ ...server, authenticated: false, user_logged_out: true })).toBe(true) + expect(canStartOAuthLogin({ ...server, connected: true, connecting: false, health: undefined, last_error: undefined })).toBe(true) + }) + it('does not offer OAuth on disabled, stdio, or unauthenticated non-OAuth HTTP servers', () => { + expect(canStartOAuthLogin({ ...server, enabled: false })).toBe(false) + expect(canStartOAuthLogin({ ...server, protocol: 'stdio' })).toBe(false) + expect(canStartOAuthLogin({ ...server, oauth: undefined, authenticated: false, last_error: 'network timeout', health: undefined })).toBe(false) + }) + it('recognizes auto-discovered OAuth without explicit config', () => { + expect(canStartOAuthLogin({ ...server, oauth: undefined, authenticated: false })).toBe(true) + }) + it('starts a fresh OAuth flow from the card even when reconnect is the primary action', async () => { + const spy = vi.spyOn(useServersStore(), 'triggerOAuthLogin').mockResolvedValue(true) + const card = mount(ServerCard, { props: { server }, global: { stubs: { RouterLink: true } } }) + const action = card.find('[data-test="server-card-menu-login"]') + expect(action.text()).toBe('Sign in again') + expect(action.attributes('disabled')).toBeUndefined() + await action.trigger('click'); await flushPromises() + expect(spy).toHaveBeenCalledWith('notion') + await card.setProps({ server: { ...server, authenticated: false } }) + expect(card.find('[data-test="server-card-menu-login"]').text()).toBe('Sign in') + card.unmount() + }) + it('offers sign-in again from the detail Actions menu during an OAuth reconnect error', async () => { + const router = createRouter({ history: createWebHistory(), routes: [{ path: '/servers/:serverName', component: { template: '
    ' } }] }) + await router.push('/servers/notion'); await router.isReady() + const pinia = createPinia(); setActivePinia(pinia) + const spy = vi.spyOn(useServersStore(), 'triggerOAuthLogin').mockResolvedValue(true) + const detail = mount(ServerDetail, { props: { serverName: 'notion' }, global: { plugins: [pinia, router] } }) + await flushPromises(); await flushPromises() + const action = detail.find('[data-test="server-detail-menu-login"]') + expect(action.text()).toBe('Sign in again') + expect(action.attributes('disabled')).toBeUndefined() + await action.trigger('click'); await flushPromises() + expect(spy).toHaveBeenCalledWith('notion') + detail.unmount() + }) +})