我正在尝试验证和解码 simple-jwt-django-rest-framework 令牌。我知道我们可以使用 simple-jwt 的验证 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'
})
此代码适用于我的令牌验证。它正在正确验证令牌,但是当我检索 valied_token 和用户时,它给了我以下错误:-
{
"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"
}
]
}