Skip to content

Authentication vs Authorization

Two words that sound alike and do different jobs. Getting them straight clarifies both your code and your status codes.

  • Authentication (authn)who are you? The client proves its identity with a credential: an API key, a session cookie, or a bearer token.
  • Authorization (authz)what are you allowed to do? Given a known identity, the server decides whether this caller may perform this action on this resource.

Authentication comes first; authorization builds on its result. A request can be authenticated (we know who you are) yet unauthorized (you still may not do that).

  • 401 Unauthorized — authentication failed or was missing. The client should supply or refresh credentials. Conventionally accompanied by a WWW-Authenticate header.
  • 403 Forbidden — authentication succeeded, but the caller lacks permission. Sending different credentials will not help.

Identity travels in the Authorization header:

GET /me HTTP/1.1
Authorization: Bearer eyJhbGciOiJI...
JavaScript
Which question does authorization answer?
A valid token is sent, but the user may not delete this resource. Which status?
A request arrives with no credentials at all. Which status?