jwt.py 415 B

1234567891011121314151617
  1. from flask_jwt_extended import JWTManager
  2. def init_jwt(app):
  3. jwt = JWTManager(app)
  4. # 处理 refresh token 过期,强制用户登出
  5. @jwt.unauthorized_loader
  6. def unauthorized_callback(error):
  7. # 延迟导入,避免循环导入
  8. from app.routes import logout
  9. # 模拟调用登出接口
  10. with app.test_request_context():
  11. return logout()
  12. return jwt