pub trait AuthProvider:
Send
+ Sync
+ Debug {
// Required methods
fn credential<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Credential, FaucetError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
Self: 'async_trait;
fn provider_name(&self) -> &'static str;
// Provided methods
fn invalidate<'life0, 'life1, 'async_trait>(
&'life0 self,
_stale: &'life1 Credential,
) -> Pin<Box<dyn Future<Output = Result<Credential, FaucetError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait { ... }
fn sign_request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_method: &'life1 str,
_url: &'life2 str,
_query: &'life3 BTreeMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<Option<Credential>, FaucetError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn request_auth<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_method: &'life1 str,
_url: &'life2 str,
_query: &'life3 BTreeMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<RequestAuth, FaucetError>> + Send + 'async_trait>>
where 'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait { ... }
fn reauth_statuses(&self) -> &[u16] { ... }
}Expand description
A live, shareable source of credentials.
One instance is shared (via Arc) across all connectors that reference it,
giving single-flight refresh: concurrent callers during a refresh await the
one in-flight fetch rather than each refreshing independently.
Object-safe — no generics or associated types, so it can be held as
Arc<dyn AuthProvider> (SharedAuthProvider).
Required Methods§
Sourcefn credential<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Credential, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
fn credential<'life0, 'async_trait>(
&'life0 self,
) -> Pin<Box<dyn Future<Output = Result<Credential, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
Self: 'async_trait,
Return a currently-valid credential, refreshing if needed.
Sourcefn provider_name(&self) -> &'static str
fn provider_name(&self) -> &'static str
Stable, non-empty name for diagnostics and metrics.
Provided Methods§
Sourcefn invalidate<'life0, 'life1, 'async_trait>(
&'life0 self,
_stale: &'life1 Credential,
) -> Pin<Box<dyn Future<Output = Result<Credential, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
fn invalidate<'life0, 'life1, 'async_trait>(
&'life0 self,
_stale: &'life1 Credential,
) -> Pin<Box<dyn Future<Output = Result<Credential, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
Self: 'async_trait,
Force a refresh iff the cached credential still equals stale
(compare-and-swap). Multiple connectors that hit a 401 with the same
token collapse into a single refresh; callers holding an already-rotated
token get the new one without triggering another fetch.
The default delegates to AuthProvider::credential; providers that
support refresh override it.
Sourcefn sign_request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_method: &'life1 str,
_url: &'life2 str,
_query: &'life3 BTreeMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<Option<Credential>, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn sign_request<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_method: &'life1 str,
_url: &'life2 str,
_query: &'life3 BTreeMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<Option<Credential>, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Per-request signing hook (OAuth1 and similar, #496).
Most providers issue a reusable credential via credential;
they return Ok(None) here (the default) and the connector applies the
cached credential. A provider that must sign each request individually
(e.g. OAuth1, whose signature covers the HTTP method, URL, and query
parameters) overrides this to compute a fresh Credential — typically a
Credential::Header carrying the Authorization signature — from the
request. When it returns Some, the connector uses it instead of
credential() for that request.
query is the request’s query parameters (the connector’s, before the
HTTP client appends them), which OAuth1 folds into its signature base
string. Object-safe: no generics, all args are borrowed primitives.
Sourcefn request_auth<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_method: &'life1 str,
_url: &'life2 str,
_query: &'life3 BTreeMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<RequestAuth, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
fn request_auth<'life0, 'life1, 'life2, 'life3, 'async_trait>(
&'life0 self,
_method: &'life1 str,
_url: &'life2 str,
_query: &'life3 BTreeMap<String, String>,
) -> Pin<Box<dyn Future<Output = Result<RequestAuth, FaucetError>> + Send + 'async_trait>>where
'life0: 'async_trait,
'life1: 'async_trait,
'life2: 'async_trait,
'life3: 'async_trait,
Self: 'async_trait,
Richer per-request auth for multi-step flows (#511): credential placements across header / query / cookie / body plus an optional dynamic base-URL override.
Most providers issue a single Credential and return an empty
RequestAuth here (the default); the connector then applies the plain
credential path. A provider that must place a
captured value somewhere other than a header, place several values at
once, or redirect the request to a captured base-URL overrides this. When
it returns a non-is_empty value, the connector
applies the placements instead of credential() for that request.
query is the request’s query parameters before the HTTP client appends
them (some flows fold them into a signature). Object-safe: no generics,
all args are borrowed primitives.
Sourcefn reauth_statuses(&self) -> &[u16]
fn reauth_statuses(&self) -> &[u16]
HTTP status codes on which the connector should force a re-auth
(via invalidate) and retry the request once.
The default is empty — connectors keep their built-in 401 handling.
A multi-step flow (#511) whose session cookie/token can expire mid-run
returns the statuses (e.g. [401], [401, 403]) that mean “log in again”.
Dyn Compatibility§
This trait is dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".