我正在尝试在 flask_jwt_extended 中实现刷新令牌系统,我遵循了官方文档。当我尝试使用 postman 使用 refresh_token 获取新的 access_token 时,我得到了带有新访问令牌的响应。但是当我尝试使用 axios 调用时,它会抛出 401 错误说:
msg: "Missing Authorization Header"
我的烧瓶代码:
@app.route("/refresh", methods=["POST"])
@jwt_required(refresh=True)
def refresh():
identity = get_jwt_identity()
print(identity)
access_token = create_access_token(identity=identity)
return jsonify(access_token=access_token)
print(access_token)
以下是我的 axios api 调用:
getAPI.post('/refresh', {
// refresh_token: context.state.refreshToken,
headers: { Authorization: `Bearer ${context.state.refreshToken}` },
})
axios api调用:
{"headers":{"Authorization":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTYxNzY0MDcyOCwianRpIjoiNmE3OTYyNjctNjYwMS00ZjQ5LWJmZjEtODUwYjhhMDkyMjgyIiwibmJmIjoxNjE3NjQwNzI4LCJ0eXBlIjoicmVmcmVzaCIsInN1YiI6eyJlbWFpbCI6InZlbjMzQGVtYWlsLmNvbSIsImFkZGl0aW9uYWxfY2xhaW1zIjp7InJvbGUiOltbIlVzZXIiXV19fSwiZXhwIjoxNjIwMjMyNzI4fQ.5MoE8DXwO7cCwN5nVC1u1st0cm1LDhBu1nSDb7VJmgg"}}