Skip to content

Commit

Permalink
Merge pull request #24 from 7kfpun/master
Browse files Browse the repository at this point in the history
verity request with method from oauth2_provider
  • Loading branch information
pavlov99 committed Feb 27, 2015
2 parents 6bf2b85 + 3e69692 commit 2eb9678
Showing 1 changed file with 7 additions and 12 deletions.
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

0 comments on commit 2eb9678

Please sign in to comment.