diff --git a/rest_framework/authtoken/serializers.py b/rest_framework/authtoken/serializers.py index e5f46dd66..580ef57c5 100644 --- a/rest_framework/authtoken/serializers.py +++ b/rest_framework/authtoken/serializers.py @@ -16,19 +16,17 @@ class AuthTokenSerializer(serializers.Serializer): username = attrs.get('username') password = attrs.get('password') - if username and password: - user = authenticate(request=self.context.get('request'), - username=username, password=password) - # The authenticate call simply returns None for is_active=False - # users. (Assuming the default ModelBackend authentication - # backend.) - if not user: - msg = _('Unable to log in with provided credentials.') - raise serializers.ValidationError(msg, code='authorization') - else: - msg = _('Must include "username" and "password".') + user = authenticate(request=self.context.get('request'), + username=username, password=password) + + # The authenticate call simply returns None for is_active=False + # users. (Assuming the default ModelBackend authentication + # backend.) + if not user: + msg = _('Unable to log in with provided credentials.') raise serializers.ValidationError(msg, code='authorization') + attrs['user'] = user return attrs