Building a custom authentication backend
Django allows you to authenticate against different sources. The AUTHENTICATION_BACKENDS
setting includes the list of authentication backends for your project. By default, this setting is set as follows:
['django.contrib.auth.backends.ModelBackend']
The default ModelBackend
authenticates users against the database using the user model of django.contrib.auth
. This will suit most of your projects. However, you can create custom backends to authenticate your user against other sources, such as a Lightweight Directory Access Protocol (LDAP) directory or any other system.
You can read more information about customizing authentication at https://docs.djangoproject.com/en/3.0/topics/auth/customizing/#other-authentication-sources.
Whenever you use the authenticate()
function of django.contrib.auth
, Django tries to authenticate the user against each of the backends defined in AUTHENTICATION_BACKENDS
one by one...