mirror of
https://github.com/encode/django-rest-framework.git
synced 2024-11-27 03:54:01 +03:00
Merge pull request #1455 from ericbuehl/master
don't implicitly import provider.oauth2
This commit is contained in:
commit
2090f452b2
|
@ -326,11 +326,11 @@ class OAuth2Authentication(BaseAuthentication):
|
||||||
"""
|
"""
|
||||||
|
|
||||||
try:
|
try:
|
||||||
token = oauth2_provider.models.AccessToken.objects.select_related('user')
|
token = oauth2_provider.oauth2.models.AccessToken.objects.select_related('user')
|
||||||
# provider_now switches to timezone aware datetime when
|
# provider_now switches to timezone aware datetime when
|
||||||
# the oauth2_provider version supports to it.
|
# the oauth2_provider version supports to it.
|
||||||
token = token.get(token=access_token, expires__gt=provider_now())
|
token = token.get(token=access_token, expires__gt=provider_now())
|
||||||
except oauth2_provider.models.AccessToken.DoesNotExist:
|
except oauth2_provider.oauth2.models.AccessToken.DoesNotExist:
|
||||||
raise exceptions.AuthenticationFailed('Invalid token')
|
raise exceptions.AuthenticationFailed('Invalid token')
|
||||||
|
|
||||||
user = token.user
|
user = token.user
|
||||||
|
|
|
@ -550,13 +550,10 @@ except (ImportError, ImproperlyConfigured):
|
||||||
|
|
||||||
# OAuth 2 support is optional
|
# OAuth 2 support is optional
|
||||||
try:
|
try:
|
||||||
import provider.oauth2 as oauth2_provider
|
import provider as oauth2_provider
|
||||||
from provider.oauth2 import models as oauth2_provider_models
|
|
||||||
from provider.oauth2 import forms as oauth2_provider_forms
|
|
||||||
from provider import scope as oauth2_provider_scope
|
from provider import scope as oauth2_provider_scope
|
||||||
from provider import constants as oauth2_constants
|
from provider import constants as oauth2_constants
|
||||||
from provider import __version__ as provider_version
|
if oauth2_provider.__version__ in ('0.2.3', '0.2.4'):
|
||||||
if provider_version in ('0.2.3', '0.2.4'):
|
|
||||||
# 0.2.3 and 0.2.4 are supported version that do not support
|
# 0.2.3 and 0.2.4 are supported version that do not support
|
||||||
# timezone aware datetimes
|
# timezone aware datetimes
|
||||||
import datetime
|
import datetime
|
||||||
|
@ -566,8 +563,6 @@ try:
|
||||||
from django.utils.timezone import now as provider_now
|
from django.utils.timezone import now as provider_now
|
||||||
except ImportError:
|
except ImportError:
|
||||||
oauth2_provider = None
|
oauth2_provider = None
|
||||||
oauth2_provider_models = None
|
|
||||||
oauth2_provider_forms = None
|
|
||||||
oauth2_provider_scope = None
|
oauth2_provider_scope = None
|
||||||
oauth2_constants = None
|
oauth2_constants = None
|
||||||
provider_now = None
|
provider_now = None
|
||||||
|
|
|
@ -19,7 +19,7 @@ from rest_framework.authentication import (
|
||||||
)
|
)
|
||||||
from rest_framework.authtoken.models import Token
|
from rest_framework.authtoken.models import Token
|
||||||
from rest_framework.compat import patterns, url, include
|
from rest_framework.compat import patterns, url, include
|
||||||
from rest_framework.compat import oauth2_provider, oauth2_provider_models, oauth2_provider_scope
|
from rest_framework.compat import oauth2_provider, oauth2_provider_scope
|
||||||
from rest_framework.compat import oauth, oauth_provider
|
from rest_framework.compat import oauth, oauth_provider
|
||||||
from rest_framework.test import APIRequestFactory, APIClient
|
from rest_framework.test import APIRequestFactory, APIClient
|
||||||
from rest_framework.views import APIView
|
from rest_framework.views import APIView
|
||||||
|
@ -488,7 +488,7 @@ class OAuth2Tests(TestCase):
|
||||||
self.ACCESS_TOKEN = "access_token"
|
self.ACCESS_TOKEN = "access_token"
|
||||||
self.REFRESH_TOKEN = "refresh_token"
|
self.REFRESH_TOKEN = "refresh_token"
|
||||||
|
|
||||||
self.oauth2_client = oauth2_provider_models.Client.objects.create(
|
self.oauth2_client = oauth2_provider.oauth2.models.Client.objects.create(
|
||||||
client_id=self.CLIENT_ID,
|
client_id=self.CLIENT_ID,
|
||||||
client_secret=self.CLIENT_SECRET,
|
client_secret=self.CLIENT_SECRET,
|
||||||
redirect_uri='',
|
redirect_uri='',
|
||||||
|
@ -497,12 +497,12 @@ class OAuth2Tests(TestCase):
|
||||||
user=None,
|
user=None,
|
||||||
)
|
)
|
||||||
|
|
||||||
self.access_token = oauth2_provider_models.AccessToken.objects.create(
|
self.access_token = oauth2_provider.oauth2.models.AccessToken.objects.create(
|
||||||
token=self.ACCESS_TOKEN,
|
token=self.ACCESS_TOKEN,
|
||||||
client=self.oauth2_client,
|
client=self.oauth2_client,
|
||||||
user=self.user,
|
user=self.user,
|
||||||
)
|
)
|
||||||
self.refresh_token = oauth2_provider_models.RefreshToken.objects.create(
|
self.refresh_token = oauth2_provider.oauth2.models.RefreshToken.objects.create(
|
||||||
user=self.user,
|
user=self.user,
|
||||||
access_token=self.access_token,
|
access_token=self.access_token,
|
||||||
client=self.oauth2_client
|
client=self.oauth2_client
|
||||||
|
|
Loading…
Reference in New Issue
Block a user