Move the logout logic to the auth manager
response.headers["X-Frame-Options"] = "DENY"
        return response
    app.after_request(apply_caching)
def init_api_experimental_auth(app):
    """Loads authentication backends."""
    auth_backends = "airflow.api.auth.backend.default"
    try:
        auth_backends = conf.get("api", "auth_backends")
    except AirflowConfigException:
        pass
    app.api_auth = []
    for backend in auth_backends.split(","):
        try:
            auth = import_module(backend.strip())
            auth.init_app(app)
            app.api_auth.append(auth)
        except ImportError as err:
            log.critical("Cannot import %s for API authentication due to: %s", backend, err)
            raise AirflowException(err)
def init_check_user_active(app):
    @app.before_request
    def check_user_active():
        if get_auth_manager().is_logged_in() and not g.user.is_active:
            logout_user()
            return redirect(get_auth_manager().get_url_login())