Skip to content

Customizable Exception for Invalid Client Registration ID in OAuth2AuthorizationRequestRedirectFilter #13793

Closed
@leewin12

Description

@leewin12

Thank you for your continuous efforts in maintaining and improving spring security.
I would like to discuss a potential enhancement that could benefit many users.

Expected Behavior

Allow users to receive a more descriptive custom error message or be redirected to a specific error URL when an invalid client registration is provided during the OIDC process.

Current Behavior

  1. A user enters the Client Registration ID and initiates the OIDC login process on our SPA page.
  2. The SPA frontend constructs an OIDC initiation URL as https://{domain}/oauth2/authorization/{ClientRegistrationId}.
  3. The user's browser redirects to the URL mentioned and reaches DefaultOAuth2AuthorizationRequestResolver via OAuth2AuthorizationRequestRedirectFilter.
  4. If the ClientRegistrationId is invalid, DefaultOAuth2AuthorizationRequestResolver throws either an IllegalArgumentException (5.7.x) or an InvalidClientRegistrationIdException (5.8.x).
  5. OAuth2AuthorizationRequestRedirectFilter interrupts the filter chain and returns HttpStatus.INTERNAL_SERVER_ERROR. (code)
  6. The user is redirected to https://{domain}/error, triggering a white-label page.

Context

  1. Pre-validating the ClientRegistrationId cannot prevent this situation.
  2. In step (5), because OAuth2AuthorizationRequestRedirectFilter interrupts the filter chain, any additional error-handling filters become ineffective.
  3. Overriding OAuth2AuthorizationRequestRedirectFilter offers no benefit due to the private accessor of unsuccessfulRedirectForAuthorization.
  4. To the best of my knowledge, checking the ClientRegistrationId is not part of the OIDC process, so the framework might allow individual applications to set their own policies on this matter.

Metadata

Metadata

Assignees

Labels

in: oauth2An issue in OAuth2 modules (oauth2-core, oauth2-client, oauth2-resource-server, oauth2-jose)status: duplicateA duplicate of another issuetype: enhancementA general enhancement

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions