What Is HTTP Basic Auth?
Anyone who wants to access sensitive information, data, or directories on the internet is usually asked by the server for authorization. To obtain it, the visitor is shown a dialog for entering a username and password. With this information, the server can ideally recognize the user and grant access. Several levels of security and authentication are available for this scenario.
In the early days of the internet, these authentication methods were fairly simple. One well-known and very basic method goes by the name HTTP Basic Auth. It prompts users to enter their credentials in a plain, predefined dialog. This dialog is not limited to browsers. Windows also displays it, for example, when a network resource is accessed. How does this simple login work in detail? The following sections explain it.
How Basic Auth Works
Although considerably more advanced methods such as OAuth 2.0 are now available for authenticating users, HTTP Basic Auth is still offered as a standard method. The way it works is simple and transparent. As soon as you enter a valid URL in the web browser and submit it, the server checks whether you as a user may access the requested URL. If the resource is protected, the server sends your browser a corresponding status code (401 when authorization is required) and requests authentication. The server response header then looks like the following example.
HTTP/1.1 401 Unauthorized
Date: Wed, 12 Dec 2018 12:16:21 GMT
WWW-Authenticate: Basic realm="User Profile Login"
Content-Length: 0
...In this server response, the key WWW-Authenticate followed by the parameter Basic requests the standard authentication method. The parameter realm= adds a short description to the error message. This value can be set freely and, in this example, describes the area in which the error occurred. Here, someone evidently tried to use a URL to go directly to an area protected by a user account.
The browser then either opens a predefined dialog for the username and password or uses credentials that are already stored in the browser. These are encoded and sent back to the server in a new header that requests authorization. The request header looks like the following example.
GET /securefiles/ HTTP/1.1
Host: www.dataliquid.com
Authorization: Basic TWFuZnJlZDpBMnA3IzU/MUgzMw==
...With this message, the browser sends the credentials back to the server. The parameter Authorization is given the value Basic for standard authorization. The value that follows, TWFuZnJlZDpBMnA3IzU/MUgzMw==, represents the credentials in Base64 encoding. “Manfred” is the username and “A2p7#5?1H33” is the password. With this information, the server can now log you in correctly and the browser can open the requested URL.
In addition to the Basic authentication scheme shown here, the server can offer the client further schemes.
- Anonymous contains no authentication information and therefore serves as a universal release for all requests.
- Basic was introduced in the example above as the standard authentication. It requires a combination of username and password.
- Digest replaces the Basic scheme with hash-based authentication that runs as a multistep exchange between client and server.
- NTLM is a more secure variant of Digest authentication and uses the Windows credentials to grant access.
- Negotiate selects either the NTLM scheme or the Kerberos protocol automatically, depending on availability.
Conclusion
Even though considerably more modern and more secure methods such as OAuth 2.0 or single sign-on are now used as the standard, HTTP Basic Auth remains available as a standard login method for simple use cases. Its advantages should not be underestimated. It offers standard security factors, fast response times, and low overhead. It is also implemented as a standard on nearly every server and client system. Using it in your own client and server environments is well documented and easy to implement.
Nevertheless, we generally recommend the newer methods OAuth 2.0 and Single Sign-On. With OAuth 2.0, the focus is on uncomplicated use for the users. They can log in to many platforms quickly and securely with an existing Google account and its credentials. The same applies to single sign-on. Users today no longer want to remember dozens of usernames and passwords to authorize themselves with web services and providers.