Answer the question
In order to leave comments, you need to log in
What HTTP status to use?
We have some RESTful API.
The client is authenticated and receives a token.
Further, to access certain pages, the client must provide this token.
What HTTP status should the server return if the token is not passed?
- 400 Bad Request (because the token is a required parameter)
- 401 Unauthorized
- 403 Forbidden
What if the wrong token is passed?
UPD
...or did the session for the passed token expire?
UPD 2
According to " Web Server Header Based Decision Diagram " from wikipedia, what happens is:
Can the absence of a parameter be considered a "Bad Request"?
The request could not be understood by the server due to malformed syntax. The client SHOULD NOT repeat the request without modifications.
The server understood the request, but is refusing to fulfill it. Authorization will not help and the request SHOULD NOT be repeated.
Answer the question
In order to leave comments, you need to log in
403 for both situations, if there is a differentiation of rights, if just an identity check - 401
Is this fundamental or do you just want to do it as “correctly” as possible?)
I would choose 403 for both if not passed and for incorrect. If indeed the parameter is required at the API level, then 400 is possible for the missing one, but this is a moot point. And 401 is still conceived for another.
I would look at this from the point of view of a developer who connects to the API: in order to quickly and easily debug my error, the 401 Unauthorized status would help me the most.
For an auth request:
* 400 if no token was submitted at all
* 401 if invalid
For other pages:
* 403 if no token was submitted at all
* 403 if invalid
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question