我正在使用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"
}
我应该如何知道在前端过期之前刷新令牌,它将如何做?
答案 0 :(得分:0)
所以您通常要做的是有2个端点来发行令牌
还有一个发出刷新令牌的刷新
因此,在您第一次从JS代码调用时,您将获得令牌。令牌通常包含DateTime或有效期(以秒为单位)
然后在您的JS中,您将检查令牌剩余的时间,如果还不多,则应致电refrehtoken路由以获取新令牌