Skip to the content.

HTTP Authentication

Flow

The challenge and response flow works like this:

  1. The server responds to a client with a 401 (Unauthorized) or 407 (Proxy Authentication Required) response status and provides information on how to authorize with a WWW-Authenticate or Proxy-Authenticate response header containing at least one challenge.
  2. A client that wants to authenticate itself with the server can then do so by including an Authorization or Proxy-Authorization request header with the credentials.
  3. Usually a client will present a password prompt to the user and will then issue the request including the correct Authorization or Proxy-Authorization header.

HTTP Authentication Sequence Diagram

Authentication schemes

Basic Authentication

Response header

WWW-Authenticate: Basic realm="<str>"

Request header

Authorization: Basic <base64-str>

Nginx Conf

location /status {
    auth_basic            "Access to the staging site";
    auth_basic_user_file  /etc/apache2/.htpasswd;
}

See RFC 7617 - The ‘Basic’ HTTP Authentication Scheme (2015.9).

Digest Authentication

Response header

WWW-Authenticate: Digest realm="<str>", nonce="<random-str>", algorithm="SHA512"

Request header

Authorization: Digest username="<username>" realm="<str>" algorithm="SHA512" nonce="<random-str>" response="<md-str>"

See RFC 7616 - HTTP Digest Access Authentication (2015.9).

References