pub struct Session { /* private fields */ }Expand description
An authenticated session. Cheaply cloneable — every clone shares one token store and one single-flight gate, so refreshes coalesce across clones and tasks.
Implementations§
Source§impl Session
impl Session
Sourcepub fn with_http_client(&self, http: Client) -> Self
pub fn with_http_client(&self, http: Client) -> Self
This session — the same token store and refresh gate — sending through http instead.
How a transfer leaves a path behind: a new path generation builds a new client
(GenerationPool), and requests sent through it never
ride a connection pooled on the old path. http must come from
crate::net::http_builder or crate::net::http_client, so it carries the handshake.
Sourcepub async fn is_authenticated(&self) -> bool
pub async fn is_authenticated(&self) -> bool
Whether the session currently holds tokens.
Sourcepub async fn export(&self) -> Option<PersistedSession>
pub async fn export(&self) -> Option<PersistedSession>
Snapshot the token material for the platform’s secure storage. None if the
session has been logged out.
Sourcepub async fn execute<F>(&self, build: F) -> Result<Response, AuthError>where
F: Fn(&Client) -> RequestBuilder,
pub async fn execute<F>(&self, build: F) -> Result<Response, AuthError>where
F: Fn(&Client) -> RequestBuilder,
Run an authenticated request, injecting the bearer token and recovering from
a 401 by refreshing once and replaying.
build is the caller’s un-authenticated request (path, method, body); the
SDK adds the Authorization header, so callers never see the token. build
is invoked again for the retry, so the request is reconstructed with the
fresh token (no body-clone requirement).
Sourcepub async fn refresh(&self) -> Result<(), AuthError>
pub async fn refresh(&self) -> Result<(), AuthError>
Force a refresh now (single-flight). A no-op on the wire if a concurrent caller already rotated the token.
Sourcepub async fn logout(&self) -> Result<(), AuthError>
pub async fn logout(&self) -> Result<(), AuthError>
Revoke the session server-side and clear the local store. Idempotent: a server that no longer honors the token (or an already-empty store) still resolves to a cleared, logged-out session.
Sourcepub async fn bearer(&self) -> Result<SecretString, AuthError>
pub async fn bearer(&self) -> Result<SecretString, AuthError>
A currently-valid bearer access token for injecting into a request the
SDK does not build with Session::execute — notably the generated REST client’s
token-provider seam (crate::client::AuthenticatedClient), where the token is
attached by the client rather than by this module. Pre-flight-refreshes exactly like
Session::execute; the reactive half — a 401 the pre-flight check could not
foresee — is refresh_rejected’s.
Trait Implementations§
Auto Trait Implementations§
impl !RefUnwindSafe for Session
impl !UnwindSafe for Session
impl Freeze for Session
impl Send for Session
impl Sync for Session
impl Unpin for Session
impl UnsafeUnpin for Session
Blanket Implementations§
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§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>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> 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