-
Notifications
You must be signed in to change notification settings - Fork 121
Implement OAuth 2.0 Token Exchange (RFC 8693) support #2082
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
base: main
Are you sure you want to change the base?
Conversation
Add a token exchange client library that enables ToolHive to exchange incoming access tokens for backend-specific tokens when proxying MCP server requests. The implementation follows RFC 8693 and is compatible with standard oauth2.TokenSource interfaces. Fixes #2064
@claude review this PR. Make sure to review it from the security perspective and read RFC 8693 before the review. |
Claude finished @jhrozek's task —— View job OAuth 2.0 Token Exchange (RFC 8693) Security ReviewI've completed a comprehensive security review of this Token Exchange implementation. Here are my findings: Review Tasks:
🔒 Security Analysis SummaryOverall Assessment: SECURE ✅ 🟢 Security Strengths1. Credential Protection Excellence
2. Robust Input Validation
3. DoS Protection Measures
4. Error Handling Security
🟡 Areas for Security Consideration1. SSRF Protection Awareness
2. Transport Security
🟢 RFC 8693 Compliance AnalysisRequired Parameters ✅
Optional Parameters ✅
Response Handling ✅
🟢 Integration Assessmentoauth2.TokenSource Compatibility ✅
Design Patterns ✅
📋 Minor Enhancement Suggestions
🧪 Test Coverage AnalysisExcellent test coverage with 26 comprehensive test scenarios covering:
🚀 ConclusionThis is a high-quality, security-conscious implementation of RFC 8693. The code demonstrates:
Recommendation: APPROVE - This implementation meets enterprise security standards and is ready for production use. Job Run: Link |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR implements OAuth 2.0 Token Exchange (RFC 8693) support for ToolHive by adding a token exchange client library. The implementation allows exchanging incoming access tokens for backend-specific tokens when proxying MCP server requests, following RFC 8693 standards and being compatible with standard oauth2.TokenSource interfaces.
- Adds a comprehensive token exchange client library with Config, TokenSource implementation, and HTTP request handling
- Implements proper error handling for OAuth errors, network failures, and malformed responses
- Includes extensive test coverage for happy path, error scenarios, edge cases, and security considerations
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
File | Description |
---|---|
pkg/auth/tokenexchange/exchange.go | Core implementation of OAuth 2.0 token exchange with Config, TokenSource, and HTTP handling |
pkg/auth/tokenexchange/exchange_test.go | Comprehensive test suite covering success cases, error handling, and edge cases |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
if c.ClientID == "" { | ||
return fmt.Errorf("ClientID is required") | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The validation requires ClientID but the implementation supports public clients (no client credentials). This creates an inconsistency since line 373-378 in addClientAuthentication allows empty ClientID/ClientSecret. Consider making ClientID optional or documenting why it's required for this specific use case.
if c.ClientID == "" { | |
return fmt.Errorf("ClientID is required") | |
} | |
// ClientID is optional to support public clients (RFC 8693, section 2.2) | |
// If your use case requires a ClientID, ensure it is set in the Config. |
Copilot uses AI. Check for mistakes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is technically right, but the IDPs I looked all support only confidential clients.
HOWEVER, this made me realize that the authentication I used (using the form fields) is technically supported, but both keycloak and okta docs seem to suggest that it's preferred to use Authorization: Bearer base64(client_id:client_secret)
.
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #2082 +/- ##
==========================================
+ Coverage 48.20% 48.53% +0.33%
==========================================
Files 233 239 +6
Lines 29229 30231 +1002
==========================================
+ Hits 14089 14673 +584
- Misses 14106 14448 +342
- Partials 1034 1110 +76 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Add a token exchange client library that enables ToolHive to exchange incoming access tokens for backend-specific tokens when proxying MCP server requests. The implementation follows RFC 8693 and is compatible with standard oauth2.TokenSource interfaces.
Fixes #2064