diff --git a/rest_framework_jwt/compat.py b/rest_framework_jwt/compat.py index 93e7898d..b69375c8 100644 --- a/rest_framework_jwt/compat.py +++ b/rest_framework_jwt/compat.py @@ -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 @@ -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) diff --git a/rest_framework_jwt/serializers.py b/rest_framework_jwt/serializers.py index 12b10a44..f6c0703d 100644 --- a/rest_framework_jwt/serializers.py +++ b/rest_framework_jwt/serializers.py @@ -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 @@ -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: