Skip to content

fix(google-oauth): bypass PKCE for headless token exchange#1101

Closed
teyrebaz33 wants to merge 1 commit intoNousResearch:mainfrom
teyrebaz33:fix/google-oauth-pkce-headless
Closed

fix(google-oauth): bypass PKCE for headless token exchange#1101
teyrebaz33 wants to merge 1 commit intoNousResearch:mainfrom
teyrebaz33:fix/google-oauth-pkce-headless

Conversation

@teyrebaz33
Copy link
Copy Markdown
Contributor

Fixes #1093

Problem

On headless systems, get_auth_url() generates an auth URL via Flow.authorization_url() which includes PKCE parameters. When the user manually copies the auth code and runs --auth-code, a new Flow object is created — the original PKCE verifier is lost. Google's token endpoint then rejects the exchange with invalid_grant: Missing code verifier.

Fix

  • get_auth_url(): builds the authorization URL manually without code_challenge / code_challenge_method parameters
  • exchange_auth_code(): performs a direct HTTP POST to the token endpoint without PKCE, instead of using flow.fetch_token()

Desktop OAuth clients (installed apps) are not required to use PKCE, and Google's token endpoint accepts non-PKCE requests for installed applications.

Changes

  • skills/productivity/google-workspace/scripts/setup.py: rewrite get_auth_url() and exchange_auth_code() to avoid PKCE
  • tests/skills/test_google_oauth_setup.py: new test file with 8 tests covering both functions

On headless systems the Flow object that generated the auth URL is no
longer in memory when the user pastes the auth code, so the PKCE verifier
is lost. This caused 'Missing code verifier' errors from Google's token
endpoint.

Fix:
- get_auth_url(): builds the authorization URL manually without
  code_challenge / code_challenge_method parameters
- exchange_auth_code(): performs a direct HTTP POST to the token endpoint
  without PKCE instead of using flow.fetch_token()

Desktop OAuth clients (installed apps) are not required to use PKCE and
Google's token endpoint accepts non-PKCE requests for installed apps.

Fixes NousResearch#1093
@teknium1
Copy link
Copy Markdown
Contributor

Fixed via #1396. The underlying headless/manual OAuth bug was real, but instead of bypassing PKCE we preserved the pending OAuth state and code verifier across and , keeping the library-supported PKCE flow intact. Thanks for surfacing and working on the issue.

@teknium1 teknium1 closed this Mar 15, 2026
@teknium1
Copy link
Copy Markdown
Contributor

Fixed via #1396. The underlying headless/manual OAuth bug was real, but instead of bypassing PKCE we preserved the pending OAuth state and code verifier across --auth-url and --auth-code, keeping the library-supported PKCE flow intact. Thanks for surfacing and working on the issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Google OAuth PKCE Issue on Headless Systems

2 participants