-
Notifications
You must be signed in to change notification settings - Fork 7
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
Introduce Authz contextvar and Authorization object #615
Conversation
@ateska I want to introduce Authorization context which can be accessed and used similarly to the Tenant context. I'm still testing it but it's close to finished. What do you think? |
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.
Discussed in person.
# Conflicts: # asab/contextvars.py
I like it, I looked over the implementation and I do not have anything to add. There are even updated examples etc... |
Summary
asab.web.auth.Authorization
asab.web.auth.Authorization
object with request authorization and authentication details, such asCredentialsId
,Username
orEmail
.has_resource_access
,has_superuser_access
andhas_tenant_access
, which return boolean value. Plusrequire_resource_access
,require_superuser_access
andrequire_tenant_access
, which raiseasab.exceptions.AccessDenied
and log a warning when access is missing.Authorization
object is stored inasab.contextvars.Authz
context variable so it can be conveniently accessed from anywhere, including websocket methods.Authorization
objects are kept (or "cached") inAuthService
and cleaned up when they expire.DEPRECATION
Handler argumentsuser_info
andresources
are now deprecated and their usage will log a warning at init time. Use the methods and attributes ofAuthorization
instead, for example:OLD
NEW
Automatic AuthService installation
DEPRECATION
When the app has only one web container, you don't need to callAuthService.install(web_container)
, because it is called automatically at init time. Re-applying the installation will log a warning.Other changes
asab.web.auth
module for better reusability.Usage
See https://github.com/TeskaLabs/asab/blob/feature/auth-contextvar/examples/web-auth.py for a full example.