@@ -24,7 +24,8 @@ public class McpAuthenticationOptions : AuthenticationSchemeOptions
2424 /// The URI to the resource metadata document.
2525 /// </summary>
2626 /// <remarks>
27- /// This URI will be included in the WWW-Authenticate header when a 401 response is returned.
27+ /// This URI will be included in the WWW-Authenticate header when a 401 response is returned
28+ /// and Bearer authentication is supported.
2829 /// </remarks>
2930 public Uri ResourceMetadataUri { get ; set ; } = DefaultResourceMetadataUri ;
3031
@@ -48,6 +49,26 @@ public class McpAuthenticationOptions : AuthenticationSchemeOptions
4849 /// </remarks>
4950 public Func < HttpContext , ProtectedResourceMetadata > ? ResourceMetadataProvider { get ; set ; }
5051
52+ /// <summary>
53+ /// Gets or sets the authentication schemes supported by this server.
54+ /// </summary>
55+ /// <remarks>
56+ /// When set, these schemes will be included in WWW-Authenticate headers during an authentication challenge.
57+ /// By default, this is empty and must be populated with the authentication schemes your server supports.
58+ /// If Bearer is included, the resource metadata URI will be included in its parameters.
59+ /// </remarks>
60+ public List < string > SupportedAuthenticationSchemes { get ; set ; } = new List < string > ( ) ;
61+
62+ /// <summary>
63+ /// Gets or sets a delegate that dynamically provides authentication schemes based on the HTTP context.
64+ /// </summary>
65+ /// <remarks>
66+ /// When set, this delegate will be called to determine which authentication schemes to include
67+ /// in WWW-Authenticate headers during an authentication challenge. This takes precedence over the static
68+ /// <see cref="SupportedAuthenticationSchemes"/> property.
69+ /// </remarks>
70+ public Func < HttpContext , IEnumerable < string > > ? SupportedAuthenticationSchemesProvider { get ; set ; }
71+
5172 /// <summary>
5273 /// Gets the resource metadata for the current request.
5374 /// </summary>
@@ -62,4 +83,19 @@ internal ProtectedResourceMetadata GetResourceMetadata(HttpContext context)
6283
6384 return ResourceMetadata ;
6485 }
86+
87+ /// <summary>
88+ /// Gets the supported authentication schemes for the current request.
89+ /// </summary>
90+ /// <param name="context">The HTTP context for the current request.</param>
91+ /// <returns>The authentication schemes supported for the current request.</returns>
92+ internal IEnumerable < string > GetSupportedAuthenticationSchemes ( HttpContext context )
93+ {
94+ if ( SupportedAuthenticationSchemesProvider != null )
95+ {
96+ return SupportedAuthenticationSchemesProvider ( context ) ;
97+ }
98+
99+ return SupportedAuthenticationSchemes ;
100+ }
65101}
0 commit comments