Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

verity request with method from oauth2_provider #24

Merged
merged 1 commit into from
Feb 27, 2015
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 7 additions & 12 deletions jsonapi/auth.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import base64
from django.contrib.auth import authenticate
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned

from .utils import Choices

Expand Down Expand Up @@ -36,17 +35,13 @@ class DjangoToolkitOAuthAuthenticator(object):

@classmethod
def authenticate(cls, request):
from oauth2_provider.models import AccessToken
if 'HTTP_AUTHORIZATION' in request.META:
auth = request.META['HTTP_AUTHORIZATION'].split()
if len(auth) == 2 and auth[0].lower() == "bearer":
token = auth[1]
queryset = AccessToken.objects.filter(token=token)
try:
user = queryset.get().user
return user
except (ObjectDoesNotExist, MultipleObjectsReturned):
pass
from oauth2_provider.oauth2_backends import get_oauthlib_core
oauthlib_core = get_oauthlib_core()
valid, oauthlib_req = oauthlib_core.verify_request(request, scopes=[])
if valid:
return oauthlib_req.user
else:
return None


class Authenticator(object):
Expand Down