2

With which HTTP status code should a REST API respond if the request is authenticated (according to The OAuth 2.0 Authorization Framework: Bearer Token Usage: Authorization Request Header Field) but the authenticated user is unauthorized to view the resource being requested?

For example, imagine I make a request to see a certain user's profile: GET /users/123. I authenticate successfully, but that user has blocked me. With which HTTP status code should the server respond?

Related:

4
  • 1
    greenbytes.de/tech/webdav/rfc7231.html#status.403 Commented Aug 26, 2016 at 5:34
  • 1
    Here's a useful guide for choosing an appropriate HTTP Status Code Commented Aug 26, 2016 at 8:32
  • Does my answer resolve your doubts? Commented Aug 30, 2016 at 14:36
  • Yes, thank you @Opal. :-) Commented Aug 30, 2016 at 20:05

1 Answer 1

3

The code you need is 403 Forbidden:

From wikipedia:

A 403 response generally indicates one of two conditions:

  • Authentication was provided, but the authenticated user is not permitted to perform the requested operation.
  • The operation is forbidden to all users. For example, requests for a directory listing return code 403 when directory listing has been disabled.
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.