Python rest_framework.authentication.TokenAuthentication() Examples
The following are 4
code examples of rest_framework.authentication.TokenAuthentication().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
rest_framework.authentication
, or try the search function
.
Example #1
Source File: authentication.py From py2swagger with MIT License | 6 votes |
def get_authentication_introspectors(view): """ Get View Authentication Introspectors :param view: DjangoRestFramework View :return: list of authentication introspectors :rtype: list """ from rest_framework import authentication authenticators_map = { authentication.BasicAuthentication: BasicAuthenticationIntrospector, authentication.TokenAuthentication: TokenAuthenticationIntrospector, } authenticators = getattr(view, 'authentication_classes', []) introspectors = [] for authenticator in authenticators: introspectors.append( authenticators_map.get(authenticator, BaseAuthenticationIntrospector)(authenticator) ) return introspectors
Example #2
Source File: authentication.py From product-definition-center with MIT License | 6 votes |
def authenticate(self, request): auth_result = super(TokenAuthenticationWithChangeSet, self).authenticate(request) # NOTE(xchu): The `auth_result` can be `None` if uncorrect # authorization header is privided or nothing privided. if auth_result is None: return auth_result # NOTE(xchu): Update request.changeset.author if the author is None; # That's because if we use `TokenAuthentication`, # DRF do the TokenAuthentication after the request passed # `ChangesetMiddleware` and all other Django middlewares. # Which means that we will not have the user until `authenticate` # here. if hasattr(request, "changeset") and request.changeset.author is None: # the `auth_result` is `None` or a (user, token) tuple. request.changeset.author = auth_result[0] return auth_result
Example #3
Source File: views.py From django-rest-social-auth with MIT License | 5 votes |
def get_authenticators(self): try: from knox.auth import TokenAuthentication except ImportError: warnings.warn( 'django-rest-knox must be installed for Knox authentication', ImportWarning, ) raise return [TokenAuthentication()]
Example #4
Source File: authorized_application.py From kpi with GNU Affero General Public License v3.0 | 5 votes |
def authenticate_credentials(self, key): """ Mostly duplicated from TokenAuthentication, except that we return an AnonymousUser """ try: token = self.model.objects.get(key=key) except self.model.DoesNotExist: raise exceptions.AuthenticationFailed(_('Invalid token.')) return AnonymousUser(), token