简体   繁体   中英

throwing error for flask jwt extended refresh token

I am trying to implement refresh token system in flask_jwt_extended, I followed official documentation. When I try to get new access_token with refresh_token using postman I get the response with new access token. But when I try with axios call it is throwing 401 error saying:

msg: "Missing Authorization Header"

my flask code:

@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)

below is my axios api call:

getAPI.post('/refresh', {
          // refresh_token: context.state.refreshToken,
          headers: { Authorization: `Bearer ${context.state.refreshToken}` },
        })

axios api call:

{"headers":{"Authorization":"Bearer eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJmcmVzaCI6ZmFsc2UsImlhdCI6MTYxNzY0MDcyOCwianRpIjoiNmE3OTYyNjctNjYwMS00ZjQ5LWJmZjEtODUwYjhhMDkyMjgyIiwibmJmIjoxNjE3NjQwNzI4LCJ0eXBlIjoicmVmcmVzaCIsInN1YiI6eyJlbWFpbCI6InZlbjMzQGVtYWlsLmNvbSIsImFkZGl0aW9uYWxfY2xhaW1zIjp7InJvbGUiOltbIlVzZXIiXV19fSwiZXhwIjoxNjIwMjMyNzI4fQ.5MoE8DXwO7cCwN5nVC1u1st0cm1LDhBu1nSDb7VJmgg"}}

'POST' call configuration options for flask_extended should be in third argument. original answer is provided by github .

getAPI.post('/refresh', {
          {},
          headers: { Authorization: `Bearer ${context.state.refreshToken}` },
        })

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM