Skip to content

Commit

Permalink
Merge pull request jpadilla#5 from bskim45/master
Browse files Browse the repository at this point in the history
Exempt Views from CSRF verification
  • Loading branch information
jpadilla committed Dec 28, 2015
2 parents 0096200 + c9e1698 commit 1802270
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions jwt_auth/mixins.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
from django.http import HttpResponse

import jwt
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt

from jwt_auth import settings, exceptions
from jwt_auth.utils import get_authorization_header
from jwt_auth.compat import json, smart_text, User
Expand All @@ -22,6 +25,7 @@ class JSONWebTokenAuthMixin(object):
"""
www_authenticate_realm = 'api'

@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
try:
request.user, request.token = self.authenticate(request)
Expand Down
6 changes: 6 additions & 0 deletions jwt_auth/views.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
from django.http import HttpResponse, HttpResponseBadRequest
from django.utils.decorators import method_decorator
from django.views.decorators.csrf import csrf_exempt
from django.views.generic import View
from django.core.serializers.json import DjangoJSONEncoder

Expand All @@ -11,6 +13,10 @@ class ObtainJSONWebToken(View):
error_response_dict = {'errors': ['Improperly formatted request']}
json_encoder_class = DjangoJSONEncoder

@method_decorator(csrf_exempt)
def dispatch(self, request, *args, **kwargs):
return super(ObtainJSONWebToken, self).dispatch(request, *args, **kwargs)

def post(self, request, *args, **kwargs):
try:
request_json = json.loads(smart_text(request.body))
Expand Down

0 comments on commit 1802270

Please sign in to comment.