HTTP Authentication
Flow
The challenge and response flow works like this:
- The server responds to a client with a
401
(Unauthorized) or407
(Proxy Authentication Required) response status and provides information on how to authorize with aWWW-Authenticate
orProxy-Authenticate
response header containing at least one challenge. - A client that wants to authenticate itself with the server can then do so
by including an
Authorization
orProxy-Authorization
request header with the credentials. - Usually a client will present a password prompt to the user
and will then issue the request
including the correct
Authorization
orProxy-Authorization
header.
Authentication schemes
-
Basic: base64-encoded credentials. See RFC 7617 - The ‘Basic’ HTTP Authentication Scheme (2015.9).
-
Digest: SHA-256 algorithm credentials. See RFC 7616 - HTTP Digest Access Authentication (2015.9).
-
Bearer (also called token): bearer tokens to access OAuth 2.0 (with bearer format JWT). See RFC 6750 - The OAuth 2.0 Authorization Framework: Bearer Token Usage and Swagger - Bearer Authentication.
-
HOBA See RFC 7486, Section 3, HTTP Origin-Bound Authentication, digital-signature-based
-
Mutual See RFC 8120
-
Negotiate / NTLM See RFC 4599
-
VAPID See RFC 8292
-
SCRAM See RFC 7804
-
AWS4-HMAC-SHA256 See AWS docs. This scheme is used for AWS3 server authentication.
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
- HTTP - MDN
- David Gourley & Brian Totty. HTTP: The Definitive Guide (2002) ISBN: 978-1-56592-509-0 (《HTTP权威指南》)
- RFC 7235 - Hypertext Transfer Protocol (HTTP/1.1): Authentication (2014) (Obsoleted by RFC 9110 - HTTP Semantics (2022.6))
- RFC 2617 - HTTP Authentication: Basic and Digest Access Authentication (1999) (Obsoleted by RFC 7616 - HTTP Digest Access Authentication (2015.9) and RFC 7617 - The ‘Basic’ HTTP Authentication Scheme (2015.9))
- RFC 7615 - HTTP Authentication-Info and Proxy-Authentication-Info Response Header Fields (2015) (Obsoleted by RFC 9110 - HTTP Semantics (2022.6))
- RFC 7616 - HTTP Digest Access Authentication (2015.9)
- RFC 7617 - The ‘Basic’ HTTP Authentication Scheme (2015.9)
- RFC 2616 - Hypertext Transfer Protocol – HTTP/1.1 (1999) (Obsoleted by RFC 9112 - HTTP/1.1 (2022.6))
- RFC 2068 - Hypertext Transfer Protocol – HTTP/1.1 (1997.1) (Obsoleted by RFC 9112 - HTTP/1.1 (2022.6))
- RFC 9110 - HTTP Semantics (2022.6)
- RFC 9112 - HTTP/1.1 (2022.6)
- HTTP - Hypertext Transfer Protocol - W3C
- Swagger Bearer Authentication