fix: route OAuth callback token exchange through proxy fetch#1342
Open
iherdt wants to merge 1 commit into
Open
fix: route OAuth callback token exchange through proxy fetch#1342iherdt wants to merge 1 commit into
iherdt wants to merge 1 commit into
Conversation
The /oauth/callback handler called `auth()` without a fetchFn, so the SDK fell back to global fetch for the metadata + token-endpoint requests. Auth servers that emit incomplete CORS headers (e.g. `/oauth2/token` missing Access-Control-Allow-Origin on the response) caused the token exchange to fail with `TypeError: Failed to fetch`, even when initial registration succeeded via the proxy. Wire config + connectionType into OAuthCallback and build a createProxyFetch when connectionType === "proxy", matching the existing pattern in useConnection and AuthDebugger. Reproducible against the WorkOS shop MCP at https://shop.workos.com/mcp (signin.shop.workos.com auth server). With this fix the full OAuth dance — metadata discovery, registration, authorize redirect, callback, token exchange — completes end to end.
8e2e820 to
6957754
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The
/oauth/callbackhandler callsauth()without passing afetchFn, so the SDK falls back to globalfetchfor the metadata + token-endpoint requests. Auth servers that emit incomplete CORS headers on POST responses (e.g./oauth2/tokenreturning noAccess-Control-Allow-Origineven though the preflight does) cause the token exchange to fail withTypeError: Failed to fetch— even when the initial registration phase succeeded via the existing proxy fetch path.This matches the proxy-fetch pattern already used in
useConnection.handleAuthErrorandAuthDebugger, so it's not a new mechanism — just an existing one applied to the callback that was missed.Type of Change
Changes Made
client/src/components/OAuthCallback.tsx: acceptconfigandconnectionTypeprops; build acreateProxyFetch(config)whenconnectionType === "proxy"; pass that asfetchFntoauth().client/src/App.tsx: threadconfigandconnectionTypethrough to the lazy-loadedOAuthCallback.Net diff: +25 / -4.
Related Issues
None filed yet. The same root cause as the proxy-fetch work in
useConnection(commit that addedcreateProxyFetch), just for a different callsite.Testing
OAuthCallback.tsx)Reproducer
Real-world repro against WorkOS's demo MCP — its auth server
signin.shop.workos.comreturns noAccess-Control-Allow-Originon the/oauth2/tokenPOST response (only on the preflight).https://shop.workos.com/mcp, Connection Type = Via Proxy./fetch, browser redirects to authorize, user signs in, lands at/oauth/callback?code=..., thenTypeError: Failed to fetchtoast appears and the token exchange dies. Browser console shows three CORS errors againstsignin.shop.workos.com.well-known/*and/oauth2/tokenendpoints.localhost:6277/fetchinstead, the token exchange completes, and the inspector connects to the MCP server.Test Results
npm test -- --testPathPattern="OAuthCallback|App|proxyFetch"→ 59/59 pass. Prettier check passes on changed files.Checklist
prettier --checkpasses)Breaking Changes
None.
OAuthCallbackgains two required props but it's only mounted from one place inApp.tsx(line 1288), which is updated in this PR.Additional Context
The original proxy-fetch work landed for the initial-connection OAuth flow but the callback was a separate code path. With both wired up, the inspector now works end-to-end against any auth server whose CORS is "good enough for browsers that don't preflight" but trips on POST responses — a class of misconfiguration we've seen in the wild beyond just WorkOS.