diff --git a/packages/shared/src/app-definitions.test.ts b/packages/shared/src/app-definitions.test.ts index ff3bdaec084..269e1c82f37 100644 --- a/packages/shared/src/app-definitions.test.ts +++ b/packages/shared/src/app-definitions.test.ts @@ -1673,3 +1673,13 @@ it("limits explicit DCR registration preference to remote MCP OAuth methods with nonMcp.methods[0]!.transport = "rest_api"; expect(appDefinitionSchema.safeParse(nonMcp).success).toBe(false); }); + +it("uses Slack MCP user OAuth endpoints and includes user-scope and MCP prerequisites", () => { + const slack = getConnectableAppDefinition("slack")!; + const mcpOAuth = slack.methods.find((method) => method.key === "mcp-oauth")!; + expect(mcpOAuth.defaults?.authorizationEndpoint).toBe("https://slack.com/oauth/v2_user/authorize"); + expect(mcpOAuth.defaults?.tokenEndpoint).toBe("https://slack.com/api/oauth.v2.user.access"); + expect(mcpOAuth.defaults?.scopesHint).toContain("search:read.public"); + expect(mcpOAuth.guidanceMd).toContain("User Token Scopes"); + expect(mcpOAuth.guidanceMd).toContain("Model Context Protocol"); +}); diff --git a/packages/shared/src/app-definitions/slack.json b/packages/shared/src/app-definitions/slack.json index 733de01cdee..0a3e028d0c7 100644 --- a/packages/shared/src/app-definitions/slack.json +++ b/packages/shared/src/app-definitions/slack.json @@ -28,8 +28,8 @@ }, "defaults": { "serverUrl": "https://mcp.slack.com/mcp", - "authorizationEndpoint": "https://slack.com/oauth/v2/authorize", - "tokenEndpoint": "https://slack.com/api/oauth.v2.access", + "authorizationEndpoint": "https://slack.com/oauth/v2_user/authorize", + "tokenEndpoint": "https://slack.com/api/oauth.v2.user.access", "scopesHint": [ "canvases:read", "canvases:write", @@ -63,7 +63,7 @@ "users:read.email" ] }, - "guidanceMd": "Connect a Slack workspace and limit access to the channels agents need.", + "guidanceMd": "In your Slack app settings, add Paperclip's callback URL under OAuth & Permissions, add the requested scopes under User Token Scopes (not Bot Token Scopes), and enable Model Context Protocol under Features → Agents & AI Apps.", "riskTier": "S3", "label": "Use this connection as an agent tool", "purpose": "tool", diff --git a/scripts/ingest-app-definitions.mjs b/scripts/ingest-app-definitions.mjs index 96af5ceb254..dca72a7ed0e 100644 --- a/scripts/ingest-app-definitions.mjs +++ b/scripts/ingest-app-definitions.mjs @@ -356,12 +356,43 @@ const apps = [ "oauth", { serverUrl: "https://mcp.slack.com/mcp", - authorizationEndpoint: "https://slack.com/oauth/v2/authorize", - tokenEndpoint: "https://slack.com/api/oauth.v2.access", - scopesHint: ["channels:read", "chat:write", "search:read"], + authorizationEndpoint: "https://slack.com/oauth/v2_user/authorize", + tokenEndpoint: "https://slack.com/api/oauth.v2.user.access", + scopesHint: [ + "canvases:read", + "canvases:write", + "channels:history", + "channels:read", + "channels:write", + "chat:write", + "emoji:read", + "files:read", + "files:write", + "groups:history", + "groups:read", + "groups:write", + "im:history", + "im:read", + "im:write", + "lists:read", + "lists:write", + "mpim:history", + "mpim:read", + "mpim:write", + "reactions:read", + "reactions:write", + "search:read.files", + "search:read.im", + "search:read.mpim", + "search:read.private", + "search:read.public", + "search:read.users", + "users:read", + "users:read.email", + ], }, "S3", - "Connect a Slack workspace and limit access to the channels agents need.", + "In your Slack app settings, add Paperclip's callback URL under OAuth & Permissions, add the requested scopes under User Token Scopes (not Bot Token Scopes), and enable Model Context Protocol under Features → Agents & AI Apps.", { label: "Use this connection as an agent tool", purpose: "tool", diff --git a/server/src/__tests__/tool-access-service.test.ts b/server/src/__tests__/tool-access-service.test.ts index 4d5bd0ba993..f690121937f 100644 --- a/server/src/__tests__/tool-access-service.test.ts +++ b/server/src/__tests__/tool-access-service.test.ts @@ -10592,7 +10592,7 @@ describeEmbeddedPostgres("tool access service", () => { let gatewayAuthorization: string | null = null; vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { return { ok: true, status: 200, @@ -10743,7 +10743,7 @@ describeEmbeddedPostgres("tool access service", () => { ); vi.spyOn(globalThis, "fetch").mockImplementation(async (url) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { return { ok: true, status: 200, @@ -10896,7 +10896,7 @@ describeEmbeddedPostgres("tool access service", () => { ).searchParams.get("state")!; vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; const userAuthorization = body.get("code") === "user-authorization-code"; @@ -11221,7 +11221,7 @@ describeEmbeddedPostgres("tool access service", () => { ); vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const code = (init?.body as URLSearchParams).get("code"); expect(["personal-code", "personal-reconnect-code"]).toContain(code); const reconnecting = code === "personal-reconnect-code"; @@ -11565,7 +11565,7 @@ describeEmbeddedPostgres("tool access service", () => { if (mode === "managed") definition.ownershipAvailability = { ...availability, platform_shared: true }; let discoverNewTool = false; vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { - if (String(url) === "https://slack.com/api/oauth.v2.access") return mcpHttpResponse(oauthToken("fixture-access-token", "fixture-refresh-token")); + if (String(url) === "https://slack.com/api/oauth.v2.user.access") return mcpHttpResponse(oauthToken("fixture-access-token", "fixture-refresh-token")); const body = JSON.parse(String(init?.body)); if (body.method === "notifications/initialized") return new Response(null, { status: 202 }); return mcpHttpResponse({ jsonrpc: "2.0", id: body.id, result: body.method === "initialize" ? { protocolVersion: "2025-06-18" } @@ -11649,7 +11649,7 @@ describeEmbeddedPostgres("tool access service", () => { const redirectUri = "https://paperclip.example/api/tools/oauth/callback"; vi.spyOn(globalThis, "fetch").mockImplementation(async url => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") return mcpHttpResponse(oauthToken("fixture-access-token", "fixture-refresh-token")); + if (href === "https://slack.com/api/oauth.v2.user.access") return mcpHttpResponse(oauthToken("fixture-access-token", "fixture-refresh-token")); if (href === "https://mcp.slack.com/mcp") return mcpHttpResponse(catalogResponse([{ name: "search_messages", annotations: { readOnlyHint: true } }])); throw new Error(`unexpected fetch ${href}`); }); @@ -11715,7 +11715,7 @@ describeEmbeddedPostgres("tool access service", () => { let discoverNewTool = false; vi.spyOn(globalThis, "fetch").mockImplementation(async url => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") return mcpHttpResponse(oauthToken("fixture-access-token", "fixture-refresh-token")); + if (href === "https://slack.com/api/oauth.v2.user.access") return mcpHttpResponse(oauthToken("fixture-access-token", "fixture-refresh-token")); if (href === "https://mcp.slack.com/mcp") return mcpHttpResponse(catalogResponse([{ name: "search_messages", annotations: { readOnlyHint: true } }, ...(discoverNewTool ? [{ name: "new_search", annotations: { readOnlyHint: true } }] : [])])); throw new Error(`unexpected fetch ${href}`); }); @@ -11792,7 +11792,7 @@ describeEmbeddedPostgres("tool access service", () => { ); vi.spyOn(globalThis, "fetch").mockImplementation(async (url) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { return mcpHttpResponse(oauthToken("share-access-token", "share-refresh-token")); } if (href === "https://mcp.slack.com/mcp") { @@ -11931,7 +11931,7 @@ describeEmbeddedPostgres("tool access service", () => { .spyOn(globalThis, "fetch") .mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; if (body.get("grant_type") === "refresh_token") { expect(body.get("refresh_token")).toBe("personal-refresh-token"); @@ -12052,7 +12052,7 @@ describeEmbeddedPostgres("tool access service", () => { ); vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; if (body.get("grant_type") === "refresh_token") { return mcpHttpResponse({ @@ -12263,7 +12263,7 @@ describeEmbeddedPostgres("tool access service", () => { let tokenScope: string | null = null; vi.spyOn(globalThis, "fetch").mockImplementation(async (url) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { return mcpHttpResponse({ ok: true, access_token: `access-${randomUUID()}`, @@ -12398,7 +12398,7 @@ describeEmbeddedPostgres("tool access service", () => { let refreshScope: string | null = null; vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; return body.get("grant_type") === "refresh_token" ? slackToken(refreshScope) @@ -13051,7 +13051,7 @@ describeEmbeddedPostgres("tool access service", () => { }); const startUrl = new URL(connectRes.body.auth.startUrl); expect(`${startUrl.origin}${startUrl.pathname}`).toBe( - "https://slack.com/oauth/v2/authorize", + "https://slack.com/oauth/v2_user/authorize", ); expect(startUrl.searchParams.get("client_id")).toBe("slack-client-id"); expect(startUrl.searchParams.get("code_challenge_method")).toBe("S256"); @@ -13078,7 +13078,7 @@ describeEmbeddedPostgres("tool access service", () => { .spyOn(globalThis, "fetch") .mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; expect(body.get("grant_type")).toBe("authorization_code"); expect(body.get("code")).toBe("oauth-code"); @@ -13190,6 +13190,114 @@ describeEmbeddedPostgres("tool access service", () => { }, ); + it("uses Slack user OAuth endpoints even for legacy drafts and propagates allowlisted provider_error without reflecting error_description", async () => { + const origin = "https://paperclip.example"; + vi.stubEnv("PAPERCLIP_PUBLIC_URL", origin); + const company = await createCompany(db); + await grantBoardUser(db, company.id, "board-user", [ + "tools:manage_connections", + ]); + const app = createRouteApp(db); + + const connectRes = await request(app) + .post(`/api/companies/${company.id}/tools/apps/connect`) + .set("Host", "paperclip.example") + .set("Origin", origin) + .send({ + galleryKey: "slack", + name: "Slack user OAuth", + oauthClient: { + clientId: "slack-customer-id", + clientSecret: "slack-customer-secret", + }, + }) + .expect(201); + + const initialStartUrl = new URL(connectRes.body.auth.startUrl); + expect(`${initialStartUrl.origin}${initialStartUrl.pathname}`).toBe( + "https://slack.com/oauth/v2_user/authorize", + ); + expect(initialStartUrl.searchParams.get("scope")?.split(" ")).toContain( + "search:read.public", + ); + + const [existingDraft] = await db + .select() + .from(toolConnections) + .where(eq(toolConnections.id, connectRes.body.connectionId)); + const legacyOAuth = { + ...((existingDraft!.config.oauth as Record) ?? {}), + authorizationUrl: "https://slack.com/oauth/v2/authorize", + tokenUrl: "https://slack.com/api/oauth.v2.access", + }; + await db + .update(toolConnections) + .set({ + config: { ...existingDraft!.config, oauth: legacyOAuth }, + transportConfig: { ...existingDraft!.transportConfig, oauth: legacyOAuth }, + }) + .where(eq(toolConnections.id, connectRes.body.connectionId)); + + const retryStartRes = await request(app) + .post(`/api/tools/oauth/${connectRes.body.connectionId}/start`) + .set("Host", "paperclip.example") + .set("Origin", origin) + .send({}) + .expect(200); + const retryUrl = new URL(retryStartRes.body.authorizationUrl); + expect(`${retryUrl.origin}${retryUrl.pathname}`).toBe( + "https://slack.com/oauth/v2_user/authorize", + ); + const retryState = retryUrl.searchParams.get("state")!; + + const failedCallbackRes = await request(app) + .get("/api/tools/oauth/callback") + .set("Host", "paperclip.example") + .set("Accept", "text/html") + .query({ + state: retryState, + error: "invalid_scope", + error_description: "Invalid permissions requested (untrusted-canary)", + }); + + expect(failedCallbackRes.status).toBe(303); + const recoveryLocation = new URL(failedCallbackRes.headers.location, origin); + expect(recoveryLocation.pathname).toBe(`/${company.issuePrefix}/apps/connect`); + expect(recoveryLocation.searchParams.get("source")).toBe("slack"); + expect(recoveryLocation.searchParams.get("resume")).toBe(connectRes.body.connectionId); + expect(recoveryLocation.searchParams.get("oauth")).toBe("denied"); + expect(recoveryLocation.searchParams.get("code")).toBe("oauth_authorization_denied"); + expect(recoveryLocation.searchParams.get("provider_error")).toBe("invalid_scope"); + expect(failedCallbackRes.headers.location).not.toContain("untrusted-canary"); + expect(failedCallbackRes.headers.location).not.toContain("error_description"); + + const unlistedStartRes = await request(app) + .post(`/api/tools/oauth/${connectRes.body.connectionId}/start`) + .set("Host", "paperclip.example") + .set("Origin", origin) + .send({}) + .expect(200); + const unlistedState = new URL(unlistedStartRes.body.authorizationUrl).searchParams.get("state")!; + + const unlistedCallbackRes = await request(app) + .get("/api/tools/oauth/callback") + .set("Host", "paperclip.example") + .set("Accept", "text/html") + .query({ + state: unlistedState, + error: "evil_unlisted_code", + error_description: "unlisted-canary", + }); + + expect(unlistedCallbackRes.status).toBe(303); + const unlistedRecoveryLocation = new URL(unlistedCallbackRes.headers.location, origin); + expect(unlistedRecoveryLocation.searchParams.get("oauth")).toBe("denied"); + expect(unlistedRecoveryLocation.searchParams.get("code")).toBe("oauth_authorization_denied"); + expect(unlistedRecoveryLocation.searchParams.get("provider_error")).toBeNull(); + expect(unlistedCallbackRes.headers.location).not.toContain("evil_unlisted_code"); + expect(unlistedCallbackRes.headers.location).not.toContain("unlisted-canary"); + }); + it("normalizes a direct numeric loopback origin for OAuth when no public URL is configured", async () => { vi.stubEnv("PAPERCLIP_PUBLIC_URL", ""); vi.stubEnv("PAPERCLIP_TOOL_OAUTH_SLACK_CLIENT_ID", "slack-client-id"); @@ -13581,7 +13689,7 @@ describeEmbeddedPostgres("tool access service", () => { vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; expect(body.get("grant_type")).toBe("authorization_code"); expect(body.get("code")).toBe("oauth-code"); @@ -14988,7 +15096,7 @@ describeEmbeddedPostgres("tool access service", () => { let refreshCallCount = 0; vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; if (body.get("grant_type") === "authorization_code") { return { @@ -15112,7 +15220,7 @@ describeEmbeddedPostgres("tool access service", () => { .spyOn(globalThis, "fetch") .mockImplementation(async (url) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { return mcpHttpResponse(oauthToken("expired-access-token", "single-use-refresh-token")); } if (href === "https://mcp.slack.com/mcp") { @@ -15140,7 +15248,7 @@ describeEmbeddedPostgres("tool access service", () => { let refreshCallCount = 0; fetchMock.mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; expect(body.get("grant_type")).toBe("refresh_token"); expect(body.get("refresh_token")).toBe("single-use-refresh-token"); @@ -15222,7 +15330,7 @@ describeEmbeddedPostgres("tool access service", () => { .spyOn(globalThis, "fetch") .mockImplementation(async (url) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { return mcpHttpResponse(oauthToken("expired-access-token", "submitted-refresh-token")); } if (href === "https://mcp.slack.com/mcp") { @@ -15253,7 +15361,7 @@ describeEmbeddedPostgres("tool access service", () => { fetchMock.mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = init?.body as URLSearchParams; expect(body.get("refresh_token")).toBe("submitted-refresh-token"); await secretService(db).rotate(refreshRef.secretId, { @@ -15366,7 +15474,7 @@ describeEmbeddedPostgres("tool access service", () => { const tokenRequests: Array<{ url: string; clientId: string | null; clientSecret: string | null }> = []; vi.spyOn(globalThis, "fetch").mockImplementation(async (url, init) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { const body = new URLSearchParams(String(init?.body ?? "")); tokenRequests.push({ url: href, clientId: body.get("client_id"), clientSecret: body.get("client_secret") }); return { ok: true, status: 200, json: async () => ({ access_token: "deployment-access", refresh_token: "deployment-refresh", expires_in: 3600 }) } as Response; @@ -15385,7 +15493,7 @@ describeEmbeddedPostgres("tool access service", () => { redirectUri: "https://paperclip.example/api/tools/oauth/callback", actor: { actorType: "user", actorId: userId }, }); - expect(tokenRequests).toEqual([{ url: "https://slack.com/api/oauth.v2.access", clientId: "slack-deployment-id", clientSecret: "slack-deployment-secret" }]); + expect(tokenRequests).toEqual([{ url: "https://slack.com/api/oauth.v2.user.access", clientId: "slack-deployment-id", clientSecret: "slack-deployment-secret" }]); }); it("never sends a deployment OAuth client to a machine-to-machine token endpoint of a custom server", async () => { @@ -15450,7 +15558,7 @@ describeEmbeddedPostgres("tool access service", () => { .spyOn(globalThis, "fetch") .mockImplementation(async (url) => { const href = String(url); - if (href === "https://slack.com/api/oauth.v2.access") { + if (href === "https://slack.com/api/oauth.v2.user.access") { return { ok: true, json: async () => ({ diff --git a/server/src/routes/tool-access.ts b/server/src/routes/tool-access.ts index 3523cb266c7..494039bdca5 100644 --- a/server/src/routes/tool-access.ts +++ b/server/src/routes/tool-access.ts @@ -1,4 +1,5 @@ import { isCrossSiteOAuthCallbackNavigation, oauthCallbackInterstitialHtml } from "../lib/oauth-browser-return.js"; +import { normalizeOAuthProviderError } from "../services/tool-access/oauth/provider-errors.js"; import { aiConnectionRouterPluginKey, isSamePaperclipInstance, paperclipPeerFromMcpUrl } from "@paperclipai/shared"; import { aiConnectionRouterService } from "../services/ai-connection-router.js"; import { loadPluginAppCatalog } from "../services/plugin-app-catalog.js"; @@ -218,17 +219,24 @@ export function githubInstallationRecovery(code: string | null | undefined, deta return installationUrl || managementUrl ? { installationUrl, managementUrl } : null; } +function safeOAuthProviderErrorCode(value: unknown): string | null { + const normalized = normalizeOAuthProviderError(value); + return normalized && normalized !== "unrecognized" ? normalized : null; +} + export function connectionIntentOAuthOutcomeHtml(input: { interactionId: string | null; issueId: string | null; outcome: "connected" | "declined" | "failed"; openerOrigin?: string | null; code?: string | null; + providerError?: string | null; recovery?: { installationUrl: string | null; managementUrl: string | null } | null; }) { // The callback window is only a signal. Connection identity and every // authorization URL stay server-side; the opener refreshes the task from the // interaction id instead of trusting provider-window data. + const safeProviderError = input.outcome === "connected" ? null : safeOAuthProviderErrorCode(input.providerError); const message = JSON.stringify({ type: "paperclip.connection-intent.oauth", ...(input.interactionId ? { interactionId: input.interactionId } : {}), @@ -236,6 +244,7 @@ export function connectionIntentOAuthOutcomeHtml(input: { ...(input.outcome === "failed" && input.code && OAUTH_FAILURE_CODE_PATTERN.test(input.code) ? { code: input.code } : {}), + ...(safeProviderError ? { providerError: safeProviderError } : {}), ...(input.outcome === "failed" && input.code === "github_installation_required" && input.recovery ? { recovery: input.recovery } : {}), @@ -370,6 +379,7 @@ export function toolAccessRoutes( outcome: "connected" | "declined" | "failed"; openerOrigin?: string | null; code?: string | null; + providerError?: string | null; recovery?: { installationUrl: string | null; managementUrl: string | null } | null; }, ) { @@ -561,10 +571,13 @@ function connectorEnrollmentPrincipal(req: Request): string { outcome: "failed" | "denied", code?: string | null, providerRecovery?: { installationUrl?: unknown; managementUrl?: unknown }, + providerError?: string | null, ) { const detailPermissionsPath = await oauthAppPath(connection.companyId, connection.id); const params = new URLSearchParams({ oauth: outcome }); if (code) params.set("code", code); + const safeProviderError = safeOAuthProviderErrorCode(providerError); + if (safeProviderError) params.set("provider_error", safeProviderError); const addGitHubRecoveryUrls = (target: URLSearchParams) => { if (code !== "github_installation_required") return; for (const [key, value] of [ @@ -598,6 +611,7 @@ function connectorEnrollmentPrincipal(req: Request): string { oauth: outcome, }); if (code) setupParams.set("code", code); + if (safeProviderError) setupParams.set("provider_error", safeProviderError); addGitHubRecoveryUrls(setupParams); const setupRoute = connection.credentialSource === "vercel_connect" ? "/apps/vercel-connect" @@ -1658,6 +1672,7 @@ function connectorEnrollmentPrincipal(req: Request): string { ? callbackError.details as Record : null; const callbackErrorCode = typeof details?.code === "string" ? details.code : null; + const callbackProviderError = safeOAuthProviderErrorCode(details?.providerError); const callbackFailureCode = callbackErrorCode ?? (callbackError instanceof HttpError ? `oauth_callback_http_${callbackError.status}` : "oauth_callback_failed"); await logActivity(db, { @@ -1669,6 +1684,7 @@ function connectorEnrollmentPrincipal(req: Request): string { entityId: pendingState.connectionId, details: { code: callbackFailureCode, + ...(callbackProviderError ? { providerError: callbackProviderError } : {}), status: callbackError instanceof HttpError ? callbackError.status : 500, // HttpError messages are Paperclip-authored. Provider-authored // error_description/error_uri values are never read above and cannot @@ -1693,6 +1709,7 @@ function connectorEnrollmentPrincipal(req: Request): string { outcome, openerOrigin: pendingState.returnTo, code: callbackFailureCode, + providerError: callbackProviderError, recovery: githubInstallationRecovery(callbackErrorCode, details), }); return; @@ -1701,6 +1718,8 @@ function connectorEnrollmentPrincipal(req: Request): string { pendingConnection, callbackErrorCode === "oauth_authorization_denied" ? "denied" : "failed", callbackFailureCode, + undefined, + callbackProviderError, )); return; } diff --git a/server/src/services/tool-access/oauth/client-settings.test.ts b/server/src/services/tool-access/oauth/client-settings.test.ts index 0998a32d556..2225abb7024 100644 --- a/server/src/services/tool-access/oauth/client-settings.test.ts +++ b/server/src/services/tool-access/oauth/client-settings.test.ts @@ -30,7 +30,7 @@ describe("instance OAuth clients", () => { vi.stubEnv("PAPERCLIP_TOOL_OAUTH_SLACK_CLIENT_ID", "instance-slack-id"); vi.stubEnv("PAPERCLIP_TOOL_OAUTH_SLACK_CLIENT_SECRET", "instance-slack-secret"); - expect(configuredOAuthClientForConnection(slack(), "slack", "https://slack.com/api/oauth.v2.access")).toMatchObject({ + expect(configuredOAuthClientForConnection(slack(), "slack", "https://slack.com/api/oauth.v2.user.access")).toMatchObject({ clientId: "instance-slack-id", clientSecret: "instance-slack-secret", }); @@ -38,9 +38,9 @@ describe("instance OAuth clients", () => { it.each([ ["a different host", "https://attacker.example/token"], - ["a lookalike path on the vendor host", "https://slack.com/api/oauth.v2.access/../../collect"], - ["plain http on the vendor host", "http://slack.com/api/oauth.v2.access"], - ["a vendor subdomain", "https://evil.slack.com/api/oauth.v2.access"], + ["a lookalike path on the vendor host", "https://slack.com/api/oauth.v2.user.access/../../collect"], + ["plain http on the vendor host", "http://slack.com/api/oauth.v2.user.access"], + ["a vendor subdomain", "https://evil.slack.com/api/oauth.v2.user.access"], ["no token endpoint", null], ])("never returns the instance secret for %s", (_label, tokenUrl) => { vi.stubEnv("PAPERCLIP_TOOL_OAUTH_SLACK_CLIENT_ID", "instance-slack-id"); @@ -94,7 +94,7 @@ describe("instance OAuth clients", () => { expect(client.clientId).toBeNull(); expect(client.clientSecret).toBeNull(); } - expect(configuredOAuthClientForConnection(marked, "slack", "https://slack.com/api/oauth.v2.access").clientId).toBeNull(); + expect(configuredOAuthClientForConnection(marked, "slack", "https://slack.com/api/oauth.v2.user.access").clientId).toBeNull(); }); it("never uses one app's instance client for a connection that claims another provider", () => { diff --git a/tests/runner-e2e/source-sdk-public-inputs.json b/tests/runner-e2e/source-sdk-public-inputs.json index 4b7c6149766..79d666146e4 100644 --- a/tests/runner-e2e/source-sdk-public-inputs.json +++ b/tests/runner-e2e/source-sdk-public-inputs.json @@ -78,7 +78,7 @@ "packages/shared/src/app-definitions-url.test.ts": "56792d6745a5bc7eafc36e7403f4c9bbd671ae99", "packages/shared/src/app-definitions.generated.ts": "b162e9621fab029951d77a6b4605ab7893904a3a", "packages/shared/src/app-definitions.ingestion-report.json": "a7b60c7c16a484a411989315e9f08d48258fa647", - "packages/shared/src/app-definitions.test.ts": "ff3bdaec0840b1aff109ce0928aa3eacb4d27032", + "packages/shared/src/app-definitions.test.ts": "269e1c82f377bab004c00765ba51543922315172", "packages/shared/src/app-definitions.ts": "f8c9c3aa66ea3bbe38c3a2eff7abca9a25911c83", "packages/shared/src/app-definitions/1password.json": "c11a4777de2c78805b2d391da5eb075a9511e0f8", "packages/shared/src/app-definitions/agentmail.json": "edd0799b1980d0f5f43b89c8f7a1173dc623f7fa", @@ -171,7 +171,7 @@ "packages/shared/src/app-definitions/sentry.json": "0afeca8c0e76be5d8324fa6d18fb970a38bb2b88", "packages/shared/src/app-definitions/shopify.json": "f6bff7db55083d96060d8bd46a08aa38b33c3080", "packages/shared/src/app-definitions/similarweb.json": "37a912287b7ad323cf783eb32d01b943a93e83fd", - "packages/shared/src/app-definitions/slack.json": "733de01cdeec0dc66d732639925c9bb9fb7dc53d", + "packages/shared/src/app-definitions/slack.json": "0a3e028d0c729f1448be06eaff3a7b51f08b194d", "packages/shared/src/app-definitions/speko.json": "6f25f776269b435e8cbde3c3249d35d3063156ce", "packages/shared/src/app-definitions/stripe.json": "708fb6d3498dbb57902dd5ebc45c8fded5d6b578", "packages/shared/src/app-definitions/supabase.json": "9a92a2f30af01e1c9f4cebdf7d4ba0101353c1c6", diff --git a/ui/src/features/connections/ConnectionSetupFlow.oauth.test.ts b/ui/src/features/connections/ConnectionSetupFlow.oauth.test.ts index dd5a3a9b7c2..65d614e337e 100644 --- a/ui/src/features/connections/ConnectionSetupFlow.oauth.test.ts +++ b/ui/src/features/connections/ConnectionSetupFlow.oauth.test.ts @@ -3,13 +3,16 @@ import { describe, expect, it } from "vitest"; import type { ToolApplication, ToolConnection } from "@paperclipai/shared"; import { getConnectableAppDefinition } from "@paperclipai/shared"; +import { readOAuthWindowFailureDetails, readOAuthWindowOutcome } from "@/lib/oauthWindowOutcome"; import { isConnectionDefinitionUnavailable, isVercelConnectUnavailable, isMissingOAuthStateMessage, + oauthCallbackErrorMessage, oauthFailureMessage, readConnectionIntentGitHubRecovery, readConnectionIntentOAuthFailureCode, + readConnectionIntentOAuthProviderError, readConnectionIntentOAuthOutcome, retainedResumeMatches, retainedReconnectMatches, @@ -350,10 +353,61 @@ describe("connection intent OAuth failure reasons", () => { it("ignores malformed codes and never shows a raw code", () => { expect(readConnectionIntentOAuthFailureCode({ code: "