slmg opened a new issue, #32747: URL: https://github.com/apache/airflow/issues/32747
### Apache Airflow version 2.6.3 ### What happened Hi, I would like to pass a custom [WSGI Middleware](https://medium.com/swlh/creating-middlewares-with-python-flask-166bd03f2fd4) to the underlying flask server. I could theoretically do so in *webserver_config.py* by accessing `flask.current_app`: ```python # webserver_config.py from flask import current_app from airflow.www.fab_security.manager import AUTH_REMOTE_USER class MyAuthMiddleware: def __init__(self, wsgi_app) -> None: self.wsgi_app = wsgi_app def __call__(self, environ: dict, start_response): print("--> Custom authenticating logic") environ["REMOTE_USER"] = "username" return self.wsgi_app(environ, start_response) current_app.wsgi_app = MyAuthMiddleware(current_app.wsgi_app) AUTH_TYPE = AUTH_REMOTE_USER ``` But for this to work [the application context](https://flask.palletsprojects.com/en/2.3.x/appcontext/) should be pushed while reading the webserver config. Thus https://github.com/apache/airflow/blob/fbeddc30178eec7bddbafc1d560ff1eb812ae37a/airflow/www/app.py#L84 should become ```python with flask_app.app_context(): flask_app.config.from_pyfile(settings.WEBSERVER_CONFIG, silent=True) ``` ### What you think should happen instead _No response_ ### How to reproduce Documented in description. ### Operating System Debian 11 (Bullseye) ### Versions of Apache Airflow Providers _No response_ ### Deployment Official Apache Airflow Helm Chart ### Deployment details _No response_ ### Anything else _No response_ ### Are you willing to submit PR? - [X] Yes I am willing to submit a PR! ### Code of Conduct - [X] I agree to follow this project's [Code of Conduct](https://github.com/apache/airflow/blob/main/CODE_OF_CONDUCT.md) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
