-
-
Notifications
You must be signed in to change notification settings - Fork 767
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Update context throughout middleware stack? #1750
Comments
Big +1 for this. This issue bit me quite hard when we were trying to move from a non-trivial Connexion 2 codebase to 3. I can't recall the workaround we had to do, but it wasn't pretty. |
Another big +1 on this. I'm working on a custom authentication scenario that needs access to the request context, to make authn and authz decisions based on data in the request. |
@SpudInNZ May I ask for your workaround? I need access to the request in the security middleware and currently I have no idea how to do that. |
For middlewares inheriting the
|
I think this might be the core problem when migrating a flask-based connexion v2 app to v3. In our case, it would have been really beneficial if our security implementations could have access to the flask config/db. I think we could clean up our "integration code" quite a bit if connexion provided the scope to middlewares earlier in the stack. |
We currently set the Context variables offered to the user in the
ContextMiddleware
at the end of the stack, which makes them available in view functions and any code called from there.In code called earlier in the middleware stack, such as the security functions for example, the context is not available.
Each middleware has access to all the information needed to set the context, so we could update the context in each middleware throughout the middleware stack to make it accessible to code running anywhere in the stack during a request.
Note that middlewares handling responses, such as the
ResponseValidation
, actually need this context when returning the response, so we might have to set and unset it as follows:The text was updated successfully, but these errors were encountered: