我正在使用flask jet-extended构建应用程序,并且正在从https://flask-jwt-extended.readthedocs.io/en/stable/blocklist_and_token_revoking/注销
我的问题是装饰器@jwt.token_in_blacklist_loader似乎不起作用。我正在这样做:
@bp.route('/logout', methods=('GET', 'POST'))
@jwt_required
def logout():
jti = get_raw_jwt()["jti"]
insert_jti_in_blacklist(jti) # function that insert jti in my database
return redirect(url_for('auth.login')) #redirect to login
@jwt.token_in_blacklist_loader
def check_if_token_revoked(jwt_header, jwt_payload):$
print("check revoked token")
jti = jwt_payload["jti"]
return jti_in_blacklist(jti) #function return True if my jti is in blacklist以及我测试黑名单的函数:
@bp.route('/account', methods=('GET', 'POST'))
@jwt_required
def account() -> str:
print(jti_in_blacklist(get_raw_jwt()["jti"]))我所做的是,从我的应用程序中注销,然后转到account中的函数print in account return "True“(我的令牌在黑名单中),但我从未进入check_if_token_revoked (我没有让我控制台打印"check revoked token”)
那么,为什么不调用它呢?通常这正是这个装饰器的目标,我不明白为什么它不能工作
谢谢
发布于 2021-03-18 01:34:14
尝试将@jwt_required更改为@jwt_required(),解释为here。
发布于 2021-03-18 01:46:15
感谢@igor,我在文档中发现我使用的是jwt-extended的旧版本,其中JWT_BLACKLIST_ENABLED需要放在"True“上。
现在它可以正常工作了。
https://stackoverflow.com/questions/66678112
复制相似问题