pub(crate) struct SessionManager {
state: Mutex<SessionState>,
identity: IdentityClient,
token: AccessToken,
}Expand description
Manages the connector session lifecycle. All mutable state sits behind one async Mutex, so at
most one renewal is in flight. Debug is hand-written to avoid leaking the token or bearer.
Fields§
§state: Mutex<SessionState>§identity: IdentityClient§token: AccessTokenImplementations§
Source§impl SessionManager
impl SessionManager
Sourcepub(crate) async fn new(
identity: IdentityClient,
token: AccessToken,
key_store: KeyStore<KeySlotIds>,
) -> Result<Arc<Self>, SessionError>
pub(crate) async fn new( identity: IdentityClient, token: AccessToken, key_store: KeyStore<KeySlotIds>, ) -> Result<Arc<Self>, SessionError>
Build the manager and authenticate. A rejected credential returns
Err(SessionError::Lost(Revoked)), which callers treat as a fatal startup failure.
key_store is the client’s, which the org key is installed into.
pub(crate) async fn phase(&self) -> SessionPhase
Sourcepub(crate) async fn organization_id(&self) -> Option<OrganizationId>
pub(crate) async fn organization_id(&self) -> Option<OrganizationId>
None only before the first authentication, which Self::new has already performed.
Sourcepub(crate) async fn bearer(
&self,
deadline: Option<Instant>,
) -> Result<String, SessionError>
pub(crate) async fn bearer( &self, deadline: Option<Instant>, ) -> Result<String, SessionError>
Obtain a valid bearer, renewing as needed. Retries transient errors with capped backoff up
to deadline (NO_DEADLINE_MAX_TRIES caps a None deadline); a rejected credential
clears secrets and returns Err(Lost(Revoked)).
Sourcepub(crate) async fn force_refresh(
&self,
stale: &str,
deadline: Option<Instant>,
) -> Result<String, SessionError>
pub(crate) async fn force_refresh( &self, stale: &str, deadline: Option<Instant>, ) -> Result<String, SessionError>
Force a session refresh on the 401 path. A bearer that no longer matches stale was already
renewed concurrently and is returned as-is, as in bitwarden-auth’s resolve_retry.
Sourceasync fn renew_with_backoff(
&self,
deadline: Option<Instant>,
stale: Option<&str>,
) -> Result<String, SessionError>
async fn renew_with_backoff( &self, deadline: Option<Instant>, stale: Option<&str>, ) -> Result<String, SessionError>
Return the stored bearer if it is fresh and not stale, otherwise renew with backoff. The
check runs under the same guard as the renewal, so concurrent callers coalesce onto one
renewal and a concurrent close() cannot slip in between. The mutex is held across the
identity call and released during the backoff sleep.
Trait Implementations§
Auto Trait Implementations§
impl !Freeze for SessionManager
impl !RefUnwindSafe for SessionManager
impl !UnwindSafe for SessionManager
impl Send for SessionManager
impl Sync for SessionManager
impl Unpin for SessionManager
impl UnsafeUnpin for SessionManager
Blanket Implementations§
§impl<T> AnySync for T
impl<T> AnySync for T
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
§impl<T> CompatExt for T
impl<T> CompatExt for T
§impl<T, UT> HandleAlloc<UT> for T
impl<T, UT> HandleAlloc<UT> for T
§fn new_handle(value: Arc<T>) -> Handle
fn new_handle(value: Arc<T>) -> Handle
§unsafe fn clone_handle(handle: Handle) -> Handle
unsafe fn clone_handle(handle: Handle) -> Handle
§unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
unsafe fn consume_handle(handle: Handle) -> Arc<T> ⓘ
Arc<> Read more§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more