-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Invalid_request failures in JwtTokenValidators are always turned into invalid_token errors #10337
Comments
Hi, @jason076, thanks for the report.
Why would you want the error to change? The errors are defined as follows (emphasis mine):
So I'm not sure why you'd want to return an
The above says that I believe you can customize the behavior in your own Have I misunderstood your use case? |
Sorry, I had a Mistake in the expected behavior section. ** Expected behavior ** ** Background ** In our project I wondered why the server is returning 401 despite this bug. I expected that if a Line 101 in 8c74d6c
the INVALID_REQUEST is turned into an INVALID_TOKEN effectively changing the status from 400 to 401.
|
So in short the current code does the following |
Ah, gotcha, @jason076. Thanks for clarifying. It seems to me that if the validator determines the token to be invalid, an Taking a look at Can you submit a PR to correct |
If you would like us to look at this issue, please provide the requested information. If the information is not provided within the next 7 days this issue will be closed. |
Closing due to lack of requested feedback. If you would like us to look at this issue, please provide the requested information and we will re-open the issue. |
Sorry for the late Feedback. I will submit a PR in the next days. |
I have submitted the PR #10500 |
Previously JwtClaimValidator returned the invalid_request error on claim validation failure. But validators have to return invalid_token errors on failure according to: https://datatracker.ietf.org/doc/html/rfc6750#section-3.1. Also see gh-10337 Closes gh-10337
Previously JwtClaimValidator returned the invalid_request error on claim validation failure. But validators have to return invalid_token errors on failure according to: https://datatracker.ietf.org/doc/html/rfc6750#section-3.1. Also see gh-10337 Closes gh-10337
Previously JwtClaimValidator returned the invalid_request error on claim validation failure. But validators have to return invalid_token errors on failure according to: https://datatracker.ietf.org/doc/html/rfc6750#section-3.1. Also see gh-10337 Closes gh-10337
Previously JwtClaimValidator returned the invalid_request error on claim validation failure. But validators have to return invalid_token errors on failure according to: https://datatracker.ietf.org/doc/html/rfc6750#section-3.1. Also see gh-10337 Closes gh-10337
Previously JwtClaimValidator returned the invalid_request error on claim validation failure. But validators have to return invalid_token errors on failure according to: https://datatracker.ietf.org/doc/html/rfc6750#section-3.1. Also see gh-10337 Closes gh-10337
Previously JwtClaimValidator returned the invalid_request error on claim validation failure. But validators have to return invalid_token errors on failure according to: https://datatracker.ietf.org/doc/html/rfc6750#section-3.1. Closes gh-10337
Describe the bug
Returning any failure in a
OAuth2TokenValidator
validate
function always results in aInvalidBearerTokenException
with the error codeBearerTokenErrorCodes.INVALID_TOKEN
and returns a 401. The Error handling does not respect the Error code the validate function returns. This leads toOAuth2ErrorCodes.INVALID_REQUEST
get converted toBearerTokenErrorCodes.INVALID_TOKEN
.To Reproduce
Return
OAuth2ErrorCodes.INVALID_REQUEST
inOAuth2TokenValidator
validate
. This was already the case in an bug I reported earlier: #10319Expected behavior
If I return
OAuth2ErrorCodes.INVALID_REQUEST
failure fromOAuth2TokenValidator
validate
I expect anOAuth2AuthenticationException
with theBeareErrorCode
BearerTokenErrorCodes.INVALID_REQUEST
and the status code 400.Sample
The problematic line in the sourcode is the following
spring-security/oauth2/oauth2-resource-server/src/main/java/org/springframework/security/oauth2/server/resource/authentication/JwtAuthenticationProvider.java
Line 101 in 8c74d6c
Each
BadJwtException
is converted toInvalidBearerTokenException
with the error codeBearerTokenErrorCodes.INVALID_TOKEN
The text was updated successfully, but these errors were encountered: