Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Consider enhancing OAuth2Error with specific error codes #1240

Open
Yneth opened this issue May 27, 2023 · 4 comments
Open

Consider enhancing OAuth2Error with specific error codes #1240

Yneth opened this issue May 27, 2023 · 4 comments
Labels
type: enhancement A general enhancement

Comments

@Yneth
Copy link

Yneth commented May 27, 2023

Expected Behavior
I want to have the option to override OAuth2 Error codes that are thrown from the spring-authorization-server source code.

Current Behavior
I am not able to override default OAuth2 Error codes.

Context
In our project, we want to provide more meaningful error codes to clients, as sometimes the standard OAuth2 error codes are too vague, such as invalid_grant. In our client's code, we want to have specific error codes for each problem so that they can handle each case differently.

We can currently map error codes by parsing the error_description, but we want to avoid that.

It would be amazing if we had either more
(A) detailed error codes or
(B) an additional internal list of error codes that would allow for more precise usage.

I understand it could violate RFC but we are ok with that.

Example
Option A:
instead of just invalid_request say missing_client_id

Option B:
send both invalid_request and missing_client_id

@Yneth Yneth added the type: enhancement A general enhancement label May 27, 2023
@jgrandja
Copy link
Collaborator

@Yneth The Protocol Endpoints provide hooks into customizing the error response (including error code) by configuring a custom AuthenticationFailureHandler. For example, the Token Endpoint provides authorizationServerConfigurer.tokenEndpoint.errorResponseHandler() for customizing the OAuth2Error response.

FYI, we're also planning on writing a How-to guide in gh-541.

I'll close this as customizing the error response is available.

@jgrandja jgrandja self-assigned this May 30, 2023
@jgrandja jgrandja added status: invalid An issue that we don't feel is valid and removed type: enhancement A general enhancement labels May 30, 2023
@Yneth
Copy link
Author

Yneth commented May 30, 2023

I will try to explain my issue better as in my case using AuthenticationFailureHandler is not enough.
Let's consider the following lines of code:

in those two cases, it would be impossible to enrich the error code to something more granular, like invalid_client_id or invalid_redirect_uri.
as in AuthenticationFailureHandler we are dealing with OAuth2AuthenticationException that holds no additional info.

in this case, we could potentially parse the error description but it is not something we would like to do in our code base, as it will be unstable between releases.

@Yneth
Copy link
Author

Yneth commented May 30, 2023

@jgrandja

@jgrandja jgrandja changed the title customizable/granular OAuth2 error codes Consider enhancing OAuth2Error with specific error codes May 30, 2023
@jgrandja jgrandja added type: enhancement A general enhancement and removed status: invalid An issue that we don't feel is valid labels May 30, 2023
@jgrandja
Copy link
Collaborator

Thanks for the explanation @Yneth. I've re-opened the issue and we'll give it some further thought.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

2 participants