pub trait AuthExt {
Show 13 methods
// Required methods
fn current_user(&self) -> Option<&CurrentUser>;
fn require_current_user(&self) -> Result<&CurrentUser>;
fn profile(&self) -> Result<&CurrentUser>;
fn require_permission(&self, slug: &str) -> Result<&CurrentUser>;
fn require_role(&self, slug: &str) -> Result<&CurrentUser>;
fn password_confirmed(&self) -> bool;
fn can<P: Policy<R> + Default, R>(
&self,
ability: Ability,
resource: &R,
) -> bool;
fn authorize<P: Policy<R> + Default, R>(
&self,
ability: Ability,
resource: &R,
) -> Result<&CurrentUser>;
fn authorize_with(
&self,
f: impl FnOnce(&CurrentUser) -> bool,
) -> Result<&CurrentUser>;
fn login_user(&mut self, user: CurrentUser);
fn logout_user(&mut self);
fn logout_other_sessions(&self) -> impl Future<Output = Result<u64>> + Send;
fn logout_all_sessions(
&mut self,
) -> impl Future<Output = Result<u64>> + Send;
}Expand description
Request helpers for RBAC (CurrentUser from Fortify / Passport session).
Required Methods§
fn current_user(&self) -> Option<&CurrentUser>
fn require_current_user(&self) -> Result<&CurrentUser>
Sourcefn profile(&self) -> Result<&CurrentUser>
fn profile(&self) -> Result<&CurrentUser>
Alias for Self::require_current_user.
fn require_permission(&self, slug: &str) -> Result<&CurrentUser>
fn require_role(&self, slug: &str) -> Result<&CurrentUser>
fn password_confirmed(&self) -> bool
Sourcefn can<P: Policy<R> + Default, R>(&self, ability: Ability, resource: &R) -> bool
fn can<P: Policy<R> + Default, R>(&self, ability: Ability, resource: &R) -> bool
Check a crate::Policy ability against resource.
Like Self::can, but returns Error::Forbidden on deny.
Custom predicate authorization.
Sourcefn login_user(&mut self, user: CurrentUser)
fn login_user(&mut self, user: CurrentUser)
Programmatic login: rotate session, persist passport user id, set CurrentUser.
ⓘ
let cu = load_current_user(db, id).await?.unwrap();
req.login_user(cu);Sourcefn logout_user(&mut self)
fn logout_user(&mut self)
Clear Fortify/Passport session auth (pending 2FA, password confirm, CurrentUser).
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".