Created
September 7, 2012 16:22
-
-
Save tomchristie/3667533 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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