diff options
| author | Tom Christie | 2013-03-29 06:42:24 -0700 |
|---|---|---|
| committer | Tom Christie | 2013-03-29 06:42:24 -0700 |
| commit | a69262a1cd03667416d94080101f735039aa084f (patch) | |
| tree | 40e849db9b542fd6743437b323610819e43c7b2b /rest_framework/authentication.py | |
| parent | ff3ebd979dab9a358a4708ea1de0fd8ebf121157 (diff) | |
| parent | fa61b2b2f10bf07e3cb87ca947ce7f0ca51a2ede (diff) | |
| download | django-rest-framework-a69262a1cd03667416d94080101f735039aa084f.tar.bz2 | |
Merge pull request #767 from tomchristie/fix-oauth2-token-only
Fix OAuth 2 token only
Diffstat (limited to 'rest_framework/authentication.py')
| -rw-r--r-- | rest_framework/authentication.py | 26 |
1 files changed, 11 insertions, 15 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 8f4ec536..145d4295 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -2,14 +2,16 @@ Provides a set of pluggable authentication policies. """ from __future__ import unicode_literals +import base64 +from datetime import datetime + from django.contrib.auth import authenticate from django.core.exceptions import ImproperlyConfigured from rest_framework import exceptions, HTTP_HEADER_ENCODING from rest_framework.compat import CsrfViewMiddleware from rest_framework.compat import oauth, oauth_provider, oauth_provider_store -from rest_framework.compat import oauth2_provider, oauth2_provider_forms, oauth2_provider_backends +from rest_framework.compat import oauth2_provider, oauth2_provider_forms from rest_framework.authtoken.models import Token -import base64 def get_authorization_header(request): @@ -315,21 +317,15 @@ class OAuth2Authentication(BaseAuthentication): Authenticate the request, given the access token. """ - # Authenticate the client - oauth2_client_form = oauth2_provider_forms.ClientAuthForm(request.REQUEST) - if not oauth2_client_form.is_valid(): - raise exceptions.AuthenticationFailed('Client could not be validated') - client = oauth2_client_form.cleaned_data.get('client') - - # Retrieve the `OAuth2AccessToken` instance from the access_token - auth_backend = oauth2_provider_backends.AccessTokenBackend() - token = auth_backend.authenticate(access_token, client) - if token is None: + try: + token = oauth2_provider.models.AccessToken.objects.select_related('user') + # TODO: Change to timezone aware datetime when oauth2_provider add + # support to it. + token = token.get(token=access_token, expires__gt=datetime.now()) + except oauth2_provider.models.AccessToken.DoesNotExist: raise exceptions.AuthenticationFailed('Invalid token') - user = token.user - - if not user.is_active: + if not token.user.is_active: msg = 'User inactive or deleted: %s' % user.username raise exceptions.AuthenticationFailed(msg) |
