Skip to main content

AuthHook

Trait AuthHook 

Source
pub trait AuthHook: 'static {
    // Required method
    fn on_event(
        cx: &Cx,
        event: &AuthEvent<'_>,
        ex: &mut dyn Executor,
    ) -> impl Future<Output = Result<()>> + Send;
}
Expand description

Work a panel does inside the transaction of each AuthEvent, registered by Panel::auth_hook: an audit trail of who acted as whom.

Run every statement through ex. An Err on an event that grants or changes something (a sign-in, a start of impersonation, a change of credentials, address or second factor) rolls it back and fails the request. An Err on a stop of impersonation, a sign-out or a refused attempt rolls back what the hooks wrote and is logged, and the event stands: a session that cannot stop acting as someone else, or sign out, is worse than one the trail misses.

struct Trace;

impl AuthHook for Trace {
    async fn on_event(
        _cx: &Cx,
        event: &AuthEvent<'_>,
        _ex: &mut dyn toasty::Executor,
    ) -> Result<()> {
        if let (AuthEventKind::Impersonate { .. }, Some(actor), Some(target)) =
            (event.kind(), event.actor(), event.target_id())
        {
            tracing::info!("{} acts as {target}", actor.user_id());
        }
        Ok(())
    }
}

Required Methods§

Source

fn on_event( cx: &Cx, event: &AuthEvent<'_>, ex: &mut dyn Executor, ) -> impl Future<Output = Result<()>> + Send

Work inside the event’s transaction.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§