Authentication mechanisms with Python
Most of the web services that we use today require some authentication mechanism in order to ensure that the user's credentials are valid to access it. In this section, we'll learn how to implement authentication in Python.
The HTTP protocol natively supports three authentication mechanisms:
- HTTP basic authentication: Base64 is based on the HTTP basic authentication mechanism to encode the user composed with a password using the format
user: password
. - HTTP digest authentication: This mechanism uses MD5 to encrypt the user, key, and realm hashes.
- HTTP bearer authentication: This mechanism uses an authentication based on
access_token
. One of the most popular protocols that uses this type of authentication is OAuth. In the following URL, we can find the different Python libraries supported by this protocol: https://oauth.net/code/python/
Python supports both mechanisms through the requests
module. However, the main...