-
Notifications
You must be signed in to change notification settings - Fork 67
Auth using before_request decorator #141
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
Auth using before_request decorator #141
Conversation
Ensure MapAdapter is only created once Rework test with test_successful_views
|
I like this a lot! I wonder if we can (optionally) combine the public routes into the constructor, ie instead of two calls: add_public_routes(app, ["/home", "/user/<user_id>/public"])
BasicAuth(app, USERS)you could write it as: BasicAuth(app, USERS, public_routes=["/home", "/user/<user_id>/public"]) |
Add public_routes to Auth's constructor. Add types and docstrings.
|
Good idea, added |
|
I was looking exactly for the new feature "integration of public routes" for my multi page dash app. Would you mind having a short look into this minimal example? Do you see something wrong here? Thanks in advance :) |
|
Yes you are right it actually doesn't work in its current state... The issues are:
Given the above, I think I will remove the public routes part of the PR to keep only the change to a @alexcjohnson happy to have your thoughts on this or if you see some workarounds I may not have thought about. |
|
@fkuschel I gave it a bit more thought and I believe I have a working solution. It does require to mark all callbacks on public routes as Checkout the updated Readme for usage and example in a multi-page app. |
|
@RenaudLN, Thanks a lot! |
Public routes is separated into another PR
|
I reverted this PR to just being about using the before_request decorator. I will create another PR for the public routes once this is merged. @alexcjohnson Would you be able to give this a final review? @fkuschel If you were using the branch from my fork, you should switch to the new branch feature/whitelist-routes Also looks like the tests are failing due to issues with installing the latest version of the Chrome driver in CircleCI. |
|
@RenaudLN this looks great. Can you update the browser-tools orb like in https://github.com/plotly/dash/pull/2603/files? That should get the tests running again. |
|
Done and tests passed :) |
alexcjohnson
left a 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.
💃 Thanks very much @RenaudLN - and @fkuschel and @olivier-lacroix thank you for your feedback :)
|
@RenaudLN , thank you very much for your suggestions! |
|
@RenaudLN, @fkuschel, and @olivier-lacroix - my apologies, I had forgotten to create a release for this work! But v2.1.0 is now published. |
|
@alexcjohnson I had split out the whitelisting from this PR as this one was originally about protecting all routes with before_request and whitelisting was starting to muddy up the changes. #142 is still required to add the whitelist functionality. |
|
Ah ok, I had forgotten that in the history here. If you want to update that PR I can make another release! |
|
Is there no way anymore to have unprotected paths? This seems like a breaking change |
This PR changes the behaviour of Auth (and BasicAuth) to work on every single route by default. Until now, only the routes that were created before the instantiation of Auth were protected.
To ensure every route goes through the auth check, a
before_requestdecorator is used.Bonus: Users can whitelist endpoints by marking them as public via Flask's config using the
PUBLIC_ROUTESkey. The public routes should follow the same format as regular Flask routes.