1

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

0

Know someone who can answer? Share a link to this question via email, Twitter, or Facebook.

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.