I am mounting a Flask app as a sub-application in my root FastAPI app, as explained in the documentation
Now I want to add an authentication layer using HTTPAuthorizationCredentials dependency, as nicely explained in this tutorial
How can I do that?
Preferably, I would like that any type of access attempt to my Flask sub-application goes first through a valid token authentication process implemented in my FastAPI root app. Is that possible?
You can use a custom
WSGIMiddlewareand authorize the call to flask app inside that like this:For the tutorial you are looking at, you can replace the invoking
authenticatefunction in my example insideAuthWSGIMiddleware->__call__()withAuthHandler().decode_toke(authorization)