Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions docs/features/oauth-authentication.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 5 additions & 0 deletions frontend/src/components/ServerCard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,9 @@
<li v-if="canLogout">
<button type="button" @click="triggerLogout" :disabled="loading" data-test="server-card-menu-logout">Logout</button>
</li>
<li v-if="canSignIn">
<button type="button" @click="triggerOAuth" :disabled="loading" data-test="server-card-menu-login">{{ server.authenticated || server.connected ? 'Sign in again' : 'Sign in' }}</button>
</li>
<li>
<button
type="button"
Expand Down Expand Up @@ -229,6 +232,7 @@ import { useSystemStore } from '@/stores/system'
import { useSecurityScannerStatus } from '@/composables/useSecurityScannerStatus'
import { serverDetailPath, serverDisplayName, reviewPath } from '@/utils/serverRoute'
import { oauthSignInState, healthStatusText, healthActionLabel } from '@/utils/health'
import { canStartOAuthLogin } from '@/utils/oauthActions'
import { deriveTrustModeState, TRUST_MODES } from '@/utils/trustMode'

interface Props {
Expand Down Expand Up @@ -259,6 +263,7 @@ const isHttpProtocol = computed(() => {
// the status line reads a calm amber "Sign-in required" instead of red
// "Disconnected"/"Unhealthy", matching the ServerDetail Sign-in CTA.
const signInState = computed(() => oauthSignInState(props.server))
const canSignIn = computed(() => canStartOAuthLogin(props.server))

// Trust-mode badge (spec 088 FR-007 / FR-001). Display only — the mode is
// changed from the server detail Configuration tab.
Expand Down
14 changes: 14 additions & 0 deletions frontend/src/utils/oauthActions.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import type { Server } from '@/types'

// Account switching and recovery must remain available even when a timeout
// is classified as a reconnect error, or a background connection is running.
export function canStartOAuthLogin(server: Server): boolean {
const protocol = String(server.protocol)
const remote = ['http', 'sse', 'streamable-http'].includes(protocol) ||
(protocol === 'auto' && !!server.url && !server.command)
return !!(server.enabled && remote && (
server.oauth || server.authenticated || server.health?.action === 'login' ||
server.health?.actions?.includes('login') || server.diagnostic?.code?.startsWith('MCPX_OAUTH_') ||
/oauth/i.test(server.last_error || '')
))
}
8 changes: 5 additions & 3 deletions frontend/src/views/ServerDetail.vue
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@
{{ isHttpProtocol ? 'Reconnect' : 'Restart' }}
</button>
</li>
<li v-if="healthAction === 'login'">
<button @click="triggerOAuth" :disabled="actionLoading">
<li v-if="canSignIn">
<button @click="triggerOAuth" :disabled="actionLoading" data-test="server-detail-menu-login">
<span v-if="actionLoading" class="loading loading-spinner loading-xs"></span>
Login
{{ server.authenticated || server.connected ? 'Sign in again' : 'Sign in' }}
</button>
</li>
<li v-if="server.enabled && server.connected">
Expand Down Expand Up @@ -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'
Expand Down Expand Up @@ -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(() => {
Expand Down
78 changes: 78 additions & 0 deletions frontend/tests/unit/oauth-manual-signin.spec.ts
Original file line number Diff line number Diff line change
@@ -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: '<div/>' } }] })
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()
})
})
Loading