Man*_*tis 5 django django-rest-framework django-rest-framework-jwt
我正在尝试使用django rest_framework_jwt.我可以让它生成一个令牌,但当我尝试将其在标题中发送到受保护的视图时,我得到"未提供身份验证凭据".
我发送的标头的格式是:
"Authorization": "Token SomeRandomToken"
Run Code Online (Sandbox Code Playgroud)
settings.py
INSTALLED_APPS = [
...
rest_framework.authtoken
]
REST_FRAMEWORK = {
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework.authentication.TokenAuthentication',
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
'DEFAULT_PERMISSION_CLASSES': (
'rest_framework.permissions.IsAuthenticated',
),
}
Run Code Online (Sandbox Code Playgroud)
views.py
class UserList(mixins.ListModelMixin,
mixins.CreateModelMixin,
generics.GenericAPIView):
permission_classes = (permissions.IsAuthenticated,)
authentication_classes = (JSONWebTokenAuthentication,)
queryset = User.objects.all()
serializer_class = UserSerializer
Run Code Online (Sandbox Code Playgroud)
从看文档,我会说,你应该删除默认TokenAuthentication从
AUTHENTICATION_CLASSES
'DEFAULT_AUTHENTICATION_CLASSES': (
'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
),
Run Code Online (Sandbox Code Playgroud)
标题似乎有不同的格式:
现在,为了访问受保护的API,您必须包含
Authorization: JWT <your_token>标题.
| 归档时间: |
|
| 查看次数: |
2929 次 |
| 最近记录: |