Skip to main content

AuthProvider

Trait AuthProvider 

pub trait AuthProvider:
    Clone
    + Send
    + Sync
    + 'static {
    type Error: Into<CratestackError> + Send;

    // Required method
    fn authenticate(
        &self,
        request: &RequestContext<'_>,
    ) -> impl Future<Output = Result<CratestackContext, Self::Error>> + Send;

    // Provided method
    fn credential<'r>(&self, request: &RequestContext<'r>) -> Credential<'r> { ... }
}
Expand description

Resolves the caller of a request into a CratestackContext.

Implement authenticate as a plain async fn returning Result<CratestackContext, Self::Error> — the impl Future + Send return type below is only how the trait spells “the future must be Send”, and an async fn in the impl satisfies it directly. For the synchronous, header-only case a Clone + Send + Sync closure Fn(&http::HeaderMap) -> Result<CratestackContext, E> already implements this trait (see the blanket impl below).

Required Associated Types§

Required Methods§

fn authenticate( &self, request: &RequestContext<'_>, ) -> impl Future<Output = Result<CratestackContext, Self::Error>> + Send

Provided Methods§

fn credential<'r>(&self, request: &RequestContext<'r>) -> Credential<'r>

Whether request carries this provider’s credential, read from the request head without authenticating (the body may be empty). The first-success chain skips a provider that answers [Credential::Absent]. The default, [Credential::Unknown], means the provider is always called, as before this method existed. See [Credential].

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementations on Foreign Types§

§

impl AuthProvider for SignedRequestAuthProvider

§

type Error = CratestackError

§

fn authenticate( &self, request: &RequestContext<'_>, ) -> impl Future<Output = Result<CratestackContext, <SignedRequestAuthProvider as AuthProvider>::Error>> + Send

Implementors§