@@ -117,29 +117,36 @@ public async Task RunServerAsync(string[]? args = null, CancellationToken cancel
117117 RedirectUris = [ "http://localhost:1179/callback" ] ,
118118 } ;
119119
120- // OAuth 2.0 Authorization Server Metadata (RFC 8414)
121- app . MapGet ( "/.well-known/oauth-authorization-server" , ( ) =>
120+ // The MCP spec tells the client to use /.well-known/oauth-authorization-server but AddJwtBearer looks for
121+ // /.well-known/openid-configuration by default. To make things easier, we support both with the same response
122+ // which seems to be common. Ex. https://github.com/keycloak/keycloak/pull/29628
123+ string [ ] metadataEndpoints = [ "/.well-known/oauth-authorization-server" , "/.well-known/openid-configuration" ] ;
124+ foreach ( var metadataEndpoint in metadataEndpoints )
122125 {
123- var metadata = new OAuthServerMetadata
126+ // OAuth 2.0 Authorization Server Metadata (RFC 8414)
127+ app . MapGet ( metadataEndpoint , ( ) =>
124128 {
125- Issuer = _url ,
126- AuthorizationEndpoint = $ "{ _url } /authorize",
127- TokenEndpoint = $ "{ _url } /token",
128- JwksUri = $ "{ _url } /.well-known/jwks.json",
129- ResponseTypesSupported = [ "code" ] ,
130- SubjectTypesSupported = [ "public" ] ,
131- IdTokenSigningAlgValuesSupported = [ "RS256" ] ,
132- ScopesSupported = [ "openid" , "profile" , "email" , "mcp:tools" ] ,
133- TokenEndpointAuthMethodsSupported = [ "client_secret_post" ] ,
134- ClaimsSupported = [ "sub" , "iss" , "name" , "email" , "aud" ] ,
135- CodeChallengeMethodsSupported = [ "S256" ] ,
136- GrantTypesSupported = [ "authorization_code" , "refresh_token" ] ,
137- IntrospectionEndpoint = $ "{ _url } /introspect",
138- RegistrationEndpoint = $ "{ _url } /register"
139- } ;
140-
141- return Results . Ok ( metadata ) ;
142- } ) ;
129+ var metadata = new OAuthServerMetadata
130+ {
131+ Issuer = _url ,
132+ AuthorizationEndpoint = $ "{ _url } /authorize",
133+ TokenEndpoint = $ "{ _url } /token",
134+ JwksUri = $ "{ _url } /.well-known/jwks.json",
135+ ResponseTypesSupported = [ "code" ] ,
136+ SubjectTypesSupported = [ "public" ] ,
137+ IdTokenSigningAlgValuesSupported = [ "RS256" ] ,
138+ ScopesSupported = [ "openid" , "profile" , "email" , "mcp:tools" ] ,
139+ TokenEndpointAuthMethodsSupported = [ "client_secret_post" ] ,
140+ ClaimsSupported = [ "sub" , "iss" , "name" , "email" , "aud" ] ,
141+ CodeChallengeMethodsSupported = [ "S256" ] ,
142+ GrantTypesSupported = [ "authorization_code" , "refresh_token" ] ,
143+ IntrospectionEndpoint = $ "{ _url } /introspect",
144+ RegistrationEndpoint = $ "{ _url } /register"
145+ } ;
146+
147+ return Results . Ok ( metadata ) ;
148+ } ) ;
149+ }
143150
144151 // JWKS endpoint to expose the public key
145152 app . MapGet ( "/.well-known/jwks.json" , ( ) =>
0 commit comments