Skip to content

fix: use plain HTTP client with claude-cli User-Agent for OAuth token exchange#52

Merged
mirrorange merged 1 commit intomirrorange:mainfrom
Rivenlalala:feature/oauth-plain-client
Mar 28, 2026
Merged

fix: use plain HTTP client with claude-cli User-Agent for OAuth token exchange#52
mirrorange merged 1 commit intomirrorange:mainfrom
Rivenlalala:feature/oauth-plain-client

Conversation

@Rivenlalala
Copy link
Copy Markdown

@Rivenlalala Rivenlalala commented Mar 25, 2026

Problem

OAuth token exchange to console.anthropic.com/v1/oauth/token returns 429 because Anthropic now rejects requests carrying browser fingerprinting headers (TLS JA3, browser User-Agent) or non-matching User-Agent values.

The current exchange_token() and refresh_access_token() use _request() which creates a session with impersonate="chrome", triggering the rejection.

Changes

  • Add create_plain_session() in http_client.py — prefers httpx (no TLS fingerprinting), falls back to curl_cffi/rnet with impersonate=None
  • Add _token_request() in oauth.py — uses the plain session with Content-Type: application/x-www-form-urlencoded and User-Agent: claude-cli/2.1.81 (external, cli)
  • Switch exchange_token() and refresh_access_token() to use _token_request()

What #51 was missing

PR #51 correctly identified the need for a plain HTTP session and application/x-www-form-urlencoded content type, but used User-Agent: anthropic which Anthropic also blanket-rejects with 429. Per the opencode discussion, the token endpoint requires a User-Agent matching Claude Code's format (claude-cli/<version> (external, cli)).

References

… exchange

Anthropic rejects requests to console.anthropic.com/v1/oauth/token that
carry browser fingerprinting or non-matching User-Agent headers with 429.
Use a plain httpx session with User-Agent matching Claude Code's format.

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
@mirrorange mirrorange merged commit 3f68e98 into mirrorange:main Mar 28, 2026
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.

2 participants