Basic Authentication
Basic Authentication is a simple authentication scheme built into the HTTP protocol where a client sends encoded (base64) credentials (username and password) in the Authorization header of an HTTP request.
When accessing a secure web page, the browser sends a request with the header Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQ=
, where dXNlcm5hbWU6cGFzc3dvcmQ=
is the Base64 encoded string of username:password
.
This code creates a session to capture the request headers, prepares the request with Basic Authentication, and then sends the request. It prints out both the request headers and the response headers, as well as the response content.
This authentication system is also known as HTTP Authentication. HTTP provides a general framework for access control and authentication.
Deep Dive
The challenge and response flow works like this:
Usually a client will present a password prompt to the user and will then issue the request including the correct
Authorization
header.
Authentication Schemes
The general HTTP authentication framework is the base for a number of authentication schemes.
Basic
Uses base64-encoded credentials for simple username and password authentication.
Bearer
Uses bearer tokens, which are opaque tokens used to access OAuth 2.0-protected resources.
Digest
Uses hashed credentials for more secure authentication, supporting SHA-256 and MD5 hashing (MD5 is not recommended).
HOBA
Uses digital signatures to authenticate, ensuring that the request originates from a specific client.
Mutual
Involves both client and server authenticating each other to establish a trusted connection.
Negotiate/NTLM
Uses a negotiation mechanism to select the authentication protocol, often used in Windows environments.
VAPID
Authorizes push notifications by proving ownership of the server sending the notifications.
SCRAM
Enhances password-based authentication by using a challenge-response mechanism with salted passwords.
AWS4-HMAC-SHA256
A secure authentication method for AWS services, using keyed-hash message authentication with SHA-256.
The "Basic" authentication scheme offers very poor security, but is widely supported and easy to set up.
As the user ID and password are passed over the network as clear text (it is base64 encoded, but base64 is a reversible encoding), the basic authentication scheme is not secure. HTTPS/TLS should be used with basic authentication. Without these additional security enhancements, basic authentication should not be used to protect sensitive or valuable information.
Last updated