Repository navigation
Description
Summary
When the embedded authorization server acts as an OAuth2 client to an
upstream IdP via DCR, the resulting client is always driven with
client_secret_post at the token endpoint, regardless of what the upstream's
Dynamic Client Registration response actually negotiated. Upstream
authorization servers that only accept client_secret_basic (e.g. Ory Hydra,
which defaults new DCR-registered confidential clients to
client_secret_basic) reject the code exchange with invalid_client, so the
upstream connection can never complete.
Where
pkg/auth/dcr/resolver.go:191-193 — dcr.Resolution already carries the
negotiated method:
// TokenEndpointAuthMethod is the authentication method negotiated at the
// token endpoint for this client.
TokenEndpointAuthMethod string...populated from the DCR response's token_endpoint_auth_method. But
pkg/authserver/upstream/oauth2.go:
CommonOAuthConfig(~line 96) has no field to carry an auth-method
override — onlyClientID/ClientSecret.newBaseOAuth2Provider(line ~311-320) hardcodes it:
Endpoint: oauth2.Endpoint{
AuthURL: config.AuthorizationEndpoint,
TokenURL: config.TokenEndpoint,
AuthStyle: oauth2.AuthStyleInParams, // Send client credentials in POST body
},So every upstream OAuth2 provider — DCR-registered or statically
configured — sends client_secret_post unconditionally at token exchange,
regardless of what dcr.Resolution.TokenEndpointAuthMethod says.
Why it happens
Nothing between dcr.ResolveCredentials and newBaseOAuth2Provider threads
TokenEndpointAuthMethod through. Even a caller that wanted to respect it
has no field on OAuth2Config/CommonOAuthConfig to set.
Impact
Any upstream whose authorization server negotiates (or defaults to)
client_secret_basic for a DCR-registered confidential client fails the
authorization_code exchange every time, with no workaround available to the
integrator — the auth method is a property of the upstream's registration
response, not something the embedded-authserver operator controls.
Confirmed against a real upstream: an Ory-Hydra-based authorization server
returns token_endpoint_auth_method: "client_secret_basic" from its DCR
/register endpoint. The subsequent code exchange still sends
client_secret_post and the upstream rejects it:
token request failed: invalid_client - Client authentication failed (e.g.,
unknown client, no client authentication included, or unsupported
authentication method). The OAuth 2.0 Client supports client authentication
method 'client_secret_basic', but method 'client_secret_post' was requested.
You must configure the OAuth 2.0 client's 'token_endpoint_auth_method' value
to accept 'client_secret_post'.
Statically configured upstreams are unaffected only by luck — this only
surfaces where the upstream AS is strict about the negotiated method.
Expected
CommonOAuthConfiggains aTokenEndpointAuthMethodfield (or
OAuth2Configdoes, since only OAuth2 upstreams reach
newBaseOAuth2Provider).newBaseOAuth2Providermaps it tooauth2.AuthStyle:
client_secret_basic→oauth2.AuthStyleInHeader,client_secret_post→
oauth2.AuthStyleInParams, unset → current default (or
oauth2.AuthStyleAutoDetect).- Callers that build an
OAuth2Configfrom adcr.Resolution(e.g. an
embedded-authserver's upstream-DCR-as-client wiring) copy
resolution.TokenEndpointAuthMethodthrough.
Reproduce
- Configure an OAuth2 upstream with
DCRConfigpointed at an authorization
server that returnstoken_endpoint_auth_method: "client_secret_basic"
from its registration endpoint (Ory Hydra does this by default for
confidential clients). - Complete the authorization redirect and let the embedded authserver
exchange the code. - Observe
invalid_client— the upstream expected Basic auth, the embedded
authserver sent the secret in the POST body.
Version
Observed via github.com/stacklok/toolhive v0.34.0. Confirmed unchanged on
main as of this report (pkg/authserver/upstream/oauth2.go:318).
Activity
Respect DCR-negotiated token endpoint auth method (#5866)