I am making django authentication function via rest framework. I made view.py, serizlizers.py and backends.py. And I setup settings.py to call my own authentication function. But something is wrong and I got the error message that means "detail" : "don't include authentication information".
I have no idea what is wrong of my function. Please give me an advice.
backends.py
class RemoshinUserAuthBackend(BaseAuthentication):
def authenticate(self, username=None, password=None):
try:
user = RemoshinUser.objects.get(username=username)
if not user.check_password(password):
return None
except RemoshinUser.DoesNotExist:
return None
return user
def get_user(self, user_id):
try:
return User.objects.get(pk=user_id)
except User.DoesNotExist:
return None
views.py
@method_decorator(csrf_exempt, name='dispatch')
class UserAuthenticationView(APIView):
authentication_classes = (RemoshinUserAuthBackend, BasicAuthentication)
permission_classes = (IsAuthenticated,)
serializer_class = RemoshinUserAuthInputSerializer
def get(self, request, format=None):
content = {
'user': request.user.username,
'auth': None,
}
return Response(content)
def post(self, request):
serializer = RemoshinUserAuthInputSerializer(data=request.data)
serializer.is_valid(raise_exception=True)
user = authenticate(**serializer.data)
if not user:
raise AuthenticationFailed()
return Response(serializer.data)
serializers.py
class RemoshinUserAuthInputSerializer(serializers.ModelSerializer):
class Meta:
model = RemoshinUser
fields = ('username', 'password')
asked Sep 7, 2017 at 0:20
Kazzz Studio
4591 gold badge7 silver badges19 bronze badges
lang-py