Table of Contents
HTTP authentication lets a server challenge a client for credentials before serving a protected resource. A typical challenge uses a 401 Unauthorized response with a WWW-Authenticate header. The client can retry with credentials in an Authorization header.
Follow a typical challenge and response
- A client requests a protected resource.
- The origin server sends a
401challenge if it needs valid credentials. - The client selects a supported scheme and retries with credentials. Some clients send credentials on the first request.
- The server checks the credentials and the permissions for that resource. If it refuses access after authentication, it may return
403 Forbidden.
Compare Basic, Digest, and Bearer
- Basic: Uses a Base64-encoded username and password. Base64 is reversible. Use HTTPS to protect the credential in transit.
- Digest: Uses a server challenge and a computed response. The digest is a hash, and supported algorithms and clients vary.
- Bearer: Sends an access token. Protect it like a password because possession can grant access until the token expires or is revoked. OAuth can issue access tokens, while JWT is one possible token format.
Recognize a separate proxy challenge
A proxy can return 407 Proxy Authentication Required with Proxy-Authenticate. The client responds with Proxy-Authorization for that proxy. This exchange is separate from authentication with the origin server.
See RFC 9110 for the protocol and TipsMake’s guides to HTTP responses and API debugging for practical examples.
Reader Comments 0
Sign in with email or Google to join the discussion.