-
-
Notifications
You must be signed in to change notification settings - Fork 769
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
Migrating to Connexion 3: Issues with current_app and g for Authentication and Request Lifecycle #1880
Comments
Thanks @gaurav-triverus. I submitted a PR which makes the class CustomMiddleware:
def __init__(self, next_app: ASGIApp):
self.next_app = next_app
def before_request(scope: Scope):
# Code here. State can be stored on the scope.
def after_request(scope: Scope):
# Code here. State can be stored on the scope.
async def __call__(self, scope: Scope, receive: Receive, send: Send) -> None:
self.before_request(scope)
await self.app(scope, receive, send)
app = connexion.FlaskApp(__name__)
app.add_middleware(CustomMiddleware, position=connexion.middleware.MiddlewarePosition.BEFORE_SECURITY) You can then access the state via |
Thanks @RobbeSneyders |
Yes indeed @gaurav-triverus
|
Hi, I have some issues implementing this custom Middleware. this is my code: `class CustomMiddleware:
def get_project_root_dir() -> str: def decode_jwt(token):
def hellow_world(): def create_app():
if name == "main": when running the code and testing the endpoint hellowworld I have 1 issue:
Results: test app --> in create_app |
Description
I am currently in the process of migrating a Flask application to Connexion 3 and have encountered an issue related to the use of current_app and the g object, which I previously utilized extensively in my Connexion 2 FlaskApp setup. In the older version, I used to set several variables in g during the @before_request hook, and these variables were accessible throughout the lifespan of a request, including in my authentication methods and in methods decorated with @after_request.
This setup was crucial for maintaining request-scoped data, such as user authentication details and other contextual information needed across different parts of the application during the processing of a single request.
However, with the upgrade to Connexion 3, I am finding it challenging to replicate this behavior. The documentation and migration guides I've consulted so far do not provide clear instructions on how to achieve similar functionality with the updated framework version. Specifically, I am looking for guidance on:
Could you provide examples or guidance on how to adapt my existing FlaskApp code to work with Connexion 3, particularly focusing on the use of current_app and g for request-scoped data handling and authentication?
Output of the commands:
The text was updated successfully, but these errors were encountered: