Basic authentication
Basic authentication is the simplest way to secure your application. It involves sending a username and password with each request to the server. This is definitely not the most secure way to do it. If it’s not that secure, why would you use it? Well, there are scenarios where it’s better to have at least some security than no security at all. For example, if you have an API and it’s generally open to the public but you want to restrict access to certain endpoints, basic authentication can be a good option.
How does it work under the hood? The client sends an Authorization header with each request. The value of this header is the word Basic followed by a space and a Base64-encoded string of the format username:password. The server then decodes this string and checks whether the username and password are valid. Here’s the flow of how it works:

Figure 11.1 – Basic authentication flow
Sometimes the basic authentication...
 
                                             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
             
     
         
                 
                 
                 
                 
                 
                 
                 
                 
                