简体   繁体   English

Django Rest Framework JWT“未提供身份验证凭据。”}

[英]Django Rest Framework JWT “Authentication credentials were not provided.”}

I am trying to write a simple API that uses JWT tokens to authenticate. 我正在尝试编写一个使用JWT令牌进行身份验证的简单API。

My settings.py : 我的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. 我已经在文档中使用url(r'^api-token-auth/', obtain_jwt_token)注册了JWT令牌提供程序,并且在调用此终结点时收到令牌。

However, when I then make a request against my APIView (which contains the header Authorization: JWT <my_token> I always receive the following error: 但是,当我随后针对我的APIView(包含标头Authorization: JWT <my_token>发出请求时,我总是收到以下错误:

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

What am I missing? 我想念什么? Thanks in advance! 提前致谢!

If you are using apache as web server then add the following in apache httpd.conf file: 如果您将apache用作Web服务器,请在apache httpd.conf文件中添加以下内容:

WSGIPassAuthorization On

This worked for me. 这对我有用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Django Rest Framework {“detail”:“未提供身份验证凭据。”} - Django Rest Framework {“detail”:“Authentication credentials were not provided.”} Django-rest-framework {“详细信息”:“未提供身份验证凭据。” } 使用 django-rest-knox - Django-rest-framework {“detail”: “Authentication credentials were not provided.” } using django-rest-knox 自定义Django休息框架身份验证响应{“详细信息”:“未提供身份验证凭据。”} - Customize Django rest framework authentication response {“detail”: “Authentication credentials were not provided.”} Django:“详细信息”:“未提供身份验证凭据。” - Django : “detail”: “Authentication credentials were not provided.” Django Rest 框架 - 未提供身份验证凭据 - Django Rest Framework - Authentication credentials were not provided "detail": "未提供身份验证凭据。" Django-rest-frameweork 和 React - "detail": "Authentication credentials were not provided." Django-rest-frameweork and React django rest API开发使用Swagger UI,有“详细信息”:“未提供身份验证凭据。” - django rest API development Using Swagger UI, got“detail”: “Authentication credentials were not provided.” Django OAuth 工具包 - 自省请求:“未提供身份验证凭据。” - Django OAuth Toolkit - Introspection Request: “Authentication credentials were not provided.” django rest 框架中未提供错误身份验证凭据 - getting error Authentication credentials were not provided in django rest framework Python 请求与 Django Rest 框架 - “详细信息”:“未提供身份验证凭据” - Python Requests with Django Rest Framework - 'detail': 'Authentication credentials were not provided'
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM