diff options
| author | Tom Christie | 2013-06-28 09:07:09 +0100 |
|---|---|---|
| committer | Tom Christie | 2013-06-28 09:07:09 +0100 |
| commit | 58d38d694eba94d4c6c20edcbefb5f4f91e6dd0f (patch) | |
| tree | ba72bed1f1f20bed9d023fb076e0adcf7e92abf1 /rest_framework/authentication.py | |
| parent | de00ec95c3007dd90b5b01f7486b430699ea63c1 (diff) | |
| parent | 1f6a59d76da286e7a89e8e41317beb16a4aab7c7 (diff) | |
| download | django-rest-framework-58d38d694eba94d4c6c20edcbefb5f4f91e6dd0f.tar.bz2 | |
Merge branch 'master' into writable-nested-modelserializer
Diffstat (limited to 'rest_framework/authentication.py')
| -rw-r--r-- | rest_framework/authentication.py | 14 |
1 files changed, 7 insertions, 7 deletions
diff --git a/rest_framework/authentication.py b/rest_framework/authentication.py index 9caca788..10298027 100644 --- a/rest_framework/authentication.py +++ b/rest_framework/authentication.py @@ -3,14 +3,13 @@ Provides various 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 +from rest_framework.compat import oauth2_provider, provider_now from rest_framework.authtoken.models import Token @@ -230,8 +229,9 @@ class OAuthAuthentication(BaseAuthentication): try: consumer_key = oauth_request.get_parameter('oauth_consumer_key') consumer = oauth_provider_store.get_consumer(request, oauth_request, consumer_key) - except oauth_provider.store.InvalidConsumerError as err: - raise exceptions.AuthenticationFailed(err) + except oauth_provider.store.InvalidConsumerError: + msg = 'Invalid consumer token: %s' % oauth_request.get_parameter('oauth_consumer_key') + raise exceptions.AuthenticationFailed(msg) if consumer.status != oauth_provider.consts.ACCEPTED: msg = 'Invalid consumer key status: %s' % consumer.get_status_display() @@ -319,9 +319,9 @@ class OAuth2Authentication(BaseAuthentication): 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()) + # provider_now switches to timezone aware datetime when + # the oauth2_provider version supports to it. + token = token.get(token=access_token, expires__gt=provider_now()) except oauth2_provider.models.AccessToken.DoesNotExist: raise exceptions.AuthenticationFailed('Invalid token') |
