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

Provide request to contrib.auth.authenticate in JSONWebTokenSerializer #388

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
6 changes: 5 additions & 1 deletion rest_framework_jwt/serializers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from calendar import timegm
from datetime import datetime, timedelta

import django
from django.contrib.auth import authenticate, get_user_model
from django.utils.translation import ugettext as _
from rest_framework import serializers
Expand Down Expand Up @@ -47,7 +48,10 @@ def validate(self, attrs):
}

if all(credentials.values()):
user = authenticate(**credentials)
if django.VERSION >= (1, 11):
user = authenticate(request=self.context.get('request'), **credentials)
else:
user = authenticate(**credentials)

if user:
if not user.is_active:
Expand Down