THE ORIONIS API
Build with clarity.
Explore the building blocks of an async-first Python framework. Every module, class, and method — connected, searchable, and ready to build with.
class documentation
class RequirePolicyMiddleware(BaseMiddleware): (source)
Constructor: RequirePolicyMiddleware(authorizer)
Gate a route behind a policy ability declared on a resource class.
The middleware evaluates the ability against the resource class, which covers the gates that do not need a loaded row, such as viewAny or create:
class CanCreatePosts(RequirePolicyMiddleware):
ability = "create"
resource = Post
Abilities that depend on a concrete row belong in the controller, where the instance already exists:
await Auth.authorizeResource("update", post)
| Method | __init__ |
Initialise the middleware with the authorizer. |
| Async Method | handle |
Evaluate the policy and continue when it allows the operation. |
| Class Variable | __slots__ |
Declare the instance attribute slots reserved by this class. |
| Class Variable | ability |
Ability declared by the policy of the resource. |
| Class Variable | resource |
Resource class protected by the policy. |
| Instance Variable | _authorizer |
Component resolving and running the policy. |
Initialise the middleware with the authorizer.
| Parameters | |
authorizer:orionis.auth.contracts.IAuthorizer | Component resolving and running the policy. |
| Returns | |
None | No return value. |
overrides
orionis.http.BaseMiddleware.handleEvaluate the policy and continue when it allows the operation.
| Parameters | |
request:orionis.http.Request | Incoming HTTP request, unused by this middleware. |
callorionis.http.NextCallable | Callable advancing to the next layer. |
| Returns | |
orionis.http.Response | Response produced by the rest of the pipeline. |
| Raises | |
orionis.auth.AuthConfigurationException | When the subclass declares no ability or no resource. |
orionis.auth.AuthenticationException | When the request carries no authenticated identity. |
orionis.auth.AuthorizationException | When the policy denies the operation. |
overrides
orionis.http.BaseMiddleware.__slots__Declare the instance attribute slots reserved by this class.