Skip to main content

Module authorization

Module authorization 

Source
Expand description

Application-defined gates and policies over authenticated users.

Applications register their own typed ability contexts while Aurelin owns evaluation, denial responses, hooks, and Axum enforcement.

use aurelin_framework::authorization::Gate;

#[derive(Clone)]
struct User { id: i64 }
#[derive(Clone)]
struct Article { owner_id: i64 }

let mut gates = Gate::<User>::builder();
gates.define("update-article", |user: User, article: Article| async move {
    user.id == article.owner_id
});
let gates = gates.build();
let user = User { id: 1 };
let article = Article { owner_id: 1 };

gates
    .for_user(Some(&user))
    .authorize("update-article", &article)
    .await?;

Structs§

AuthorizationResponse
The result of evaluating an authorization ability.
AuthorizeLayer
A route layer that authorizes an ability using the current axum-login session.
Gate
A shared registry of application-defined authorization abilities.
GateBuilder
Builds an immutable authorization gate registry.
GateEvaluated
The result of a gate check, before the default denial is applied.
PolicyRegistrar
Registers abilities belonging to one application policy.
UserGate
A request-oriented view of a gate registry for one user or guest.

Enums§

AuthorizationError
An authorization denial or invalid gate invocation.
GateError
A gate was invoked with an incompatible typed context.

Traits§

IntoAuthorizationResponse
Convert a policy result into an authorization response.
Policy
An application policy that registers typed abilities and optional pre-authorization.