正在尝试验证用户的令牌。在
如何在客户端发出请求(js+react):
axios({
method: 'POST',
url: '/verify',
headers: { authorization: sessionStorage.getItem('token') },
data: {}
})
.then(function(response) {
// ...
});
如何在服务器端接收请求(python):
^{pr2}$为什么我会得到这个错误?公司名称:
Traceback (most recent call last):
........
jwt.exceptions.DecodeError: Signature verification failed
提前谢谢你。在
注:令牌已正确发送
编辑:
找到了导致错误的原因:
@app.route('/login', methods=['POST'])
def get_user():
// ...
token = jwt.encode({'some': 'payload'}, 'secret', algorithm='HS256')
return token // when I return the token here, it becomes slightly reduced
真正的代币:
b'eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U'
我返回的减少代币:
eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJzb21lIjoicGF5bG9hZCJ9.Joh1R2dYzkRvDkqv3sygm5YyK8Gi4ShZqbhK2gxcs2U
我需要如何将生成的jwt令牌发送到客户端来解决这个问题?在
这看起来像是字符串与字节编码问题。解码字节字符串:
要将字符串编码为字节:
^{pr2}$在将传入字符串传递给
jwt.decode()
之前,您可能需要将其encode
转换为字节,如下所示:除了UTF-8之外还有其他编码,但这可能就是您需要的。在
相关问题 更多 >
编程相关推荐