我有一个django rest framework API,其中我使用django. core. signing模块创建了一个token。当使用API Clinet(E. g)Postman时,对象的签名和取消签名工作正常。但是当我尝试使用axios连接我的Next Js前端时,它得到了。
否":"在内标识eyJlbWFpbCI6InJhbW9ucmFzaDJAZ21haWwuY29tIiwiZmlyc3RfbmFtZSI6IlJhc2hlZW的值中找到QiLCJsYXN0X25hbWUiOiJSYW1vbiIsInBhc3N3b3JkIjoiTmluaW9sYTEyIiwiYWN0aXZhd@vbl9jb2RlIjoiNzk3ODY5In0%3A1rBvFl%3Ato5l_EAmsHy76eJt0sHDcO_eqlk0k4 fho78czQeNVx4.但实际令牌是eyJlbWFpbCI6InJhbW9ucmFzaDJAZ21haWwuY29tIiwiZmlyc3RfbmFzz@ZSI6IlJhc2hlZWQiLCJsYXN0X25hbWUiOiJSYW1vbiIsInBhc3N3b3JkIjoiTmluaW9sY TEyIiwiYWN0aXZhdGlvbl9jb2RlIjoiNzk3ODY5In 0:1rBvFl:至5l_EAmsHy76eJt0sHDcO_eqlk0k4fho78czQeNVx4
这是API代码
def create(self, request, *args, **kwargs):
activation_token = request.data.get("activation_token")
activation_code = request.data.get("activation_code")
print(activation_token)
try:
data = signer.unsign_object(
activation_token, max_age=timedelta(minutes=10))
except Exception as e:
print(e)
return Response({"message": "OTP has expired! Try registering again."}, status=status.HTTP_400_BAD_REQUEST)
if data["activation_code"] == activation_code:
user = User.objects.create_user(
email=data["email"], password=data["password"], first_name=data["first_name"], last_name=data["last_name"])
serializer = UserSerializer(user, many=False)
return Response(serializer.data, status=status.HTTP_201_CREATED)
else:
return Response({"message": "Invalid OTP"}, status=status.HTTP_400_BAD_REQUEST)
字符串
关于Axios Code
const response = await axios.post(
`${BASEURL}auth/users/activate/`,
JSON.stringify({
activation_code: values.otp,
activation_token: token,
}),
{
headers: {
Accept: "*/*",
"Content-Type": "application/json",
},
}
);
型
1条答案
按热度按时间xxls0lw81#
问题是,每当我把令牌放在URL中时,它都会对空格、冒号、逗号等字符进行编码。解决方案是将URI组件解码回原始形式。
字符串