2
votes

I am beginner in Django and I am learning about JWT token from here.

https://jpadilla.github.io/django-rest-framework-jwt/#rest-framework-jwt-auth

I have already set up in my settings.py.

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES':
    (
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),

    'DEFAULT_MODEL_SERIALIZER_CLASS':
        'rest_framework.serializers.ModelSerializer',

    'DEFAULT_PERMISSION_CLASSES':
    (
        'rest_framework.permissions.IsAuthenticated',
    )
}

If I do curl, I actually get back my token.

curl -X POST -d "username=khant&password=khant" http://127.0.0.1:8000/api-token-auth/

But when I access my protected url,

curl -H "Authorization: JWT eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1c2VybmFtZSI6ImtoYW50IiwidXNlcl9pZCI6OCwiZW1haWwiOiJraGFudEBnbWFpbC5jb20iLCJleHAiOjE0NzQ5MDQxNTJ9.jaZ3HwsXjx7Bk2ol5UdeE8UUlq4OEGCbnb1T8vDhO_w" http://127.0.0.1:8000/dialogue_dialoguemine/

It always say this when I access from web. Localhost is okay for me.

{"detail":"Authentication credentials were not provided."}

In my protected url, I just write simple api to query. May I know how to solve this?

class DialogueMineView(generics.ListAPIView):
    permission_classes = (IsAuthenticated,)

    serializer_class = DialogueSerializer
    paginate_by = 2

    def get_queryset(self):

        user = self.request.user
        return Dialogue.objects.filter(owner=user)
1
You did everything right, please check again you input or code in curl.Windsooon
I am still stuck. how should I troubleshoot ?Khant Thu Linn

1 Answers

0
votes

I know now. For my case, I am not okay only on web. I check from this link.

Django Rest Framework - Authentication credentials were not provided

It say I need to add

WSGIPassAuthorization On

in my httpd.conf in apache directory. It is okay now.