This repository has been archived by the owner on Sep 12, 2021. It is now read-only.
Normalize FORBIDDEN vs UNAUTHORIZED responses #35
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.
I believe in some situations the code is returning status code FORBIDDEN when it should be UNAUTHORIZED.
I'll review the code and propose a fix.
The name of these status codes can be misleading. UNAUTHORIZED is related to authentication and FORBIDDEN is related to authorization.
For reference reviewing this issue:
401 Unauthorized means "The request requires user authentication." The client MAY repeat the request with a suitable Authorization header field. It's a temporary condition.
403 Forbidden means "The server is refusing to fulfill the request." Authorization will not help and the request SHOULD NOT be repeated. It's a permanent condition.
In summary, a 401 Unauthorized response should be used for missing or bad authentication, and a 403 Forbidden response should be used afterwards, when the user is authenticated but isn’t authorized to perform the requested operation on the given resource.