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 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__ |
Undocumented |
| Class Variable | permissions |
Undocumented |
| Class Variable | requires |
Undocumented |
| Instance Variable | _authorizer |
Undocumented |
Initialise the middleware with the authorizer.
| Parameters | |
authorizer:IAuthorizer | Component evaluating the permissions of the request context. |
| Returns | |
None | The middleware keeps no per request state. |
overrides
orionis.http.BaseMiddleware.handleEvaluate the permissions and continue when they are granted.
| Parameters | |
request:Request | Incoming HTTP request, unused by this middleware. |
callNextCallable | Callable advancing to the next layer. |
| Returns | |
Response | Response produced by the rest of the pipeline. |
| Raises | |
AuthConfigurationException | When the subclass declares no permission at all. |
AuthenticationException | When the request carries no authenticated identity, which the handler turns into a 401 response. |
AuthorizationException | When the identity is authenticated but not authorized, which the handler turns into a 403 response. |