fix(oauth): route 400 token-exchange errors (invalid_grant) to onError#526
fix(oauth): route 400 token-exchange errors (invalid_grant) to onError#526mendrinos wants to merge 1 commit into
Conversation
Per RFC 6749 §5.2 the token endpoint returns 4xx (usually 400, e.g.
invalid_grant) with a structured { error } body for OAuth failures; only
invalid_client may use 401. requestAccessToken previously intercepted
only 401 and re-threw everything else, so 400 invalid_grant bypassed
onError and surfaced as an unhandled error. Route any 4xx response
carrying a structured error body to onError; re-throw network/5xx/opaque
errors.
Fixes atinux#525
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: defaults Review profile: CHILL Plan: Pro Plus Run ID: 📒 Files selected for processing (1)
📝 WalkthroughWalkthroughThe ChangesOAuth Error Handling
Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 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 |
🔗 Linked issue
Fixes #525
❓ Type of change
📚 Description
requestAccessTokenonly intercepted401token-exchange failures and routed them toonError; every other status was re-thrown. But per RFC 6749 §5.2 the token endpoint returns400 Bad Requestfor the common OAuth failures (invalid_grant,invalid_request,unauthorized_client,unsupported_grant_type,invalid_scope) — onlyinvalid_clientmay use401.As a result, the most common real-world failure —
400 invalid_grantfrom a reused/expired one-time authorization code (back/forward navigation, callback refresh, link prefetch/scanner,prompt=nonesilent re-auth) — bypassedonErrorand surfaced as anunhandlederror. Reproduced on Google, Facebook and Microsoft, which all sharerequestAccessToken.This PR routes any 4xx response that carries a structured OAuth
errorbody to the existinghandleAccessTokenErrorResponse/onErrorpath, while still re-throwing genuine network errors, 5xx, and opaque non-OAuth responses.Why gated on
error.data?.error: ensures only structured OAuth error responses (per §5.2) are swallowed — opaque 4xx HTML/proxy errors still throw. Backward compatible:401 invalid_clientcontinues to be routed toonErrorexactly as before.📝 Checklist
Summary by CodeRabbit