Skip to content

client_secret_basic authentication failures should return challenge #18285

Description

@jgrandja

As per section 3.2.3.1. Error Response:

"invalid_client": Client authentication failed (e.g., unknown
client, no client authentication included, or unsupported
authentication method). The authorization server MAY return an
HTTP 401 (Unauthorized) status code to indicate which HTTP
authentication schemes are supported. If the client attempted
to authenticate via the "Authorization" request header field,
the authorization server MUST respond with an HTTP 401
(Unauthorized) status code and include the "WWW-Authenticate"
response header field matching the authentication scheme used
by the client.

We should respond with the required authentication scheme when a client fails authentication.

Activity

  1. self-assigned this
    on Oct 25, 2021
  2. changed the title [-]Respond with authentication scheme on failed client authentication[/-] [+]Respond with authentication scheme when client authentication fails[/+] on Oct 25, 2021
  3. octopusthu commented on Dec 9, 2021

    @octopusthu

    Hi @jgrandja , the latest version of OAuth 2.1 is draft-ietf-oauth-v2-1-04, so perhaps you could update the link address in the original post to this: 3.2.3.1. Error Response

  4. removed their assignment
    on Jan 20, 2022
  5. sgiannino commented on Mar 25, 2022

    @sgiannino
    Contributor

    Hi @jgrandja i can work on it, in which version is it planned? Thank you!

  6. jgrandja commented on Mar 29, 2022

    @jgrandja
    CollaboratorAuthor

    Thanks for your interest @Enkosz. This enhancement hasn't been planned for a specific release since it's lower priority.

    However, if you would like to work on it we can schedule it whenever it is done.

  7. symposion commented on Jan 13, 2025

    @symposion

    @jgrandja You've closed my ticket #1873 as a duplicate of this one, but this ticket is a low-priority enhancement. I'd like to argue that the current behaviour is a bug - since it's in direct violation of both the HTTP spec and the OAuth spec; and it's not entirely insignificant since it means that many http clients, including at least Apache Commons and the .NET default http client - will, with their default settings, fail to authenticate for a client_credentials grant using http basic. This is a very common use case with very common libraries and it's actually quite non-obvious what's wrong at first glance. After upgrading from the old @EnableAuthorizationServer implementation to the new Spring Authorization Server this caused several of our customers to experience outages of their live services due to the (spec-incompliant) change in behaviour.

    I'm happy to submit a PR - I believe the fix is fairly trivial - if you agree that this is reasonably important.

  8. jgrandja commented on Jan 14, 2025

    @jgrandja
    CollaboratorAuthor

    @symposion The WWW-Authenticate response header was never implemented when client basic authn was implemented so that's why this was labeled as an enhancement. However, after reviewing the spec, I agree this is a bug since this MUST be implemented. I've changed it to a bug and scheduled it for next release.

    Would you be able to submit a PR for this fix?

  9. symposion commented on Jan 15, 2025

    @symposion

    @jgrandja I'd be happy to have a stab at implementing this, it doesn't seem especially complicated. Before I do, I'd like to understand why this behaviour was changed from the original implementation in the old AuthorizationServerSecurityConfigurer. In that previous auth server implementation, the default behaviour was to use BasicAuthenticationEntryPoint with a default realm name of oauth2/client . It seems like when re-implementing a deliberate choice was made to use HttpStatusEntryPoint instead... was there a reason for that? Or did it just get lost in the move?

    Related: is there any reason why we can't assume that it's a valid default setup to always issue a challenge with the Basic scheme? The spec says that the server should respond with the same scheme as any specified in the Authorization header of the request, but AFAICT out of the box SAS doesn't support anything other than Basic for this type of authentication (obviously it support other modes of auth such as JWT or POST parameters but these don't use the Authorization header)

    Providing that this is configurable - and it should always be possible for users to supply their own AuthenticationEntryPoint - I think this seems like a reasonable default. If users extend the server to support other schemes for the Authorization header when authenticating clients, then obviously they'll have to customise the AuthenticationEntryPoint

  10. jgrandja commented on Jan 16, 2025

    @jgrandja
    CollaboratorAuthor

    @symposion

    I'd like to understand why this behaviour was changed from the original implementation in the old AuthorizationServerSecurityConfigurer

    Spring Authorization Server was a complete re-write and therefore you can't rely on the same behaviour as the legacy framework. As already mentioned, the WWW-Authenticate response header was not implemented when client_secret_basic was implemented.

    is there any reason why we can't assume that it's a valid default setup to always issue a challenge with the Basic scheme?

    To be clear, the WWW-Authenticate response header should only be returned when the client_secret_basic authentication method is used.

  11. 14 remaining items

  12. jgrandja commented on Jan 22, 2025

    @jgrandja
    CollaboratorAuthor

    @symposion

    Yes, this would fix the problem.

    Excellent. As far as 2. goes (no client auth) there might be some side effects with the new default but we'll work through it and figure it out.

    to provide a customisation hook for OAuth2ClientAuthenticationFilter so that the behaviour in onAuthenticationFailure can be controlled

    This is already possible. See Configuring Client Authentication and the clientAuthentication.errorResponseHandler(), which is an AuthenticationFailureHandler.

    I'm very happy to have a stab at implementing this if you agree.

    That would be great. Thanks.

  13. changed the title [-]Respond with authentication scheme when client authentication fails[/-] [+]client_secret_basic authentication failures should return challenge[/+] on Apr 18, 2025
  14. jgrandja commented on Apr 22, 2025

    @jgrandja
    CollaboratorAuthor

    Reverted via c624d0a908af0b2a9314021e1377332ed3370661

  15. added
    in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)
    on Dec 9, 2025
  16. jgrandja commented on Dec 9, 2025

    @jgrandja
    CollaboratorAuthor
  17. symposion commented on Jan 5, 2026

    @symposion

    Hey, just wondering, what happened here? Why did this fix get reverted? I might be missing something but none of the relevant tickets/commits seem to have much in the way of explanation of what happened here?

  18. jgrandja commented on Jan 5, 2026

    @jgrandja
    CollaboratorAuthor

    @symposion Please see this comment

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)type: bugA general bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions