Skip to content

Add OAuth 2.1 support for MCP server#448

Open
kaospr wants to merge 1 commit intomainfrom
feature/oauth
Open

Add OAuth 2.1 support for MCP server#448
kaospr wants to merge 1 commit intomainfrom
feature/oauth

Conversation

@kaospr
Copy link
Collaborator

@kaospr kaospr commented Mar 6, 2026

Summary

  • Adds OAuth 2.1 authorization for MCP endpoints using Doorkeeper with PKCE (S256 only), authorization code flow, and hashed token storage
  • Implements RFC 7591 dynamic client registration at /oauth/register with IP-based rate limiting, redirect URI allowlisting (localhost + claude.ai), and input validation
  • Adds Rack middleware (McpOauthMiddleware) that authenticates MCP requests via Bearer tokens and passes signed user identity to MCP tools using MessageVerifier
  • Includes .well-known/oauth-protected-resource and .well-known/oauth-authorization-server metadata endpoints
  • Scheduled cleanup jobs for expired tokens (30+ days) and stale unused registrations (24h)
  • Rack::Attack rate limiting on the registration endpoint

Test plan

  • Dynamic registration controller tests (valid params, defaults, validation, IP rate limit, redirect URI restrictions)
  • Full PKCE authorization code flow integration test
  • Token validation tests (expired, revoked, wrong scope, forged headers)
  • Metadata endpoint tests
  • Cleanup job tests (expired tokens, stale applications, retention of active records)
  • Manual test: register client, complete OAuth flow, use MCP tools with token
  • Verify Rack::Attack rate limiting in development

🤖 Generated with Claude Code

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.

1 participant