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 RequirePermissionMiddleware(BaseMiddleware): (source)
Constructor: RequirePermissionMiddleware(authorizer)
Require one or more permissions before reaching the controller.
The Orionis router attaches middleware classes, not parameterised instances, so the required permissions are declared by subclassing:
class CanManageUsers(RequirePermissionMiddleware):
permissions = ("users.view", "users.update")
Route.get("/users", [UserController, "index"]).middleware(CanManageUsers)
Declaring the requirement as a real class keeps the compiled route cache valid, which a dynamically generated class could not do.
| Method | __init__ |
Initialise the middleware with the authorizer. |
| Async Method | handle |
Evaluate the permissions and continue when they are granted. |
| Class Variable | __slots__ |
Declare the instance attribute slots reserved by this class. |
| Class Variable | permissions |
Permissions the identity must hold. |
| Class Variable | requires |
Whether every permission is required, or just one of them. |
| Instance Variable | _authorizer |
Component evaluating the permissions of the request context. |
Initialise the middleware with the authorizer.
| Parameters | |
authorizer:orionis.auth.contracts.IAuthorizer | Component evaluating the permissions of the request context. |
| Returns | |
None | No return value. |
orionis.http.BaseMiddleware.handleEvaluate the permissions and continue when they are granted.
| 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 permission at all. |
orionis.auth.AuthenticationException | When the request carries no authenticated identity, which the handler turns into a 401 response. |
orionis.auth.AuthorizationException | When the identity is authenticated but not authorized, which the handler turns into a 403 response. |
orionis.http.BaseMiddleware.__slots__Declare the instance attribute slots reserved by this class.