Django Rest Framework JWT "Authentication credentials were not provided."}

Viewed 1021

I am trying to write a simple API that uses JWT tokens to authenticate.

My settings.py:

INSTALLED_APPS = [
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'rest_framework',
]
REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
        'rest_framework.permissions.IsAdminUser'
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
        'rest_framework.authentication.SessionAuthentication',
        'rest_framework.authentication.BasicAuthentication',
    ),
   'PAGE_SIZE': 10
}

And my View looks like this:

class ExampleView(APIView):
    permission_classes = (IsAuthenticated,)
    authentication_classes = (JSONWebTokenAuthentication,)

    def get(self, request, format=None):
        return JsonResponse({"username":str(request.user)})

Which really does nothing, but I don't even get there. I have registered the JWT Token provider as in the documentation with url(r'^api-token-auth/', obtain_jwt_token) and I receive a token when I call this endpoint.

However, when I then make a request against my APIView (which contains the header Authorization: JWT <my_token> I always receive the following error:

[Response]: 403 [Data]: {"detail":"Authentication credentials were not provided."}

What am I missing? Thanks in advance!

1 Answers
Related