我正在生成token,同时用户验证动态口令。但是,当我验证报头中的令牌时,我得到的是Invalid payload。
如果有任何帮助,为什么我会得到这个错误,然后将非常感谢。
serializers.py:
class OTPVerifyForResetPasswordAPIView(APIView):
permission_classes = (AllowAny,)
def post(self,request,*args,**kwargs):
data = request.data
user = request.user
print(user)
phone_number = request.data['phone_number']
country_code = request.data['country_code']
verification_code = request.data['verification_code']
if phone_number and country_code and verification_code:
obj_qs = User.objects.filter(phone_number__iexact = phone_number,country_code__iexact = country_code)
obj = ''
if obj_qs.exists() and obj_qs.count() ==1:
user_obj = obj_qs.first()
#Development
if verification_code == '1234':
payload = jwt_payload_handler(user_obj)
token = jwt_encode_handler(payload)
token = 'JWT '+str(token)
return Response({
'success' : 'True',
'message' : 'Your mobile number verified successfully',
'data' : {
'phone_number' : user_obj.phone_number,
'country_code' : user_obj.country_code,
'token' : token,
}
},status=HTTP_200_OK)
else:
##some logic....
else:
## some logic...发布于 2020-09-27 03:51:39
我在django-rest-framework-jwt中看到了一个类似问题的公开问题:https://github.com/jpadilla/django-rest-framework-jwt/issues/284看起来这个库已经几年没有维护了,我可能会建议你切换到其他的库,他们建议使用这个库:https://github.com/SimpleJWT/django-rest-framework-simplejwt
发布于 2020-09-28 14:56:59
使用user_obj = obj_qs.first()编辑行,如下所示
user_obj = {
'username': obj_qs.first().username,
...
}https://stackoverflow.com/questions/64074607
复制相似问题