【发布时间】:2017-03-29 01:01:21
【问题描述】:
我正在使用在 github (https://github.com/GetBlimp/django-rest-framework-jwt/tree/master/) 上找到的 Django REST 框架 JSON Web 令牌 API。
我可以成功创建令牌并使用它们来调用受保护的 REST API。但是,在某些情况下,我想在特定令牌到期之前删除它。所以我想用这样的视图来做到这一点:
class Logout(APIView):
permission_classes = (IsAuthenticated, )
authentication_classes = (JSONWebTokenAuthentication, )
def post(self, request):
# simply delete the token to force a login
request.auth.delete() # This will not work
return Response(status=status.HTTP_200_OK)
request.auth 只是一个字符串对象。所以,这当然是行不通的,但我不确定如何清除底层令牌。
编辑
阅读更多相关信息,我似乎不需要做任何事情,因为 JWT 不会在服务器端存储任何内容。因此,只需关闭应用程序并在下次登录时重新生成令牌就足够了。对吗?
【问题讨论】: