diff --git a/src/admin/api.ts b/src/admin/api.ts index 71661f4..ea9d302 100644 --- a/src/admin/api.ts +++ b/src/admin/api.ts @@ -194,8 +194,8 @@ export const adminApi = { }), /** Integration status for just-in-time connects (flows, CLI). */ - integrationProviders: (workspace: string, signal?: AbortSignal) => - call(`${ws(workspace)}/integrations/providers`, integrationProvidersSchema, { signal }), + integrationProviders: (workspace: string, signal?: AbortSignal, refreshAuthorization = false) => + call(`${ws(workspace)}/integrations/providers${refreshAuthorization ? "?refreshAuthorization=true" : ""}`, integrationProvidersSchema, { signal }), disconnectIntegration: (workspace: string, provider: string, connectionId?: string, version?: string) => { const query = new URLSearchParams({ ...(connectionId ? { connectionId } : {}), ...(version ? { version } : {}) }); return call(`${ws(workspace)}/integrations/${enc(provider)}${query.size ? `?${query}` : ""}`, null, { method: "DELETE" }); diff --git a/src/admin/contracts.ts b/src/admin/contracts.ts index 4207aa2..aeb442c 100644 --- a/src/admin/contracts.ts +++ b/src/admin/contracts.ts @@ -233,10 +233,14 @@ export const integrationProviderSchema = z.object({ credentialFields: z.array(z.object({ key: z.string(), label: z.string(), secret: z.boolean(), required: z.boolean(), placeholder: z.string().optional() })).optional(), connection: z.object({ status: z.enum(["ready", "error"]), + authorizationStatus: z.enum(["active", "inactive", "unknown"]).optional(), + authorizationReason: z.string().optional(), + authorizationCheckedAt: z.string().optional(), + upstreamConnected: z.boolean().nullable().optional(), connectionId: z.string().optional(), version: z.string().optional(), providerConfigKey: nullableText, - authMode: z.enum(["oauth2", "api_key"]).optional(), + authMode: z.enum(["oauth2", "api_key", "github_app"]).optional(), accountLabel: nullableText, scopes: z.array(z.string()).optional(), connectedAt: nullableText, diff --git a/src/flows/flow-connections.test.tsx b/src/flows/flow-connections.test.tsx index a843d4f..5d4074b 100644 --- a/src/flows/flow-connections.test.tsx +++ b/src/flows/flow-connections.test.tsx @@ -127,3 +127,89 @@ it("sends expired refreshes through sign-in recovery with a visible error", asyn await screen.findByText(/Your session has expired/), ).toBeInTheDocument(); }); + +it("requires actual authorization proof and explains a retryable unknown", async () => { + api.integrationProviders.mockResolvedValueOnce({ + providers: [ + { + ...providers[0], + connection: { + ...providers[0].connection, + authorizationStatus: "unknown", + authorizationReason: "check_timed_out", + authorizationCheckedAt: "2026-11-16T07:00:00Z", + }, + }, + ], + canManage: true, + }); + render(); + await screen.findByText("Authorization unverified"); + expect(screen.queryByText("Ready")).not.toBeInTheDocument(); + expect( + screen.getByText("The provider check timed out. Use Refresh to retry."), + ).toBeInTheDocument(); + api.integrationProviders.mockResolvedValueOnce({ + providers: [ + { + ...providers[0], + connection: { + ...providers[0].connection, + authorizationStatus: "active", + authorizationReason: "provider_verified", + authorizationCheckedAt: "2026-11-16T07:01:00Z", + }, + }, + ], + canManage: true, + }); + fireEvent.click(screen.getByRole("button", { name: "Refresh" })); + await screen.findByText("Ready"); + expect(api.integrationProviders).toHaveBeenLastCalledWith("workspace", undefined, true); + expect(screen.getByText("Verified with the provider.")).toBeInTheDocument(); +}); +it("keeps a sync failure visible even when authorization has been verified", async () => { + api.integrationProviders.mockResolvedValueOnce({ + providers: [ + { + ...providers[0], + connection: { + ...providers[0].connection, + status: "error", + authorizationStatus: "active", + authorizationReason: "provider_verified", + }, + }, + ], + canManage: true, + }); + render(); + await screen.findByText("Needs attention"); + expect(screen.getByText("Active")).toBeInTheDocument(); + expect(screen.getByText("Verified with the provider.")).toBeInTheDocument(); +}); + +it("shows inactive authorization for a present saved credential rejected by the provider", async () => { + api.integrationProviders.mockResolvedValueOnce({ + providers: [ + { + ...providers[0], + connection: { + ...providers[0].connection, + upstreamConnected: true, + authorizationStatus: "inactive", + authorizationReason: "credentials_rejected", + }, + }, + ], + canManage: true, + }); + render(); + await screen.findByText("Authorization inactive"); + expect(screen.queryByText("Ready")).not.toBeInTheDocument(); + expect( + screen.getByText( + "The provider rejected these credentials. Reconnect to restore access.", + ), + ).toBeInTheDocument(); +}); diff --git a/src/flows/flow-connections.tsx b/src/flows/flow-connections.tsx index 5495c7e..a2355fd 100644 --- a/src/flows/flow-connections.tsx +++ b/src/flows/flow-connections.tsx @@ -15,7 +15,7 @@ export type IntegrationListEntry = { connectionId?: string; version?: string; providerConfigKey: string | null; - authMode?: "oauth2" | "api_key"; + authMode?: "oauth2" | "api_key" | "github_app"; accountLabel?: string | null; scopes?: string[]; lastEventAt?: string | null; @@ -23,6 +23,9 @@ export type IntegrationListEntry = { name?: string; inherited?: boolean; upstreamConnected?: boolean | null; + authorizationStatus?: "active" | "inactive" | "unknown"; + authorizationReason?: string; + authorizationCheckedAt?: string; }; import s from "./flow-connections.module.css"; @@ -33,8 +36,42 @@ export function connectionAuthLabel( ? "OAuth" : entry.authMode === "api_key" ? "Access token" - : "Not recorded"; + : entry.authMode === "github_app" + ? "App credentials" + : "Not recorded"; } + +export function authorizationExplanation(reason?: string): string { + const explanations: Record = { + provider_verified: "Verified with the provider.", + backend_verified: "Verified by the connection service.", + credentials_rejected: + "The provider rejected these credentials. Reconnect to restore access.", + connection_missing: "This connection is missing at the connection service.", + insufficient_permissions: + "The provider refused the verification check. Check permissions, then Refresh.", + rate_limited: + "The provider limited this check. Wait a moment, then Refresh.", + check_timed_out: "The provider check timed out. Use Refresh to retry.", + authorization_inactive: "The backend reports authorization is inactive. Reconnect to restore access.", + provider_unavailable: "The provider is unavailable. Use Refresh to retry.", + backend_unavailable: "The connection backend is unavailable. Use Refresh to retry.", + backend_status_unknown: "The backend could not confirm authorization. Use Refresh to retry.", + not_checked: "This saved connection is missing information required for a check.", + checks_busy: "Connection checks are busy. Use Refresh to retry.", + unsupported_provider: + "Automatic verification is not available for this provider yet.", + unexpected_response: + "The provider response could not confirm authorization. Use Refresh to retry.", + credentials_unavailable: + "Credentials could not be checked. Use Refresh to retry.", + }; + return ( + explanations[reason ?? ""] ?? + "Authorization could not be checked. Use Refresh to retry." + ); +} + function label(entry: IntegrationListEntry) { return entry.displayName; } @@ -82,10 +119,13 @@ function state(entry: IntegrationListEntry): { } { if (entry.upstreamConnected === false) return { label: "Disconnected upstream", variant: "warning" }; - if (entry.status === "ready") - return { label: "Connected", variant: "success" }; + if (entry.authorizationStatus === "inactive") + return { label: "Authorization inactive", variant: "warning" }; if (["error", "degraded"].includes(entry.status)) return { label: "Needs attention", variant: "warning" }; + if (entry.authorizationStatus !== "active") + return { label: "Authorization unverified", variant: "default" }; + if (entry.status === "ready") return { label: "Ready", variant: "success" }; if (entry.status === "syncing") return { label: "Syncing", variant: "default" }; return { label: "Status unverified", variant: "default" }; @@ -127,8 +167,8 @@ function ConnectionsView({ const busy = useRef(false); const generation = useRef(0); - async function load(signal?: AbortSignal) { - const result = await adminApi.integrationProviders(workspaceId, signal); + async function load(signal?: AbortSignal, refreshAuthorization = false) { + const result = await adminApi.integrationProviders(workspaceId, signal, refreshAuthorization); return result.providers.flatMap((provider) => { const c = provider.connection; return c @@ -138,6 +178,10 @@ function ConnectionsView({ displayName: provider.displayName, connectionLabel: c.metadata?.displayName, status: c.status, + upstreamConnected: c.upstreamConnected, + authorizationStatus: c.authorizationStatus, + authorizationReason: c.authorizationReason, + authorizationCheckedAt: c.authorizationCheckedAt, connectionId: c.connectionId, version: c.version, providerConfigKey: c.providerConfigKey ?? null, @@ -180,7 +224,7 @@ function ConnectionsView({ setError(null); setConfirm(null); try { - const result = await load(); + const result = await load(undefined, true); if (mine === generation.current) setEntries(result); } catch (failure) { if (mine === generation.current) setError(message(failure)); @@ -342,6 +386,32 @@ function ConnectionsView({
Permissions
{entry.scopes?.join(", ") || "Not recorded"}
+
+
Authorization
+
+ {entry.authorizationStatus === "active" + ? "Active" + : entry.authorizationStatus === "inactive" + ? "Inactive" + : "Unverified"} +
+
+
+
Authorization check
+
+ {authorizationExplanation(entry.authorizationReason)} +
+
+
+
Checked
+
+ {entry.authorizationCheckedAt + ? new Date( + entry.authorizationCheckedAt, + ).toLocaleString() + : "Not checked"} +
+
{entry.inherited ? (