Skip to content

Instantly share code, notes, and snippets.

@tomchristie
Created September 7, 2012 16:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tomchristie/3667533 to your computer and use it in GitHub Desktop.
Save tomchristie/3667533 to your computer and use it in GitHub Desktop.
class TokenAuthentication(BaseAuthentication):
model = djangorestframework.tokenauth.models.Token
def authenticate(self, request):
key = request.META.get('HTTP_AUTHORIZATION', '').strip()
if not key:
return None
try:
token = self.model.objects.get(key=key)
except:
return None
if token.user.is_active and not token.revoked:
return (token.user, token)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment