Fix PKCE code verifier not generated for initial OAuth flow - #532
Conversation
When `create_oauth_flow()` is called without an explicit `code_verifier` (i.e. during the initial auth flow in `start_auth_flow()`), the function never sets `autogenerate_code_verifier=True` on the Flow constructor. oauthlib 3.2+ automatically adds `code_challenge` to the authorization URL at the session level, so Google expects a matching `code_verifier` during the token exchange. However, since `Flow.code_verifier` remains `None`, that `None` gets stored in the session store and later passed back during the callback — causing Google to reject the token exchange with `(invalid_grant) Missing code verifier`. The fix adds `autogenerate_code_verifier=True` in the else branch so the Flow object generates and exposes a proper PKCE code verifier that gets stored and reused during the callback token exchange. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review infoConfiguration used: defaults Review profile: CHILL Plan: Pro 📒 Files selected for processing (2)
📝 WalkthroughWalkthroughAdded an Changes
Sequence Diagram(s)(omitted) Estimated code review effort🎯 2 (Simple) | ⏱️ ~10 minutes Possibly related issues
Possibly related PRs
Suggested labels
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 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 |
…ace_mcp into fix/pkce-code-verifier
Summary
(invalid_grant) Missing code verifiererror during OAuth callback token exchangeautogenerate_code_verifier=Truein theelsebranch ofcreate_oauth_flow()so the initial auth flow generates a proper PKCE verifierProblem
When
create_oauth_flow()is called without an explicitcode_verifier(duringstart_auth_flow()), the function never setsautogenerate_code_verifier=True.oauthlib 3.2+ automatically adds
code_challengeto the authorization URL at the session level, so Google expects a matchingcode_verifierduring the token exchange. However,Flow.code_verifierremainsNone, gets stored asNonein the session store, and is later passed back during the callback — causing Google to reject the exchange with(invalid_grant) Missing code verifier.Fix
Add
autogenerate_code_verifier=Truein the else branch ofcreate_oauth_flow()so theFlowobject generates and exposes a proper PKCE code verifier that gets stored and reused during the callback.Test plan
🤖 Generated with Claude Code
Summary by CodeRabbit
Bug Fixes
Tests