在 Django simple-jwt 令牌身份验证中获取后端中的当前刷新令牌

Posted

技术标签:

【中文标题】在 Django simple-jwt 令牌身份验证中获取后端中的当前刷新令牌【英文标题】:Get the current refresh token in backend in Django simple-jwt token authentication 【发布时间】:2020-09-26 23:16:19 【问题描述】:

我想在后端接收刷新令牌以将令牌列入黑名单。

当用户传递它以调用 API 时,我在 request.header 中获取访问令牌,有没有办法在用户未传入标头时获取刷新令牌。

【问题讨论】:

【参考方案1】:

可以在views.py中这样使用RefreshToken:

from rest_framework_simplejwt.tokens import RefreshToken

def my_request(request):
   token = RefreshToken.for_user([INSERT HERE THE USER CLASS])
   #You can now use the refresh token
   return Response(status=status.HTTP_200_OK)

【讨论】:

以上是关于在 Django simple-jwt 令牌身份验证中获取后端中的当前刷新令牌的主要内容,如果未能解决你的问题,请参考以下文章