Skip to main content

AsyncAuth

Trait AsyncAuth 

Source
pub trait AsyncAuth:
    Send
    + Sync
    + 'static {
    // Required method
    fn resolve_async<'a>(&'a self, token: &'a str) -> AuthFuture<'a>;
}
Expand description

Resolves bearer tokens to Verifiable Identifiers, asynchronously — what the server calls.

Auth is the synchronous form, for a lookup that never waits (a token map, a JWT signature check), and every Auth is an AsyncAuth through the blanket implementation below, so an existing authenticator needs no change. Implement this trait instead when resolving a token must await — a session store, a token-introspection endpoint, a database — rather than blocking an executor thread inside Auth::resolve.

The method is named resolve_async rather than resolve so that a type implementing Auth (and so, through the blanket impl, this trait) is never ambiguous to call with both traits in scope.

ⓘ
use trust_tasks_https::{AsyncAuth, AuthFuture};

struct SessionAuth { store: SessionStore }

impl AsyncAuth for SessionAuth {
    fn resolve_async<'a>(&'a self, token: &'a str) -> AuthFuture<'a> {
        Box::pin(async move { self.store.vid_for(token).await.ok().flatten() })
    }
}

Resolution runs on every request before any framework check, so it should fail closed (None) and quickly; bound any network call it makes.

Required Methods§

Source

fn resolve_async<'a>(&'a self, token: &'a str) -> AuthFuture<'a>

Resolve token to a VID, or None if the token is unknown.

Dyn Compatibility§

This trait is dyn compatible.

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

Implementors§

Source§

impl<A: Auth> AsyncAuth for A