[POC] Implement OAuth2 Integration#161
Draft
ldjebran wants to merge 1 commit into
Draft
Conversation
Coverage Report
File Coverage
|
||||||||||||||||||||||||||||||||||||||||||||
0e8f6f3 to
0d3bc6c
Compare
Codecov Report❌ Patch coverage is
@@ Coverage Diff @@
## main #161 +/- ##
===========================================
- Coverage 80.56% 70.50% -10.07%
===========================================
Files 9 10 +1
Lines 772 956 +184
Branches 201 255 +54
===========================================
+ Hits 622 674 +52
- Misses 88 202 +114
- Partials 62 80 +18
Flags with carried forward coverage won't be shown. Click here to find out more.
🚀 New features to boost your workflow:
|
0d3bc6c to
0d35676
Compare
6238a3e to
1757885
Compare
9267e1c to
665fb21
Compare
665fb21 to
7e54367
Compare
f9144df to
4ca1975
Compare
Enable opt-in OAuth 2.1 authentication alongside the existing Bearer token flow. When OAUTH2_CLIENT_ID is set, MCP clients (Claude Code, Cursor, Gemini CLI) are automatically redirected to the AAP authorization server's login page when no token is present. Key features: - OAuth2 proxy between MCP clients and AAP auth server (OIDC discovery, PKCE, token exchange, revocation) - Public and confidential client support: OAUTH2_CLIENT_ID only = public client (PKCE only), + OAUTH2_CLIENT_SECRET = confidential client (PKCE + client_secret_post) - RFC 7591 local client registration returning pre-registered credentials - RFC 9728 path-specific protected resource metadata - Dual auth: JWT verification via JWKS with selective fallback to legacy /me/ validation (claim/signature failures reject immediately, only structural failures fall back) - JWT audience validation (ansible-services) to prevent confused deputy attacks - Configurable redirect URI host allowlist (OAUTH2_ALLOWED_REDIRECT_HOSTS) - OIDC metadata origin validation and 10s discovery timeout - WWW-Authenticate headers on all 401 responses when OAuth2 is enabled - RFC 6750 scope parameter in WWW-Authenticate (read/write based on ALLOW_WRITE_OPERATIONS) - RFC 6750 error="invalid_token" for expired tokens to trigger refresh - Configurable rate limiting on OAuth2 endpoints (OAUTH2_RATE_LIMIT, default 100 req/min per IP) - X-Forwarded-For on OAuth2 proxy calls (/token, /revoke) via custom fetch and AsyncLocalStorage for audit traceability - Sanitized error logging to prevent log injection - Redirect URI rejection logging with allowed hosts for diagnostics New file: src/oauth2-provider.ts Modified: src/index.ts, package.json, package-lock.json Documentation: docs/oauth2-integration.md Issue: https://redhat.atlassian.net/browse/AAP-75808 Co-Authored-By: Claude Code <noreply@anthropic.com> Signed-off-by: Djebran Lezzoum <ldjebran@gmail.com>
4ca1975 to
378e86a
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.
Implement OAuth2 Integration
Enable opt-in OAuth2 authentication alongside the existing Bearer token
flow. When OAUTH2_CLIENT_ID and OAUTH2_CLIENT_SECRET are set, MCP
clients (Claude Code, Cursor, Gemini CLI) are automatically redirected
to the AAP authorization server's login page when no token is present.
Key features:
PKCE, token exchange, revocation)
New file: src/oauth2-provider.ts
Modified: src/index.ts, package.json
Documentation: docs/oauth2-integration.md
Issue: https://redhat.atlassian.net/browse/AAP-75808
Co-Authored-By: Claude Code noreply@anthropic.com
Note: this is a POC but very stable code and maybe considered as a basis for implementation.
for more details see document docs/oauth2-integration.md
Put it in draft as not intended to be merged for now