Skip to main content

SessionStore

Trait SessionStore 

Source
pub trait SessionStore:
    Send
    + Sync
    + 'static {
    // Required methods
    fn load<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id_hash: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<Option<SessionRecord>, StoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn save<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id_hash: &'life1 str,
        record: &'life2 SessionRecord,
        ttl: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn update<'life0, 'life1, 'life2, 'async_trait>(
        &'life0 self,
        id_hash: &'life1 str,
        record: &'life2 SessionRecord,
        ttl: Duration,
    ) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait,
             'life2: 'async_trait;
    fn delete<'life0, 'life1, 'async_trait>(
        &'life0 self,
        id_hash: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;
    fn revoke_user<'life0, 'life1, 'async_trait>(
        &'life0 self,
        user: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait;

    // Provided method
    fn auth_epoch<'life0, 'life1, 'async_trait>(
        &'life0 self,
        _user: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = Result<u64, StoreError>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Server-side storage of sessions, keyed by the SHA-256 hex of the id.

The store never sees a raw session id, so a leaked table or backup does not hand out live sessions. Implementations must be safe for concurrent use. Requests of one session are last-writer-wins: the layer does not merge concurrent changes.

A store is not asked to enforce idle or absolute lifetimes (the layer does, from the record), but it must drop entries after ttl so that abandoned sessions disappear.

Required Methods§

Source

fn load<'life0, 'life1, 'async_trait>( &'life0 self, id_hash: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<Option<SessionRecord>, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Fetch the record for id_hash; Ok(None) when absent or expired or revoked.

§Errors

StoreError when the store cannot be read. The layer then answers 503 instead of treating the request as anonymous.

Source

fn save<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id_hash: &'life1 str, record: &'life2 SessionRecord, ttl: Duration, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Store record under id_hash, replacing any record, for ttl.

§Errors

StoreError when the record was not stored.

Source

fn update<'life0, 'life1, 'life2, 'async_trait>( &'life0 self, id_hash: &'life1 str, record: &'life2 SessionRecord, ttl: Duration, ) -> Pin<Box<dyn Future<Output = Result<bool, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait, 'life2: 'async_trait,

Replace the record under id_hash only if one is stored, for ttl; Ok(false) when there is none.

The layer writes existing sessions through this method, so a slow request that loaded a session before another request logged it out or rotated its id cannot store it again. Implementations must never let a deleted id become loadable again, even when the check and the write race with delete.

§Errors

StoreError when the record may not have been stored.

Source

fn delete<'life0, 'life1, 'async_trait>( &'life0 self, id_hash: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Remove id_hash. Removing an absent record is not an error.

§Errors

StoreError when the record may still exist.

Source

fn revoke_user<'life0, 'life1, 'async_trait>( &'life0 self, user: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<(), StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidate every session of user, now and for stale in-flight writes. Use it after password changes and account recovery.

§Errors

StoreError when the revocation may not have taken effect.

Provided Methods§

Source

fn auth_epoch<'life0, 'life1, 'async_trait>( &'life0 self, _user: &'life1 str, ) -> Pin<Box<dyn Future<Output = Result<u64, StoreError>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

The user’s current revocation epoch, recorded in SessionRecord::auth_epoch at login. Stores that revoke by deleting records can keep the default of 0.

§Errors

StoreError when the epoch cannot be read; the login then fails.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§