Skip to content
This repository has been archived by the owner on May 26, 2020. It is now read-only.

Fixes #290 -- Pass request object on authenticate() #395

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
10 changes: 9 additions & 1 deletion rest_framework_jwt/compat.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from django.contrib.auth import get_user_model
import django
from django.contrib.auth import authenticate as dj_authenticate, get_user_model

from rest_framework import serializers

Expand Down Expand Up @@ -35,3 +36,10 @@ def get_username(user):
username = user.username

return username


def authenticate(request=None, **credentials):
if django.VERSION < (1, 11):
return dj_authenticate(**credentials)
else:
return dj_authenticate(request=request, **credentials)
7 changes: 4 additions & 3 deletions rest_framework_jwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@
from calendar import timegm
from datetime import datetime, timedelta

from django.contrib.auth import authenticate, get_user_model
from django.contrib.auth import get_user_model
from django.utils.translation import ugettext as _
from rest_framework import serializers
from .compat import Serializer
from .compat import Serializer, authenticate

from rest_framework_jwt.settings import api_settings
from rest_framework_jwt.compat import get_username_field, PasswordField
Expand Down Expand Up @@ -47,7 +47,8 @@ def validate(self, attrs):
}

if all(credentials.values()):
user = authenticate(**credentials)
request = self.context.get('request')
user = authenticate(request=request, **credentials)

if user:
if not user.is_active:
Expand Down