Never stop coding. Free MIT AI gateway: one endpoint, 375 providers (150+ free), 1,400+ models Kimi, Claude, GPT, Gemini, GLM, DeepSeek, MiniMax. Works with Claude Code, Codex, Cursor, OpenCode, Cline & Copilot. Quota-aware auto-fallback, RTK+Caveman compression saves 15-95% tokens, MCP/A2A, Desktop/PWA. Built by 900+ contributors
TypeScript a2aai-agentsai-gatewayanthropicclaudeclaude-codeclinecodexcopilotcursordeepseekfree-aigeminikimillm-gatewaymcpopenaiopenai-proxyqwentoken-saver
fix(oauth): switch windsurf provider to import_token flow
yuna amelia6d157e481f08
diff --git a/src/lib/oauth/providers.ts b/src/lib/oauth/providers.tsindex 3689b4aa47..f022e43856 100644--- a/src/lib/oauth/providers.ts+++ b/src/lib/oauth/providers.ts@@ -37,11 +37,7 @@ function hasCustomGoogleOAuthCredentials(providerName, env = process.env) {* public callback URL documented in .env.example / docs/README so the popup can* navigate back to OmniRoute instead of stalling on localhost.*/-export function resolveBrowserOAuthRedirectUri(- providerName,- redirectUri,- env = process.env-) {+export function resolveBrowserOAuthRedirectUri(providerName, redirectUri, env = process.env) {if (!GOOGLE_BROWSER_PROVIDERS.has(providerName)) {return redirectUri;}@@ -89,12 +85,37 @@ export function getProviderNames() {}/**- * Generate auth data for a provider+ * Generate auth data for a provider.+ *+ * Returns `{ supported: false, error }` (no `authUrl`) for providers whose+ * browser-OAuth flow is currently disabled — e.g. windsurf / devin-cli post+ * 2026-05 rebrand, where the legacy PKCE endpoint at app.devin.ai returns 404.+ * Callers (UI / API route) should surface the `error` string and route the+ * user to the import-token flow instead.*/export function generateAuthData(providerName, redirectUri) {const provider = getProvider(providerName);const { codeVerifier, codeChallenge, state } = generatePKCE();+ if (provider.flowType === "import_token") {+ const error =+ providerName === "windsurf" || providerName === "devin-cli"+ ? "Browser login disabled — paste token from https://windsurf.com/show-auth-token instead. Phase 2 will restore Firebase OAuth via app.devin.ai successor."+ : `Browser login is disabled for ${providerName}. Use the import-token flow instead.`;+ return {+ authUrl: undefined,+ state: undefined,+ codeVerifier: undefined,+ codeChallenge: undefined,+ redirectUri,+ flowType: provider.flowType,+ fixedPort: provider.fixedPort,+ callbackPath: provider.callbackPath || "/callback",+ supported: false,+ error,+ };+ }+let authUrl;if (provider.flowType === "device_code") {authUrl = null;diff --git a/src/lib/oauth/providers/windsurf.ts b/src/lib/oauth/providers/windsurf.tsindex 8990a2a580..b334bc095f 100644--- a/src/lib/oauth/providers/windsurf.ts+++ b/src/lib/oauth/providers/windsurf.ts@@ -1,121 +1,50 @@import { WINDSURF_CONFIG } from "../constants/oauth";/**- * Windsurf / Devin CLI OAuth Provider+ * Windsurf / Devin CLI OAuth Provider — import-token only (Phase 1 hotfix, 2026-05-29).*- * Uses PKCE Authorization Code Flow — same pattern as Codex CLI.- * Extracted from Devin CLI binary (devin.exe string analysis):+ * The previous PKCE Authorization Code flow targeting `https://app.devin.ai/editor/signin`+ * stopped working post-rebrand: that endpoint now returns 404. Until Phase 2 ports the+ * Firebase OAuth + RegisterUser flow (see docs/superpowers/specs/2026-05-29-windsurf-login-fix-design.md),+ * the only supported login path is import-token:*- * 1. OmniRoute starts a local callback server (random port, 127.0.0.1)- * 2. Browser opens:- * https://app.devin.ai/editor/signin- * ?response_type=code- * &redirect_uri=http://127.0.0.1:PORT/auth/callback- * &code_challenge=<S256_CHALLENGE>- * &code_challenge_method=S256- * 3. User logs in (Google / GitHub / Windsurf Enterprise)- * 4. Browser redirects back to callback server with `code`- * 5. Exchange code via Windsurf Connect JSON:- * POST https://server.codeium.com/exa.seat_management_pb.SeatManagementService/ExchangePKCEAuthorizationCode- * { "code": "...", "codeVerifier": "...", "redirectUri": "..." }- * 6. Response: { "windsurfApiKey": "...", "apiServerUrl": "...", ... }- * 7. `windsurfApiKey` stored as `accessToken` (= WINDSURF_API_KEY)+ * 1. User opens https://windsurf.com/show-auth-token in a browser+ * 2. Copies the displayed Windsurf API key (`sk-ws-...` style)+ * 3. Pastes it into OmniRoute via /api/oauth/windsurf/import-token*- * Fallback (import_token): user visits windsurf.com/show-auth-token,- * copies their API key, and pastes it into the connection form.+ * The pasted token is stored as `accessToken` and used directly by `WindsurfExecutor`+ * (open-sse/executors/windsurf.ts) as the `Authorization: Bearer ...` header against+ * the inference server (`server.self-serve.windsurf.com`).*/export const windsurf = {config: WINDSURF_CONFIG,- flowType: "authorization_code_pkce",- // Fixed callback path expected by Devin CLI auth flow- callbackPath: WINDSURF_CONFIG.callbackPath,- // Port 0 = OS assigns a free port (we use the globalThis devin callback state)- callbackPort: WINDSURF_CONFIG.callbackPort,-- buildAuthUrl: (- config: typeof WINDSURF_CONFIG,- redirectUri: string,- state: string,- codeChallenge: string- ) => {- const params = new URLSearchParams({- response_type: "code",- redirect_uri: redirectUri,- code_challenge: codeChallenge,- code_challenge_method: config.codeChallengeMethod,- state,- });- return `${config.authorizeUrl}?${params.toString()}`;- },+ flowType: "import_token" as const,/**- * Exchange authorization code for Windsurf API key.- * Uses the Windsurf Connect JSON protocol (not standard OAuth token endpoint).+ * Validate a pasted Windsurf API key. Accepts the `sk-ws-...` format issued by+ * windsurf.com/show-auth-token and the legacy raw-token format. Empty or+ * whitespace-only tokens are rejected.*/- exchangeToken: async (- config: typeof WINDSURF_CONFIG,- code: string,- redirectUri: string,- codeVerifier: string- ) => {- const url = `${config.apiServerUrl}${config.exchangePath}`;- const response = await fetch(url, {- method: "POST",- headers: {- "Content-Type": "application/json",- Accept: "application/json",- // Connect protocol version header- "Connect-Protocol-Version": "1",- },- body: JSON.stringify({- code,- codeVerifier,- redirectUri,- }),- });-- if (!response.ok) {- const error = await response.text();- throw new Error(`Windsurf token exchange failed (${response.status}): ${error}`);+ validateImportToken(token: string): { valid: boolean; reason?: string } {+ const trimmed = (token ?? "").trim();+ if (!trimmed) {+ return { valid: false, reason: "Token is empty" };}-- const data = await response.json();- return data;+ if (trimmed.length < 16) {+ return { valid: false, reason: "Token is too short" };+ }+ return { valid: true };},/**- * Map exchange response to OmniRoute connection fields.- * The Windsurf Connect response uses camelCase JSON:- * windsurfApiKey, apiServerUrl, devinWebappHost, devinApiUrl+ * Map a pasted import token onto the connection record. The token IS the+ * Windsurf API key; there is no exchange step.*/- mapTokens: (tokens: {- windsurfApiKey?: string;- apiServerUrl?: string;- devinWebappHost?: string;- devinApiUrl?: string;- // Fallback import-token fields- accessToken?: string;- apiKey?: string;- refreshToken?: string;- expiresIn?: number;- email?: string;- authMethod?: string;- }) => {- // PKCE flow: token is in windsurfApiKey- const token = tokens.windsurfApiKey || tokens.accessToken || tokens.apiKey || "";-+ mapTokens(token: string) {return {accessToken: token,- // Windsurf API keys are long-lived — no refresh token needed- refreshToken: tokens.refreshToken || null,- expiresIn: tokens.expiresIn || 0,- email: tokens.email || null,- providerSpecificData: {- authMethod: tokens.authMethod || (tokens.windsurfApiKey ? "browser" : "import"),- apiServerUrl: tokens.apiServerUrl || null,- devinWebappHost: tokens.devinWebappHost || null,- devinApiUrl: tokens.devinApiUrl || null,- },+ refreshToken: null,+ expiresAt: null,};},};diff --git a/tests/unit/windsurf-devin-executors.test.ts b/tests/unit/windsurf-devin-executors.test.tsindex 8641d87977..c75087f902 100644--- a/tests/unit/windsurf-devin-executors.test.ts+++ b/tests/unit/windsurf-devin-executors.test.ts@@ -234,3 +234,29 @@ describe("DevinCli binary resolution", () => {}});});++// ─── Phase 1 hotfix: windsurf/devin-cli import-token flow ────────────────────+import { generateAuthData, getProvider } from "@/lib/oauth/providers";++test("windsurf provider: flowType is import_token (PKCE disabled post-rebrand)", () => {+ const provider = getProvider("windsurf");+ assert.equal(provider.flowType, "import_token");+});++test("devin-cli provider: flowType is import_token (shares windsurf config)", () => {+ const provider = getProvider("devin-cli");+ assert.equal(provider.flowType, "import_token");+});++test("windsurf provider: generateAuthData returns no authUrl (PKCE flow disabled)", () => {+ const data = generateAuthData("windsurf", "http://localhost:0/auth/callback");+ assert.equal(data.authUrl, undefined);+ assert.equal(data.supported, false);+ assert.match(data.error ?? "", /import-token|disabled|app\.devin\.ai/i);+});++test("devin-cli provider: generateAuthData returns no authUrl", () => {+ const data = generateAuthData("devin-cli", "http://localhost:0/auth/callback");+ assert.equal(data.authUrl, undefined);+ assert.equal(data.supported, false);+});