fix(oauth): fall back to system proxy when OAuth session has no proxy_url#138
fix(oauth): fall back to system proxy when OAuth session has no proxy_url#138DeliciousBuding wants to merge 1 commit into
Conversation
…_url When adding accounts via OAuth flow, if no proxy_url is provided in either the generate-auth-url step or the exchange-code step, the request to auth.openai.com goes direct — which fails from geo-blocked regions (HK, etc.) with 403 or Cloudflare 502. Add a fallback to `h.store.GetProxyURL()` (the system default proxy) in both `ExchangeOAuthCode` and `OAuthCallback` handlers, so OAuth token exchange always goes through a working proxy chain. Fixes the issue where the admin UI's "Add Account via OAuth" button returns a Cloudflare 502 HTML page instead of a proper error. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
📝 WalkthroughWalkthroughThe OAuth handler ( ChangesProxy URL fallback reliability
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Poem
🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
Summary
proxy_urlis provided in either thegenerate-auth-urlstep or theexchange-codestep, the request toauth.openai.comgoes direct — which fails from geo-restricted regions with 403, wrapped by codex2api as 502.h.store.GetProxyURL()(the system default proxy) in bothExchangeOAuthCodeandOAuthCallbackhandlers.Root cause
The
exchange-codeendpoint inadmin/oauth.gousessess.ProxyURL(set duringgenerate-auth-url) merged withreq.ProxyURL(from the request body). When both are empty,auth.BuildHTTPClient("")creates a direct HTTP client with no proxy, and the call tohttps://auth.openai.com/oauth/tokenfails from regions where OpenAI blocks direct access.Fix
Three lines added across two handlers:
ExchangeOAuthCode: after merging session + request proxy_url, if still empty, loadh.store.GetProxyURL()OAuthCallback: same fallback, and unified allsess.ProxyURLreferences to use the resolvedproxyURLvariableVerification
exchange-codereturns 502 in under 70ms with an HTML error body (direct call → geo-blocked → 403)exchange-codereturns a proper JSON error with upstream response body, confirming the proxy is used for the OAuth token exchangeTested on
🤖 Generated with Claude Code