【发布时间】:2020-11-17 14:59:45
【问题描述】:
理想情况下使用django-rest-framework-simplejwt 和身份验证类JWTAuthentication,当我错误地传递令牌时,API 应该提供403。
相反,当我发出 API 请求时,即使没有身份验证令牌,它也会成功执行。
这是一个虚拟 API,我关心的是身份验证应该起作用。
我的代码如下所示:
class ViewSet(viewsets.ModelViewSet):
queryset = get_user_model().objects.all()
serializer_class = SomeSerializer
http_method_names = ("post", "patch")
authentication_classes = (JWTAuthentication,)
当我调试时,我看到它正在执行 JWTAuthentication,它又返回 None。 这是预期的,因为我没有在标头中传递令牌。
def authenticate(self, request):
header = self.get_header(request)
if header is None:
return None
现在我认为 View 应该给予 Permission Denied,这并没有发生。
无法理解这里缺少什么。
【问题讨论】:
标签: django django-rest-framework django-rest-framework-simplejwt