@@ -439,6 +439,59 @@ public async Task CanAuthenticate_WhenFirstMetadataEndpointOmitsPkce_ButAnotherA
439439 transport , loggerFactory : LoggerFactory , cancellationToken : TestContext . Current . CancellationToken ) ;
440440 }
441441
442+ [ Fact ]
443+ public async Task CannotAuthenticate_WithClientMetadataDocument_WhenServerAdvertisesClientSecretBasicFirst ( )
444+ {
445+ // Mimic authorization servers (e.g. Auth0) that advertise client_secret_basic ahead of "none".
446+ // A CIMD client is a public client, but without an explicit TokenEndpointAuthMethod the client falls back to
447+ // the first advertised method (client_secret_basic) and authenticates with the client id and an empty secret
448+ // in the Authorization header rather than placing the client id in the body — which a public client cannot
449+ // satisfy, so the token exchange fails.
450+ TestOAuthServer . SupportedTokenEndpointAuthMethods = [ "client_secret_basic" , "client_secret_post" , "none" ] ;
451+
452+ await using var app = await StartMcpServerAsync ( ) ;
453+
454+ await using var transport = new HttpClientTransport ( new ( )
455+ {
456+ Endpoint = new ( McpServerUrl ) ,
457+ OAuth = new ClientOAuthOptions ( )
458+ {
459+ RedirectUri = new Uri ( "http://localhost:1179/callback" ) ,
460+ AuthorizationRedirectDelegate = HandleAuthorizationUrlAsync ,
461+ ClientMetadataDocumentUri = new Uri ( ClientMetadataDocumentUrl ) ,
462+ } ,
463+ } , HttpClient , LoggerFactory ) ;
464+
465+ await Assert . ThrowsAnyAsync < HttpRequestException > ( ( ) => McpClient . CreateAsync (
466+ transport , loggerFactory : LoggerFactory , cancellationToken : TestContext . Current . CancellationToken ) ) ;
467+ }
468+
469+ [ Fact ]
470+ public async Task CanAuthenticate_WithClientMetadataDocument_AndExplicitNoneAuthMethod ( )
471+ {
472+ // Same Auth0-like server that advertises client_secret_basic first, but the client explicitly declares the
473+ // public-client "none" method. The token request must then carry the client id in the body (no secret) and
474+ // succeed, proving ClientOAuthOptions.TokenEndpointAuthMethod overrides the server-advertised default.
475+ TestOAuthServer . SupportedTokenEndpointAuthMethods = [ "client_secret_basic" , "client_secret_post" , "none" ] ;
476+
477+ await using var app = await StartMcpServerAsync ( ) ;
478+
479+ await using var transport = new HttpClientTransport ( new ( )
480+ {
481+ Endpoint = new ( McpServerUrl ) ,
482+ OAuth = new ClientOAuthOptions ( )
483+ {
484+ RedirectUri = new Uri ( "http://localhost:1179/callback" ) ,
485+ AuthorizationRedirectDelegate = HandleAuthorizationUrlAsync ,
486+ ClientMetadataDocumentUri = new Uri ( ClientMetadataDocumentUrl ) ,
487+ TokenEndpointAuthMethod = "none" ,
488+ } ,
489+ } , HttpClient , LoggerFactory ) ;
490+
491+ await using var client = await McpClient . CreateAsync (
492+ transport , loggerFactory : LoggerFactory , cancellationToken : TestContext . Current . CancellationToken ) ;
493+ }
494+
442495 [ Fact ]
443496 public async Task UsesDynamicClientRegistration_WhenCimdNotSupported ( )
444497 {
0 commit comments