pub struct TokenManager { /* private fields */ }Expand description
Logs in and keeps the token fresh.
Refresh is single-flighted: concurrent callers that all observe a stale token
share one RefreshToken round-trip. Without that, N tasks would each present
the same single-use refresh token, one would win, and the rest would be told
their credential is invalid.
Implementations§
Source§impl TokenManager
impl TokenManager
Sourcepub const DEFAULT_SKEW: Duration
pub const DEFAULT_SKEW: Duration
Default refresh skew: refresh this long before actual expiry.
pub fn new(channel: Channel, meta: Metadata) -> Self
pub fn with_skew(channel: Channel, meta: Metadata, skew: Duration) -> Self
Sourcepub async fn login(
&self,
username: impl Into<String>,
password: impl Into<String>,
) -> Result<Token, Status>
pub async fn login( &self, username: impl Into<String>, password: impl Into<String>, ) -> Result<Token, Status>
Authenticate with username and password, storing the result.
Sourcepub async fn access_token(&self) -> Result<String, Status>
pub async fn access_token(&self) -> Result<String, Status>
The access token, refreshing first if it is stale.
Sourcepub async fn refresh(&self) -> Result<Token, Status>
pub async fn refresh(&self) -> Result<Token, Status>
Force a refresh. Holding the token lock across the RPC is what makes this single-flighted: a second caller waits and then observes the new token rather than presenting the spent one.
Sourcepub async fn authenticated_metadata(&self) -> Result<Metadata, Status>
pub async fn authenticated_metadata(&self) -> Result<Metadata, Status>
Metadata carrying the current access token, ready for a data-plane client.
Trait Implementations§
Source§impl Clone for TokenManager
impl Clone for TokenManager
Source§fn clone(&self) -> TokenManager
fn clone(&self) -> TokenManager
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl Debug for TokenManager
Hand-written rather than derived: a derived Debug would print the stored
access and refresh tokens, and this type is exactly the sort of thing that
ends up in a tracing field or a panic message.
impl Debug for TokenManager
Hand-written rather than derived: a derived Debug would print the stored
access and refresh tokens, and this type is exactly the sort of thing that
ends up in a tracing field or a panic message.
Auto Trait Implementations§
impl !RefUnwindSafe for TokenManager
impl !UnwindSafe for TokenManager
impl Freeze for TokenManager
impl Send for TokenManager
impl Sync for TokenManager
impl Unpin for TokenManager
impl UnsafeUnpin for TokenManager
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
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoRequest<T> for T
impl<T> IntoRequest<T> for T
Source§fn into_request(self) -> Request<T>
fn into_request(self) -> Request<T>
T in a tonic::Request