Connect ProAgentStore MCP
${clientName} wants to use ProAgentStore MCP tools as your account.
- Continue with GitHub +diff --git a/workers/mcp/src/oauth-provider.test.ts b/workers/mcp/src/oauth-provider.test.ts index e2523483..73e34175 100644 --- a/workers/mcp/src/oauth-provider.test.ts +++ b/workers/mcp/src/oauth-provider.test.ts @@ -121,17 +121,19 @@ describe("handleOAuthRoute", () => { ); expect(res?.status).toBe(200); - expect(res?.headers.get("Set-Cookie")).toContain( - "pags_mcp_oauth_inflight=1", - ); if (!res) throw new Error("Expected OAuth response"); + // The in-flight cookie that used to deadlock retries is gone. + expect(res.headers.get("Set-Cookie")).toBeNull(); const html = await res.text(); expect(html).toContain("Connect ProAgentStore MCP"); expect(html).toContain("Codex wants to use ProAgentStore MCP tools"); expect(html).toContain("/authorize/continue?nonce="); + // Both providers are offered. + expect(html).toContain("provider=github"); + expect(html).toContain("provider=google"); }); - it("redirects to FAS OAuth after the user continues", async () => { + it("redirects to FAS GitHub OAuth after the user continues", async () => { const kv = makeKv({ "authreq:nonce-1": JSON.stringify({ clientId: "client-1", @@ -143,7 +145,7 @@ describe("handleOAuthRoute", () => { const res = await handleOAuthRoute( new Request( - "https://mcp.proagentstore.online/authorize/continue?nonce=nonce-1", + "https://mcp.proagentstore.online/authorize/continue?nonce=nonce-1&provider=github", ), config(kv), ); @@ -156,6 +158,53 @@ describe("handleOAuthRoute", () => { expect(res?.headers.get("Location")).toContain("response_mode=query"); }); + it("redirects to FAS Google OAuth when provider=google", async () => { + const kv = makeKv({ + "authreq:nonce-1": JSON.stringify({ + clientId: "client-1", + redirectUri: "http://127.0.0.1:9876/callback", + codeChallenge: "abc", + state: null, + }), + }); + + const res = await handleOAuthRoute( + new Request( + "https://mcp.proagentstore.online/authorize/continue?nonce=nonce-1&provider=google", + ), + config(kv), + ); + + expect(res?.status).toBe(302); + expect(res?.headers.get("Location")).toContain( + "https://api.freeappstore.online/v1/auth/google/start", + ); + expect(res?.headers.get("Location")).toContain("app_id=pags-mcp"); + }); + + it("defaults to GitHub when no provider is given", async () => { + const kv = makeKv({ + "authreq:nonce-1": JSON.stringify({ + clientId: "client-1", + redirectUri: "http://127.0.0.1:9876/callback", + codeChallenge: "abc", + state: null, + }), + }); + + const res = await handleOAuthRoute( + new Request( + "https://mcp.proagentstore.online/authorize/continue?nonce=nonce-1", + ), + config(kv), + ); + + expect(res?.status).toBe(302); + expect(res?.headers.get("Location")).toContain( + "https://api.freeappstore.online/v1/auth/github/start", + ); + }); + it("resolves scoped OAuth access tokens", async () => { const kv = makeKv({ "token:access-1": JSON.stringify({ diff --git a/workers/mcp/src/oauth-provider.ts b/workers/mcp/src/oauth-provider.ts index 59460c34..dfbd795c 100644 --- a/workers/mcp/src/oauth-provider.ts +++ b/workers/mcp/src/oauth-provider.ts @@ -1,6 +1,6 @@ import { MCP_SCOPES, parseScopes } from "./safety.js"; -const AUTH_IN_FLIGHT_COOKIE = "pags_mcp_oauth_inflight"; +type AuthProvider = "github" | "google"; export interface OAuthConfig { issuer: string; @@ -115,15 +115,6 @@ function json(data: unknown, status = 200): Response { }); } -function cookieValue(request: Request, name: string): string | null { - const raw = request.headers.get("Cookie") ?? ""; - for (const part of raw.split(";")) { - const [k, ...v] = part.trim().split("="); - if (k === name) return v.join("=") || ""; - } - return null; -} - function escapeHtml(value: string): string { return value.replace(/[&<>"']/g, (ch) => ({ "&": "&", @@ -134,11 +125,10 @@ function escapeHtml(value: string): string { })[ch] || ch); } -function authAlreadyInProgress(): Response { - return new Response( - "
ProAgentStore MCP sign-in is already in progress in another tab. Complete that sign-in, then return to your MCP client.
", - { headers: { "Content-Type": "text/html; charset=utf-8" } }, - ); +function startEndpointFor(config: OAuthConfig, provider: AuthProvider): string { + const base = config.authStart.replace(/\/(?:github|google)\/start$/, ""); + if (base === config.authStart) return config.authStart; + return `${base}/${provider}/start`; } async function register(request: Request, config: OAuthConfig): Promise${clientName} wants to use ProAgentStore MCP tools as your account.
- Continue with GitHub +