Skip to content

Add OAuth 2.0 support to HTTP MCP bridge (Claude Code http bridge support)#104

Merged
m1rl0k merged 7 commits intotestfrom
oauth-http-mcp-bridge
Dec 24, 2025
Merged

Add OAuth 2.0 support to HTTP MCP bridge (Claude Code http bridge support)#104
m1rl0k merged 7 commits intotestfrom
oauth-http-mcp-bridge

Conversation

@voarsh2
Copy link
Copy Markdown
Contributor

@voarsh2 voarsh2 commented Dec 23, 2025

Adds a lightweight OAuth 2.0 layer to the HTTP MCP bridge to support browser/Claude Code style “local” authorization flows.

Changes:

Introduced OAuth endpoints alongside /mcp: metadata (/.well-known/oauth-authorization-server), dynamic client registration (/oauth/register), authorization (/oauth/authorize), token exchange (/oauth/token), and a helper (/oauth/store-session).

Added oauthHandler module to generate codes/tokens, manage in-memory stores, and implement endpoint handlers.

Implemented RFC9728-style authorization server metadata and RFC7591-style dynamic client registration responses.

Added an HTML login page that can authenticate to the Context Engine backend via token or username/password and then issue an auth code.

Updated the HTTP server routing to dispatch OAuth paths and keep the existing MCP POST behavior for backward compatibility.

Technical Notes: Issuer is currently derived as http://127.0.0.1:${port}; tokens/codes are stored in-process with simple time-based expiry.

- Implement RFC9728 Protected Resource Metadata
- Implement RFC7591 Dynamic Client Registration
- Add authorize endpoint with auto-approve for existing sessions
- Add token endpoint for bearer token exchange
- Add HTML login page for web-based authentication
- Add oauthHandler module with OAuth utilities and handlers
- Support both token and username/password authentication
- Local-only OAuth (127.0.0.1), suitable for development bridge
@voarsh2
Copy link
Copy Markdown
Contributor Author

voarsh2 commented Dec 23, 2025

augment review

@augmentcode
Copy link
Copy Markdown

augmentcode Bot commented Dec 23, 2025

🤖 Augment PR Summary

Summary: Adds a lightweight, local-only OAuth 2.0 authorization-code flow to the HTTP MCP bridge to support browser/Claude Code style authorization before calling /mcp.

Changes:

  • Bumps the bridge package version to 0.0.10.
  • Extends the HTTP server router to handle OAuth endpoints alongside the existing MCP POST handler.
  • Adds an OAuth handler module with in-memory stores for dynamic clients, auth codes, and bearer tokens.
  • Implements authorization server metadata at /.well-known/oauth-authorization-server and dynamic client registration at /oauth/register.
  • Implements /oauth/authorize + /oauth/token for authorization-code exchange, plus /oauth/store-session to bridge the browser login step.
  • Serves an HTML login page that authenticates to the Context Engine backend and completes the redirect with an authorization code.
  • Binds the HTTP server to 127.0.0.1 to align with the intended local security model.

Technical Notes: Issuer is derived as http://127.0.0.1:${port}; codes/tokens are stored in-process with time-based expiry checks.

🤖 Was this summary useful? React with 👍 or 👎

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 4 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ctx-mcp-bridge/src/mcpServer.js
Comment thread ctx-mcp-bridge/src/oauthHandler.js Outdated
Comment thread ctx-mcp-bridge/src/oauthHandler.js
Comment thread ctx-mcp-bridge/src/oauthHandler.js
Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 3 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ctx-mcp-bridge/src/oauthHandler.js Outdated
Comment thread ctx-mcp-bridge/src/oauthHandler.js
Comment thread ctx-mcp-bridge/src/oauthHandler.js
- Bind HTTP server to 127.0.0.1 only instead of all interfaces
- Escape JSON in login page to prevent script tag break-out XSS
- Validate client_id and redirect_uri against registered clients before redirect
- Add origin check on /oauth/store-session endpoint for CSRF protection
- Use token_endpoint_auth_method "none" (no client_secret) for local bridge
@voarsh2
Copy link
Copy Markdown
Contributor Author

voarsh2 commented Dec 23, 2025

augment review

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ctx-mcp-bridge/src/oauthHandler.js
Comment thread ctx-mcp-bridge/src/oauthHandler.js
- Validate redirect_uri in /oauth/token matches authorize request
- Fix missing Content-Type headers in error responses
- Validate backend_url is a valid URL to prevent prototype pollution
@voarsh2
Copy link
Copy Markdown
Contributor Author

voarsh2 commented Dec 23, 2025

augment review

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ctx-mcp-bridge/src/mcpServer.js Outdated
Comment thread ctx-mcp-bridge/src/oauthHandler.js
- Accept /mcp and /mcp/ paths for backward compatibility with trailing slash clients
- Bind OAuth codes to client_id to prevent cross-client code redemption
- Validate client_id in /oauth/token matches authorize request
@voarsh2
Copy link
Copy Markdown
Contributor Author

voarsh2 commented Dec 23, 2025

augment review

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ctx-mcp-bridge/src/oauthHandler.js Outdated
Comment thread ctx-mcp-bridge/src/oauthHandler.js
- Require Origin/Referer header in /oauth/store-session (reject if missing)
- Validate response_type=code in /oauth/authorize endpoint
@voarsh2
Copy link
Copy Markdown
Contributor Author

voarsh2 commented Dec 23, 2025

Augment review

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 2 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

Comment thread ctx-mcp-bridge/src/oauthHandler.js
Comment thread ctx-mcp-bridge/src/oauthHandler.js
- Add cleanupExpiredTokens() called on token issuance to prevent unbounded growth
- Restrict backend_url to http/https schemes only (reject file:, data:, etc)
@voarsh2
Copy link
Copy Markdown
Contributor Author

voarsh2 commented Dec 23, 2025

augment review

Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. No suggestions at this time.

Comment augment review to trigger a new review at any time.

@voarsh2 voarsh2 marked this pull request as draft December 24, 2025 04:24
@voarsh2 voarsh2 marked this pull request as ready for review December 24, 2025 04:24
Copy link
Copy Markdown

@augmentcode augmentcode Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review completed. 1 suggestions posted.

Fix All in Augment

Comment augment review to trigger a new review at any time.

if (existingAuth && existingAuth.entry && existingAuth.entry.sessionId) {
// Auto-generate code and redirect
const code = generateCode();
pendingCodes.set(code, {
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pendingCodes entries only get removed on successful token exchange (or if the code is presented to /oauth/token after expiry), so unredeemed auth codes can accumulate in-memory indefinitely. Consider adding some periodic/age-based pruning for pendingCodes as well (similar risk applies to registeredClients).

Fix This in Augment

🤖 Was this useful? React with 👍 or 👎

@m1rl0k m1rl0k merged commit 680ed0c into test Dec 24, 2025
1 check passed
@voarsh2 voarsh2 deleted the oauth-http-mcp-bridge branch December 24, 2025 15:53
m1rl0k added a commit that referenced this pull request Mar 1, 2026
Add OAuth 2.0 support to HTTP MCP bridge (Claude Code http bridge support)
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