Skip to content

Upstream OAuth2 client hardcodes client_secret_post; ignores DCR-negotiated token_endpoint_auth_method #5865

Description

@tgrunnagle

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 — only ClientID / 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

  • CommonOAuthConfig gains a TokenEndpointAuthMethod field (or
    OAuth2Config does, since only OAuth2 upstreams reach
    newBaseOAuth2Provider).
  • newBaseOAuth2Provider maps it to oauth2.AuthStyle:
    client_secret_basic → oauth2.AuthStyleInHeader, client_secret_post →
    oauth2.AuthStyleInParams, unset → current default (or
    oauth2.AuthStyleAutoDetect).
  • Callers that build an OAuth2Config from a dcr.Resolution (e.g. an
    embedded-authserver's upstream-DCR-as-client wiring) copy
    resolution.TokenEndpointAuthMethod through.

Reproduce

  1. Configure an OAuth2 upstream with DCRConfig pointed at an authorization
    server that returns token_endpoint_auth_method: "client_secret_basic"
    from its registration endpoint (Ory Hydra does this by default for
    confidential clients).
  2. Complete the authorization redirect and let the embedded authserver
    exchange the code.
  3. 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

  1. added
    needs-triage
    on Jul 17, 2026
  2. added
    bug
    and removed
    needs-triage
    on Jul 17, 2026
  3. self-assigned this
    on Jul 17, 2026
  4. added a commit that references this issue on Jul 17, 2026
    52ecebc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions