Skip to main content

TokenStore

Trait TokenStore 

Source
pub trait TokenStore: Send + Sync {
    // Required methods
    fn load(&self) -> impl Future<Output = Option<Token>> + Send;
    fn save(&self, token: &Token) -> impl Future<Output = ()> + Send;
}
Expand description

Pluggable persistent cache for service tokens.

Implementations are consulted by AutoRefresh whenever it has no in-memory token (cold start), and written to after every successful refresh or initial authentication. Implementations should treat both methods as best-effort — load returns None for “no token, or load failed”, save is fire-and-forget. The AutoRefresh state machine always validates freshness via Token::is_usable / Token::is_expired before returning a loaded token, so implementations don’t need to.

On native targets the trait carries Send + Sync bounds so the store can be shared across tokio::spawn background work. On wasm32 the bounds are dropped — edge runtimes are single-threaded.

Required Methods§

Source

fn load(&self) -> impl Future<Output = Option<Token>> + Send

Load the most recently saved token, or None if none has been stored (or the load failed). Errors are swallowed — the calling state machine falls back to fresh authentication when this returns None.

Source

fn save(&self, token: &Token) -> impl Future<Output = ()> + Send

Persist a token after a successful refresh or initial authentication. Best-effort — implementations should log on failure rather than returning an error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: TokenStore + ?Sized> TokenStore for Arc<T>

Available on non-WebAssembly only.

Forward TokenStore through Arc so one store can back many strategy instances (Edge Function pool, CipherStash Proxy worker pool, etc).

Source§

fn load(&self) -> impl Future<Output = Option<Token>> + Send

Source§

fn save(&self, token: &Token) -> impl Future<Output = ()> + Send

Implementors§

Source§

impl TokenStore for InMemoryTokenStore

Source§

impl TokenStore for NoStore

Source§

impl<L, LF, S, SF> TokenStore for TokenStoreFn<L, S>
where L: Fn() -> LF + Send + Sync, LF: Future<Output = Option<String>> + Send, S: Fn(String) -> SF + Send + Sync, SF: Future<Output = ()> + Send,

Available on non-WebAssembly only.