1

I am using token authentication for my current project but I have one problem, I can not authenticate a use for the life of me. To test my authentication I created a superuser and then the command python manage.py drf_create_token test1. And then created this view:

class HelloView(APIView):
    permission_classes = (IsAuthenticated)

    def get(self, request):
        content = {'message': 'Hello, World!'}
        return Response(content)

In my setting.py file I have:

INSTALLED_APPS = [
    ... # ...
    'rest_framework',
    'rest_framework.authtoken',
    'backend',
    'frontend'
]

REST_FRAMEWORK = {
    'DEFAULT_AUTHENTICATION_CLASSES': [
        'rest_framework.authentication.TokenAuthentication',
    ],
}

And when I test my API I keep geting:

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

What am I missing here? can anyone tell me? Thank you in advance.

1 Answer 1

2

If you use token authentication, then you must send token in all request to server in headers. So, you header request should contain the following entry:

enter image description here

Sign up to request clarification or add additional context in comments.

4 Comments

You make yourself very clear, one problem though see I am new to token authentication and do not know how to do this, if you could provide me a code sample i would be very thankful.
But if you don't have the time could you at least tell me where can I learn how to do this(resources for learning how to do this)
thank you very much for your time and effort, I finaly solved my problem

Your Answer

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.