Handling authentication
DRF provides authentication classes to identify the user performing the request. If authentication is successful, the framework sets the authenticated User
object in request.user
. If no user is authenticated, an instance of Django’s AnonymousUser
is set instead.
DRF provides the following authentication backends:
BasicAuthentication
: This is HTTP basic authentication. The user and password are sent by the client in theAuthorization
HTTP header, encoded with Base64. You can learn more about it at https://en.wikipedia.org/wiki/Basic_access_authentication.TokenAuthentication
: This is token-based authentication. AToken
model is used to store user tokens. Users include the token in theAuthorization
HTTP header for authentication.SessionAuthentication
: This uses Django’s session backend for authentication. This backend is useful for performing authenticated AJAX requests to the API from your website’s frontend...