-
Notifications
You must be signed in to change notification settings - Fork 7.3k
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
Add simple Basic auth #1203
Add simple Basic auth #1203
Conversation
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 good to me! We me be overusing the
if not settings.server.auth.enabled:
check in auth.py, but I think it makes it safer for future refactors.
As a general note, we should be documenting this (also the previous CORS support) in docs/description.md
and then executing make api-docs
to generate the udpated version of the api docs github pages, then commit those changes.
177f895
to
5222ba8
Compare
To enable the basic authentication, one must set `server.auth.enabled` to true. The static string defined in `server.auth.secret` must be set in the header `Authorization`. The health check endpoint will always be accessible, no matter the API auth configuration.
Had to disable mypy in the `auth` as we are not using the same signature for the authenticated method. mypy was complaining that the signatures of `authenticated` must be identical, no matter in which logical branch we are. Given that fastapi is accomodating itself of method signatures (it will inject the dependencies in the method call), this warning of mypy is actually preventing us to do something legit. mypy doc: https://mypy.readthedocs.io/en/stable/common_issues.html
* Add simple Basic auth To enable the basic authentication, one must set `server.auth.enabled` to true. The static string defined in `server.auth.secret` must be set in the header `Authorization`. The health check endpoint will always be accessible, no matter the API auth configuration. * Fix linting and type check * Fighting with mypy being too restrictive Had to disable mypy in the `auth` as we are not using the same signature for the authenticated method. mypy was complaining that the signatures of `authenticated` must be identical, no matter in which logical branch we are. Given that fastapi is accomodating itself of method signatures (it will inject the dependencies in the method call), this warning of mypy is actually preventing us to do something legit. mypy doc: https://mypy.readthedocs.io/en/stable/common_issues.html * Write tests to verify that the simple auth is working
To enable the basic authentication, one must set
server.auth.enabled
to true.The static string defined in
server.auth.secret
must be set in the headerAuthorization
.The health check endpoint will always be accessible, no matter the API auth configuration.
The
authenticated
"bean"/"method-in-the-chain" is declared as a dependency in the API router that requiresauthenticated
connections. c.f.faspAPI
documentation for details ondependencies
: https://fastapi.tiangolo.com/tutorial/bigger-applications/Security
section of the fastAPI is also a good read: https://fastapi.tiangolo.com/tutorial/security/