Skip to content

Anthropic OAuth authentication with PKCE and auto-refresh - #76

Merged
jamiepine merged 5 commits into
spacedriveapp:mainfrom
Marenz:pr/anthropic-oauth
Feb 20, 2026
Merged

Anthropic OAuth authentication with PKCE and auto-refresh#76
jamiepine merged 5 commits into
spacedriveapp:mainfrom
Marenz:pr/anthropic-oauth

Conversation

@Marenz

@Marenz Marenz commented Feb 20, 2026

Copy link
Copy Markdown
Collaborator

Builds on @egenvall's Claude Code Token support (#32 ) and adds full OAuth lifecycle management.

What this adds:

  • spacebot auth login — PKCE OAuth flow (opens browser, user pastes code, tokens stored in anthropic_oauth.json)
  • spacebot auth status/refresh/logout — credential management CLI
  • Auto-refresh in LlmManager — checks token expiry before each Anthropic API call, refreshes transparently and persists new tokens
  • OAuth as onboarding option — spacebot auth login offered alongside manual API key entry during first-run setup
  • Correct OAuth request headers — Bearer auth, anthropic-beta: oauth-2025-04-20, user-agent: claude-code/2.1.49, ?beta=true query param, tool name mcp_ prefix/deprefix

Also includes fixes from @egenvall's branch:

  • Fix user-agent string (claude-cliclaude-code) which caused 403s
  • Fix empty response parsing when model returns only thinking blocks (adaptive thinking on 4.6 models)
  • Debug logging for empty Anthropic responses

egenvall and others added 5 commits February 20, 2026 13:56
- Add support for `claude setup-token` as the Anthropic API Key
- Add support for dynamic-thinking per router for supported models

Clean up

Revert quickstart
Log stop_reason and raw content array at debug level when the API
returns a 200 but with no text or tool_use blocks.
Skip thinking blocks instead of discarding them, preventing empty response errors when model returns only thinking content.
- spacebot auth login: opens browser for Claude Pro/Max or Console OAuth,
  user pastes authorization code, tokens stored in anthropic_oauth.json
- spacebot auth status/refresh/logout: manage stored credentials
- LlmManager loads OAuth tokens on startup and auto-refreshes before API
  calls when the access token expires (5-minute buffer)
- OAuth tokens take priority over static ANTHROPIC_API_KEY from .env
- Onboarding flow offers OAuth as an alternative to manual API key entry
- Fix EnvGuard in tests to clear all provider env vars, add OAuth test
@egenvall

Copy link
Copy Markdown
Contributor

Neat! I went down this route initially but cut it for scope as I had limited time, this makes sense and is a great UX improvement.

@jamiepine
jamiepine merged commit 6e96fe1 into spacedriveapp:main Feb 20, 2026
cloudrumbles added a commit to cloudrumbles/spacebot that referenced this pull request Feb 21, 2026
rktmeister pushed a commit to rktmeister/spacebot that referenced this pull request Mar 11, 2026
Anthropic OAuth authentication with PKCE and auto-refresh
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.

3 participants