-
-
Notifications
You must be signed in to change notification settings - Fork 3.9k
OAuth Authentication Support for Anthropic #1565
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
ksylvan
merged 9 commits into
danielmiessler:main
from
ksylvan:0701-claude-oauth-support
Jul 5, 2025
Merged
OAuth Authentication Support for Anthropic #1565
ksylvan
merged 9 commits into
danielmiessler:main
from
ksylvan:0701-claude-oauth-support
Jul 5, 2025
Conversation
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
Collaborator
Author
|
Stopped here: We have to figure out how Claude Code does its magic when it grabs the OAuth token. |
Collaborator
|
LGTM |
- Move golang.org/x/oauth2 from indirect to direct dependency - Add OAuth login option for Anthropic client - Implement PKCE OAuth flow with browser integration - Add custom HTTP transport for OAuth Bearer tokens - Support both API key and OAuth authentication methods - Add Claude Code system message for OAuth sessions - Update REST API to handle OAuth tokens - Improve environment variable name sanitization with regex
9b0b531 to
4bff88f
Compare
Collaborator
Author
|
Okay, @eugeis and @johnsaigle, I got it to work. I will be finalizing the PR soon. We use the same technique that the |
… authentication ## CHANGES - Add automatic OAuth token refresh when expired - Implement persistent token storage using common OAuth storage - Remove deprecated AuthToken setting from client configuration - Add token validation with 5-minute expiration buffer - Create refreshToken function for seamless token renewal - Update OAuth flow to save complete token information - Enhance error handling for OAuth authentication failures - Simplify client configuration by removing manual token management
## CHANGES - Remove OAuth-specific v1 endpoint handling logic - Standardize all API calls to use v2 endpoint - Simplify baseURL configuration by removing conditional branching - Update endpoint logic to always append v2 suffix
…ion and timeout handling ## CHANGES - Add automatic OAuth flow initiation when no token exists - Implement fallback re-authentication when token refresh fails - Add timeout contexts for OAuth and refresh operations - Create context-aware OAuth flow and token exchange functions - Enhance error handling with graceful authentication recovery - Add user input timeout protection for authorization codes - Preserve refresh tokens during token exchange operations
### CHANGES - Remove redundant base URL trimming logic - Append base URL directly without modification - Eliminate conditional check for API version suffix
…te module ## CHANGES - Remove OAuth transport implementation from main client - Extract OAuth flow functions to separate module - Remove unused imports and constants from client - Replace inline OAuth transport with NewOAuthTransport call - Update runOAuthFlow to exported RunOAuthFlow function - Clean up token management and refresh logic - Simplify client configuration by removing OAuth internals
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.
OAuth Authentication Support for Anthropic
Summary
This PR adds OAuth authentication support for the Anthropic Claude provider in Fabric, allowing users to authenticate using their Claude account credentials instead of requiring an API key. The implementation includes secure token storage, automatic token refresh, and comprehensive test coverage.
Related Issues
Closes #1534
Screen Shots
Files Changed
New Files Added
common/oauth_storage.go- Core OAuth token storage functionality with secure file operationscommon/oauth_storage_test.go- Comprehensive test suite for OAuth storage operationsplugins/ai/anthropic/oauth.go- OAuth flow implementation specific to Anthropic's authentication systemModified Files
plugins/ai/anthropic/anthropic.go- Enhanced to support OAuth authentication alongside existing API key authenticationgo.mod- Movedgolang.org/x/oauth2from indirect to direct dependencyrestapi/configuration.go- Added OAuth configuration option to REST API endpointsCode Changes
OAuth Storage Implementation
The new
OAuthStoragestruct provides secure token management:Key features:
~/.config/fabric/with 0600 permissionsAnthropic OAuth Integration
The OAuth implementation includes:
Configuration Updates
Added OAuth support to the REST API configuration:
anthropic_use_oauth_loginconfiguration optionReason for Changes
This enhancement addresses the need for users to authenticate with Claude using their existing accounts rather than requiring separate API keys. OAuth provides a more user-friendly authentication experience and aligns with modern authentication practices.
Impact of Changes
Positive Impacts
Potential Risks
Test Plan
The implementation includes comprehensive unit tests covering:
Manual testing should verify:
Demo of functionality
Removed the auth token (
~/.config/fabric/.claude_oauth).Additional Notes
Security Considerations
Backward Compatibility