github.com/dustinrc/deis@v1.10.1-0.20150917223407-0894a5fb979e/controller/api/authentication.py (about)

     1  from django.contrib.auth.models import AnonymousUser
     2  from rest_framework import authentication
     3  from rest_framework.authentication import TokenAuthentication
     4  
     5  
     6  class AnonymousAuthentication(authentication.BaseAuthentication):
     7  
     8      def authenticate(self, request):
     9          """
    10          Authenticate the request for anyone!
    11          """
    12          return AnonymousUser(), None
    13  
    14  
    15  class AnonymousOrAuthenticatedAuthentication(authentication.BaseAuthentication):
    16  
    17      def authenticate(self, request):
    18          """
    19          Authenticate the request for anyone or if a valid token is provided, a user.
    20          """
    21          try:
    22              return TokenAuthentication.authenticate(TokenAuthentication(), request)
    23          except:
    24              return AnonymousUser(), None