Please refer to the Django Doc: Having written an authentication server , this is probably what you need. It covers both uses of common logins and REST APIs, such as token authentication:
The authenticate method takes credentials as keyword arguments. Most of the time, it'll just look like this: class MyBackend(object): def authenticate(self, username=None, password=None):
Once you have written your own authentication server, you just need to change your own default backend in your settings.py as follows:
AUTHENTICATION_BACKENDS = ('project.path.to.MyBackend',)
Update
Instead of overriding the default authenticate behavior, you can simply include both Backend in your settings, for example:
AUTHENTICATION_BACKENDS = ('project.path.to.MyBackend', 'django.contrib.auth.backends.ModelBackend',)
The order of the backends matters, you can read the source code and better understand how authenticate works by default and all together ( Read here )
AFAIK is the preferred way to configure authenticate , because one day you can change your default backend to something like RemoteUserBackend or whatever (for example, from RestFramework), and so you can just put your logic (MyBackend) on order in your settings and no need to worry about code breaking.
Hope this helps.
source share