Skip to main content

AuthExt

Trait AuthExt 

Source
pub trait AuthExt {
    // 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 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§

Source

fn current_user(&self) -> Option<&CurrentUser>

Source

fn require_current_user(&self) -> Result<&CurrentUser>

Source

fn profile(&self) -> Result<&CurrentUser>

Source

fn require_permission(&self, slug: &str) -> Result<&CurrentUser>

Source

fn require_role(&self, slug: &str) -> Result<&CurrentUser>

Source

fn password_confirmed(&self) -> bool

Source

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);
Source

fn logout_user(&mut self)

Clear Fortify/Passport session auth (pending 2FA, password confirm, CurrentUser).

Source

fn logout_other_sessions(&self) -> impl Future<Output = Result<u64>> + Send

Kill every other device/session for the current user; keep this cookie.

Source

fn logout_all_sessions(&mut self) -> impl Future<Output = Result<u64>> + Send

Kill all sessions for the current user, including this one.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl AuthExt for Request

Implementors§