fix: OAuth credential proxy — auto-refresh tokens + beta header#1076
Open
glifocat wants to merge 1 commit intoqwibitai:mainfrom
Open
fix: OAuth credential proxy — auto-refresh tokens + beta header#1076glifocat wants to merge 1 commit intoqwibitai:mainfrom
glifocat wants to merge 1 commit intoqwibitai:mainfrom
Conversation
OAuth users hitting 401 "OAuth authentication is currently not supported" because the proxy was missing the required `anthropic-beta: oauth-2025-04-20` header. Additionally, tokens in .env expire after ~4 hours with no refresh. Changes: - Add src/oauth-token.ts: reads ~/.claude/.credentials.json, caches tokens in memory, auto-refreshes via platform.claude.com when expired, serializes concurrent refreshes through a promise chain, writes back atomically - Rewrite credential proxy: async handler, unconditional credential injection (no exchange-based flow), beta header for OAuth, req.pipe() streaming, /health endpoint, JSON error responses, 10-min timeout - Update tests for new behavior (mock getFreshOAuthToken, process.env for upstream URL, unconditional OAuth injection assertions) Based on work by @calebfaruki (qwibitai#871) and @kianwoon (qwibitai#930/qwibitai#969). Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
4ff6391 to
eb22f58
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Change
.claude/skills/Description
OAuth users are hitting 401 "OAuth authentication is currently not supported" because the credential proxy doesn't send the required
anthropic-beta: oauth-2025-04-20header. Additionally, OAuth tokens stored in.envexpire after ~4 hours with no automatic refresh, causing silent auth failures.This PR fixes both issues:
1. Beta header injection (
credential-proxy.ts):anthropic-beta: oauth-2025-04-20on all OAuth-proxied requestsreq.pipe()streaming for large request bodies (base64 images)/healthendpoint, JSON error responses (502/503), 10-min timeout2. Token auto-refresh (new
oauth-token.ts):~/.claude/.credentials.json(same file theclaudeCLI maintains)platform.claude.com/v1/oauth/token.envtoken if credentials file is unavailableBased on work by @calebfaruki (#871) and @kianwoon (#930, #969). Supersedes both PRs with a combined, tested implementation.
Related issues: #730 (OAuth tokens expire)