[McpBundle] Add OAuth 2.1 authorization server support#2135
Draft
wachterjohannes wants to merge 1 commit into
Draft
[McpBundle] Add OAuth 2.1 authorization server support#2135wachterjohannes wants to merge 1 commit into
wachterjohannes wants to merge 1 commit into
Conversation
Lets a Symfony MCP server become its own OAuth 2.1 authorization server via config, using the authorization-server primitives from mcp/sdk. Symmetric with how the bundle already wraps the transport: it issues and validates its own RS256 JWT access tokens, registers clients (RFC 7591), and serves the discovery documents MCP clients need (RFC 8414/9728 + JWKS) — no external IdP. - New `oauth` config section (canBeEnabled) and `McpBundle::configureOAuth()` wiring the SDK engine, Cache-based storage (Psr16Cache over a cache pool, reusing the session-store pattern), token issuer/validator, DCR registrar, and discovery metadata. - Batteries-included defaults: SecurityResourceOwnerResolver (firewall user becomes the OAuth subject), AutoApproveConsent, and an AccessTokenAuthenticator for the firewall — all overridable via config. - Consolidated OAuthController (authorize/token/register/well-known/jwks) bridged Symfony <-> PSR-7; routes emitted by RouteLoader. Requires mcp/sdk ^0.6, which also updates Profiler\TraceableRegistry for the revised RegistryInterface. firebase/php-jwt, symfony/cache and symfony/security-bundle are needed only when OAuth is enabled (suggest). Docs and DI tests included.
This was referenced Jun 2, 2026
Contributor
|
Very nice! Would it be reasonable to use the same jwt library Symfony Security is already using? https://github.com/symfony/symfony/blob/8.2/src/Symfony/Component/Security/Http/composer.json#L39 |
Contributor
Author
|
@valtzu would make sense! i will evaluate that afer my vacation 🌴 |
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.
Refs #2134
Depends on modelcontextprotocol/php-sdk#373 (mcp/sdk ^0.6)
Summary
Lets a Symfony MCP server become its own OAuth 2.1 authorization server via config, using the authorization-server primitives from
mcp/sdk. It issues and validates its own RS256 JWT access tokens, registers clients (RFC 7591), and serves the discovery documents MCP clients need (RFC 8414/9728 + JWKS) — no external IdP, no third-party OAuth server.Usage
Registers
/.well-known/oauth-authorization-server,/.well-known/oauth-protected-resource,/.well-known/jwks.json,/oauth/authorize,/oauth/token,/oauth/register.What's in it
oauthconfig section (canBeEnabled) +McpBundle::configureOAuth()wiring the SDK engine, Cache-based storage (Psr16Cacheover a cache pool — reusing the session-store pattern), token issuer/validator, DCR registrar, and discovery metadata.SecurityResourceOwnerResolver(the authenticated firewall user becomes the OAuth subject),AutoApproveConsent, andAccessTokenAuthenticator.OAuthController(authorize/token/register/well-known/jwks) bridged Symfony ↔ PSR-7; routes emitted byRouteLoader.Notes
mcp/sdkto^0.6(the version with the AS primitives); this also updatesProfiler\TraceableRegistryfor the revisedRegistryInterface. CI will fail untilmcp/sdk 0.6is released — hence draft.firebase/php-jwt,symfony/cache,symfony/security-bundleare only needed when OAuth is enabled (declared viasuggest).league/oauth2-serverin favour of this (container compiles, all OAuth routes resolve, full DCR→authorize→token→bearer flow).