Skip to main content

StoreAuth

Struct StoreAuth 

Source
pub struct StoreAuth<S: UserStore> { /* private fields */ }
Expand description

Generic authentication backend that wraps a UserStore.

Provides shared validation, caching, and traffic batching logic. New backends only need to implement UserStore (data access).

§Type parameter

  • S — the underlying data store (e.g. SqlStore)

Implementations§

Source§

impl<S: UserStore> StoreAuth<S>

Source

pub fn new(store: S, config: &StoreAuthConfig) -> Self

Create a new StoreAuth wrapping the given store.

For backends that need batched traffic recording, use with_traffic_recorder after construction.

Source

pub fn store(&self) -> &S

Get a reference to the underlying store.

Source

pub fn cache_enabled(&self) -> bool

Check if caching is enabled.

Source

pub fn cache_stats(&self) -> Option<CacheStats>

Get cache statistics. Returns None if caching is disabled.

Source

pub fn cache_invalidate(&self, hash: &str)

Invalidate cache entry by password hash.

Also removes the hash from the negative cache so that a newly-added user is not blocked by a stale negative entry.

Source

pub fn cache_invalidate_user(&self, user_id: &str)

Invalidate all cache entries for a user.

Source

pub fn cache_clear(&self)

Clear all cache entries.

Trait Implementations§

Source§

impl<S: UserStore> AuthBackend for StoreAuth<S>

Source§

fn verify<'life0, 'life1, 'async_trait>( &'life0 self, hash: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<AuthResult, AuthError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Verify a password hash. Read more
Source§

fn record_traffic<'life0, 'life1, 'async_trait>( &'life0 self, user_id: &'life1 str, bytes: u64, ) -> Pin<Box<dyn Future<Output = Result<(), AuthError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Optional: Record traffic usage for a user. Read more
Source§

impl<S: UserStore + Debug> Debug for StoreAuth<S>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

Auto Trait Implementations§

§

impl<S> !Freeze for StoreAuth<S>

§

impl<S> !RefUnwindSafe for StoreAuth<S>

§

impl<S> Send for StoreAuth<S>

§

impl<S> Sync for StoreAuth<S>

§

impl<S> Unpin for StoreAuth<S>
where S: Unpin,

§

impl<S> UnsafeUnpin for StoreAuth<S>
where S: UnsafeUnpin,

§

impl<S> UnwindSafe for StoreAuth<S>
where S: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.