我正在尝试验证和解码simple-jwt-django-rest-framework token。我知道可以使用simple-jwt的verify api进行验证。但是我想在我的视图中解码和验证。下面是我正在尝试的当前代码:-
//in views.py
class home(APIView):
def post(self,request,*args,**kwargs):
print("request is ",request._request)
verify_token_response = token_verify(request._request)
print("status_code is ", verify_token_response.status_code)
if(verify_token_response.status_code == 200):
jwt_object = JWTAuthentication()
validated_token = jwt_object.get_validated_token(request._request)
user = jwt_object.get_user(validated_token)
print(user)
return Response({
'status':True,
'message':'home'
})
这段代码用于验证令牌,它能够正确地验证令牌,但当我尝试检索已验证的令牌和用户时,它会出现错误:
{
"detail": "Given token not valid for any token type",
"code": "token_not_valid",
"messages": [
{
"token_class": "AccessToken",
"token_type": "access",
"message": "Token is invalid or expired"
}
]
}