sat*_*jit 7 python django jwt django-rest-framework
我token在用户验证 OTP 时生成。但是当我验证标头中的令牌时,我得到了Invalid payload.
如果对我收到此错误的原因有任何帮助,将不胜感激。
序列化程序.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...
Run Code Online (Sandbox Code Playgroud)
我看到一个django-rest-framework-jwt关于类似问题的未决问题:https://github.com/jpadilla/django-rest-framework-jwt/issues/284
看起来这个库已经有几年没有维护了,我可能建议您切换到某种替代方案,他们建议使用这个: https: //github.com/SimpleJWT/django-rest-framework-simplejwt
| 归档时间: |
|
| 查看次数: |
236 次 |
| 最近记录: |