Allow setting token endpoint auth method on ClientOAuthOptions (#1612)#1615
Open
mikeholczer wants to merge 1 commit into
Open
Conversation
…contextprotocol#1612) Add ClientOAuthOptions.TokenEndpointAuthMethod to override the token_endpoint_auth_method otherwise inferred from DCR or the server's advertised methods. Needed for CIMD public clients that must use "none" even when the server advertises client_secret_basic first (e.g. Auth0). An explicit value now takes precedence over the DCR-returned method.
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.
Add ClientOAuthOptions.TokenEndpointAuthMethod to override the token_endpoint_auth_method otherwise inferred from DCR or the server's advertised methods. Needed for CIMD public clients that must use "none" even when the server advertises client_secret_basic first (e.g. Auth0). An explicit value now takes precedence over the DCR-returned method.
Motivation and Context
When a client does not explicitly configure a token endpoint authentication method,
ClientOAuthProviderinfers it — from the dynamic client registration (DCR) response when DCR is used, otherwise from the first entry in the authorization server'stoken_endpoint_auth_methods_supported.That inference is wrong for a public client identified by a Client ID Metadata Document (CIMD). Such a client has no secret and must authenticate with
"none"(relying on PKCE). But some authorization servers (e.g. Auth0) advertiseclient_secret_basicahead ofnone, so the client falls back toclient_secret_basic, sends the client id with an empty secret in theAuthorizationheader instead of placing the client id in the body, and the token exchange fails. This makes CIMD against such servers impossible today.There was previously no way for the caller to override this. This PR adds
ClientOAuthOptions.TokenEndpointAuthMethodso the method can be set explicitly, and makes an explicitly-configured value take precedence over the value returned by DCR.How Has This Been Tested?
Tested with our real application which uses CIMD and Auth0 as it's authorization server.
Added two integration tests in
AuthTestsexercising a CIMD client against a test OAuth server configured (Auth0-like) to advertiseclient_secret_basicahead ofnone:CannotAuthenticate_WithClientMetadataDocument_WhenServerAdvertisesClientSecretBasicFirst— confirms the failure when no explicit method is set.CanAuthenticate_WithClientMetadataDocument_AndExplicitNoneAuthMethod— confirms success whenTokenEndpointAuthMethod = "none"is set explicitly.The test OAuth server gained a configurable
SupportedTokenEndpointAuthMethodsproperty to mimic these servers. All 40OAuth.AuthTestspass locally on net8.0, net9.0, and net10.0.Breaking Changes
None. The new property is optional and defaults to
null, preserving the existing inference behavior. The DCR code path now uses??=so it only applies the registration-returned method when no explicit value was configured — unchanged for callers who don't set the new property.Types of changes
Checklist
modes)
Additional context
Fixes #1612.
The override is implemented in
PerformDynamicClientRegistrationAsyncby changing the assignment of the registration-returned method from=to??=, and by seeding_tokenEndpointAuthMethodfromoptions.TokenEndpointAuthMethodin the constructor. The new property's XML docs describe the inference fallback and call out the CIMD/public-client case explicitly.