-
Notifications
You must be signed in to change notification settings - Fork 0
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
Taks 1 - Refactor get_api_endpoints() #3
Taks 1 - Refactor get_api_endpoints() #3
Conversation
@@ -304,8 +304,4 @@ def init_api_experimental(app): | |||
def init_api_auth_provider(connexion_app: connexion.FlaskApp): | |||
"""Initialize the API offered by the auth manager.""" | |||
auth_mgr = get_auth_manager() | |||
blueprint = auth_mgr.get_api_endpoints(connexion_app) | |||
if blueprint: | |||
base_paths.append(blueprint.url_prefix if blueprint.url_prefix else "") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We do not have any blueprint
here, so we can not update base_path
But we need to handle base path update logic somewhere. Whats the impact of removing this line.
specification=specification, | ||
resolver=_LazyResolver(), | ||
base_path="/auth/fab/v1", | ||
swagger_ui_options=swagger_ui_options, | ||
strict_validation=True, | ||
validate_responses=True, | ||
) | ||
return api.blueprint if api else None | ||
return None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
return None | |
self.appbuilder.app.extensions["csrf"].exempt(api.blueprint) | |
return None |
According to the proposed solution, you it is suggested to move it here I guess.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This doesn't give you KeyError "crsf"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, you have to add an if
statement. But this does not solve the CSRF error
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if api:
self.appbuilder.app.extensions["csrf"].exempt(api.blueprint)
return None
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks like this connexion_app.add_api() doesn't return an object, so I just removed "if" statement.
I kind of understanding Vlada's struggle now.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I think that is why, CSRF error is still there. In this comment I think Rob suggested some solution
apache#36052 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what he meant here. I might need some time to understand it.
"Find a way to add csrf extension to a newly created blueprint using connexion: to retrieve blueprint object from connexion_app variable to save the current logic (flask_app.extensions["csrf"].exempt(blueprint)) or find a way to add this extension on connexion level(check the documentation for available options)."
Seems like we cannot get the blueprint, so we better focus on the second option(add this extension on the connexion level). I'm reading the connexion source code, but no luck yet.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Probably need to understand this repo. I will let you know if I find something useful.
f66f6d9
to
de01bb4
Compare
858eaa8
to
62fd55d
Compare
ProblemDue to the upgrading connextion v3, we cannot access blueprints( they moved the blueprint registration code inside their codebase). We used the returned blueprint to make exemptions to accept HTTP(S) requests without "csrf token" in the header. When the client makes a post request, it doesn't include a csrf token. That's why we get csrf token missing error with @RobbeSneyders suggested utilizing the middleware library asgi-csrf to do the same without using blueprints.
This is a sample code to make csrf-token exemption.
I'm trying to implement this on "/api/v1/" and random signing_secret for now. |
I just tried to use asgi_csrf but it doesn't work as expected. I might've made some mistakes in the implementation. I just pushed it so that you can have a look at it. @sudiptob2 |
55a9f42
to
9b6a72a
Compare
de01bb4
to
f261cf5
Compare
9b6a72a
to
6d06cb8
Compare
f261cf5
to
cdb0968
Compare
Signed-off-by: sudipto baral <sudiptobaral.me@gmail.com>
6d06cb8
to
08f4783
Compare
Problem Definiton
Ref: Github Pull Request #36052 VladaZakharova commented on Jan 18
In the
init_api_auth_provider
method, we update the base path as follows:However, the
blueprint
object obtained fromauth_mgr.get_api_endpoints(connexion_app)
will always beNone
if we are using ConnexionV3.Proposed solution
Ref vincbeck commented on Jan 18
get_api_endpoints
toset_api_endpoints
. The return type should be updated toNone
. Documentation should be updated as well to something like "Set API endpoint(s) definition for the auth manager.". This is a breaking change but nobody uses this interface yet, so it is a good time to do it.flask_app.extensions["csrf"].exempt(blueprint)
should be moved in theset_api_endpoints
method usingappbuilder.app.extensions["csrf"].exempt(api.blueprint)
How to test
python ./clients/python/test_python_client.py