pub struct Authenticator { /* private fields */ }Expand description
Owns the in-memory session and sends authenticated requests: bearer header, proactive and reactive refresh (single flight, persisted to the store), cross-process pickup, and the “session lost” state.
Implementations§
Source§impl Authenticator
impl Authenticator
Sourcepub fn new(
config: AuthConfig,
store: Arc<dyn SessionStore>,
session: Session,
clock: Arc<dyn Clock>,
) -> Result<Self, AuthError>
pub fn new( config: AuthConfig, store: Arc<dyn SessionStore>, session: Session, clock: Arc<dyn Clock>, ) -> Result<Self, AuthError>
An authenticator for session, which store holds.
Sourcepub fn from_store(
config: AuthConfig,
store: Arc<dyn SessionStore>,
clock: Arc<dyn Clock>,
) -> Result<Option<Self>, AuthError>
pub fn from_store( config: AuthConfig, store: Arc<dyn SessionStore>, clock: Arc<dyn Clock>, ) -> Result<Option<Self>, AuthError>
An authenticator for the session in store, or None when not
logged in.
Sourcepub fn status(&self) -> Receiver<AuthStatus>
pub fn status(&self) -> Receiver<AuthStatus>
Follows AuthStatus changes.
Sourcepub async fn refresh_client(&self) -> Option<RefreshClient>
pub async fn refresh_client(&self) -> Option<RefreshClient>
The client of this process’s last successful refresh, None before
one (AC19).
Sourcepub async fn get_json<T: DeserializeOwned>(
&self,
path: &str,
) -> Result<T, AuthError>
pub async fn get_json<T: DeserializeOwned>( &self, path: &str, ) -> Result<T, AuthError>
GET {api_base}{path} with the bearer token, decoded as JSON.
As Self::get, then any non-2xx status is an
AuthError::Http.
Sourcepub async fn get(
&self,
path: &str,
query: &[(&str, &str)],
timeout: Option<Duration>,
) -> Result<ApiResponse, AuthError>
pub async fn get( &self, path: &str, query: &[(&str, &str)], timeout: Option<Duration>, ) -> Result<ApiResponse, AuthError>
GET {api_base}{path}?{query} with the bearer token; the response
is returned whatever its status, with its body read.
Refreshes first when the token expires within 60 s, and once more on
a 401 before retrying once (AC5); a second 401 is
AuthError::Unauthorized. A 401 with subStatus
SUB_STATUS_NOT_AVAILABLE is not about the token: it is returned
as is, with no refresh and no retry (AC18). Fails fast with
AuthError::LoginRequired while the session is lost (AC7, AC9).
timeout bounds each HTTP request (none by default).
Sourcepub async fn send(
&self,
method: Method,
path: &str,
query: &[(&str, &str)],
form: Option<&[(&str, &str)]>,
headers: &[(&str, &str)],
timeout: Option<Duration>,
) -> Result<ApiResponse, AuthError>
pub async fn send( &self, method: Method, path: &str, query: &[(&str, &str)], form: Option<&[(&str, &str)]>, headers: &[(&str, &str)], timeout: Option<Duration>, ) -> Result<ApiResponse, AuthError>
{method} {api_base}{path}?{query} with the bearer token, an optional
form body (application/x-www-form-urlencoded) and extra request
headers; the refresh and 401 rules of Self::get apply, and the
response is returned whatever its status, headers included.