Add WWW-Authenticate header for 401 and 403 requests#51
Merged
lbalmaceda merged 3 commits intoauth0:masterfrom Jun 9, 2020
Merged
Add WWW-Authenticate header for 401 and 403 requests#51lbalmaceda merged 3 commits intoauth0:masterfrom
lbalmaceda merged 3 commits intoauth0:masterfrom
Conversation
jimmyjames
commented
Jun 5, 2020
| class JwtAccessDeniedHandler extends AccessDeniedHandlerImpl { | ||
|
|
||
| @Override | ||
| public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException { |
Contributor
Author
There was a problem hiding this comment.
AccessDeniedHandler specifies that handle must be public, which is why the class as package-private but the method as public
Contributor
Author
|
Codecov checks failing because of the lack of coverage around the |
lbalmaceda
suggested changes
Jun 9, 2020
lib/src/test/java/com/auth0/spring/security/api/JwtAccessDeniedHandlerTest.java
Outdated
Show resolved
Hide resolved
dde3fd2 to
388a48d
Compare
lbalmaceda
approved these changes
Jun 9, 2020
This was referenced Jun 17, 2020
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Changes
As raised in #47, the
WWW-Authenticateheaders should be sent on the response when the request is rejected due to a missing or invalid access token. This is specified by RFC 6750.Scenarios
401due to an invalid or missing access token will have aWWW-Authenticateheader included on the response.403due to insufficient scopes will have aWWW-Authenticateheader included on the response.WWW-Authenticate header value
RFC 6750 does not require any specific attributes of the
WWW-Authenticateheader to be set. This PR simply includes anerrorattribute, with the following values:401resulting from a missing or invalid access token403resulting from a token with insufficient scopesA couple notes on what could be added in the future, but is not included here as this change is focused on complying with RFC 6750 and enables future changes to the header attributes:
401errors, we could unwrap theAuthenticationExceptionand use the underlying exception cause to return a more specificerror(e.g., invalid signature, expired token, etc).403errors, we might be able to included the required scopes for the resource, as was added to express-jwt-authz. That would require some more thought, since we'd need to be able to hook into the required scopes as configured by the application developer.realmorauthorization_uri, if those prove to be useful for callers.Again, those possible additions are not included in this PR for the purposes of simplicity and compliance, but we can consider them going forward.
References
Testing
Please describe how this can be tested by reviewers. Be specific about anything not tested and reasons why. If this library has unit and/or integration testing, tests should be added for new functionality and existing tests should complete without errors.
Checklist