Skip to content

Commit

Permalink
Merge branch 'release/0.6.6'
Browse files Browse the repository at this point in the history
  • Loading branch information
pavlov99 committed Feb 17, 2015
2 parents 1a13ef4 + 173d7a9 commit d376193
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 1 deletion.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ register:
.PHONY: upload
# target: upload - Upload module on PyPi
upload:
@git push && git push --tags
@python setup.py sdist upload || echo 'Upload already'

.PHONY: test
Expand Down
2 changes: 1 addition & 1 deletion jsonapi/__init__.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
""" JSON:API realization."""
__version = (0, 6, 5)
__version = (0, 6, 6)

__version__ = version = '.'.join(map(str, __version))
__project__ = PROJECT = __name__
27 changes: 27 additions & 0 deletions jsonapi/auth.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import base64
from django.contrib.auth import authenticate
from django.core.exceptions import ObjectDoesNotExist, MultipleObjectsReturned

from .utils import Choices

Expand All @@ -23,11 +24,37 @@ def authenticate(cls, request):
return user


class DjangoToolkitOAuthAuthenticator(object):

""" Authentication for django-oauth-toolkit library.
NOTE: Authrntication requires django-oauth-toolkit to be installed.
Usage:
Use header "Authorization: Bearer <access_token>" with request.
"""

@classmethod
def authenticate(cls, request):
from oauth2_provider.models import AccessToken
if 'Authorization' in request.META:
auth = request.META['Authorization'].split()
if len(auth) == 2 and auth[0].lower() == "bearer":
token = auth[1].decode('utf8')
queryset = AccessToken.objects.filter(token=token)
try:
user = queryset.get().user
return user
except (ObjectDoesNotExist, MultipleObjectsReturned):
pass


class Authenticator(object):

AUTHENTICATORS = Choices(
(SessionAuthenticator, 'SESSION'),
(HTTPBasicAuthenticator, 'HTTP_BASIC'),
(DjangoToolkitOAuthAuthenticator, 'DJANGO_TOOLKIT_OAUTH'),
)

class Meta:
Expand Down

0 comments on commit d376193

Please sign in to comment.