我正在使用 python flask_jwt_extended 来处理 jwt。我有一个刷新端点(来自文档),如下所示:
# The jwt_refresh_token_required decorator insures a valid refresh
# token is present in the request before calling this endpoint. We
# can use the get_jwt_identity() function to get the identity of
# the refresh token, and use the create_access_token() function again
# to make a new access token for this identity.
@app.route('/refresh', methods=['POST'])
@jwt_refresh_token_required
def refresh():
current_user = get_jwt_identity()
ret = {
'access_token': create_access_token(identity=current_user)
}
return jsonify(ret), 200
我不确定何时应该在前端调用此端点。当我尝试使用受保护的端点时,我得到以下信息(这是预期的):
{
"msg": "Token has expired"
}
我应该怎么知道在前端到期之前刷新令牌,它会怎么做?