mirror of
https://github.com/encode/django-rest-framework.git
synced 2025-08-02 11:30:12 +03:00
Merge aeaf3517d3
into c245fc6cde
This commit is contained in:
commit
41ca63ddab
|
@ -4,7 +4,7 @@ Provides various authentication policies.
|
|||
from __future__ import unicode_literals
|
||||
import base64
|
||||
|
||||
from django.contrib.auth import authenticate
|
||||
from django.contrib.auth import authenticate, backends as django_backends
|
||||
from django.core.exceptions import ImproperlyConfigured
|
||||
from rest_framework import exceptions, HTTP_HEADER_ENCODING
|
||||
from rest_framework.compat import CsrfViewMiddleware
|
||||
|
@ -346,3 +346,21 @@ class OAuth2Authentication(BaseAuthentication):
|
|||
Check details on the `OAuth2Authentication.authenticate` method
|
||||
"""
|
||||
return 'Bearer realm="%s"' % self.www_authenticate_realm
|
||||
|
||||
|
||||
class TokenBackend(django_backends.ModelBackend):
|
||||
"""A Django authentication backend for Tokens
|
||||
|
||||
Intend to be used listed at settings.AUTHENTICATION_BACKENDS
|
||||
"""
|
||||
def authenticate(self, token=None):
|
||||
authenticator = TokenAuthentication()
|
||||
user = None
|
||||
|
||||
if token:
|
||||
try:
|
||||
user, token_object = authenticator.authenticate_credentials(token)
|
||||
except exceptions.AuthenticationFailed:
|
||||
pass # return None
|
||||
|
||||
return user
|
||||
|
|
Loading…
Reference in New Issue
Block a user