Struct tame_oauth::token_cache::CachedTokenProvider
source · pub struct CachedTokenProvider<P> { /* private fields */ }
Expand description
Wraps a TokenProvider
in a cache, only invokes the inner TokenProvider
if
the token in cache is expired, or if it doesn’t exist.
Implementations§
source§impl CachedTokenProvider<EndUserCredentialsInner>
impl CachedTokenProvider<EndUserCredentialsInner>
pub fn new(info: EndUserCredentialsInfo) -> Self
source§impl CachedTokenProvider<ServiceAccountProviderInner>
impl CachedTokenProvider<ServiceAccountProviderInner>
pub fn new(info: ServiceAccountInfo) -> Result<Self, Error>
sourcepub fn get_account_info(&self) -> &ServiceAccountInfo
pub fn get_account_info(&self) -> &ServiceAccountInfo
Gets the ServiceAccountInfo
this was created for
source§impl CachedTokenProvider<TokenProviderWrapperInner>
impl CachedTokenProvider<TokenProviderWrapperInner>
sourcepub fn get_default_provider() -> Result<Option<Self>, Error>
pub fn get_default_provider() -> Result<Option<Self>, Error>
Get a TokenProvider
following the “Google Default Credentials”
flow, in order:
-
If the
GOOGLE_APPLICATION_CREDENTIALS
environment variable is set, use that as a path to aServiceAccountInfo
. -
Check for a gcloud’s Application Default Credentials for
EndUserCredentials
-
If we’re running on GCP, use the local metadata server.
-
Otherwise, return None.
If it appears that a method is being used, but is actually invalid,
eg GOOGLE_APPLICATION_CREDENTIALS
is set but the file doesn’t exist or
contains invalid JSON, an error is returned with the details
pub fn is_service_account_provider(&self) -> bool
pub fn is_metadata_server_provider(&self) -> bool
pub fn is_end_user_credentials_provider(&self) -> bool
Trait Implementations§
source§impl<P: Debug> Debug for CachedTokenProvider<P>
impl<P: Debug> Debug for CachedTokenProvider<P>
source§impl<P> IdTokenProvider for CachedTokenProvider<P>where
P: IdTokenProvider,
impl<P> IdTokenProvider for CachedTokenProvider<P>where
P: IdTokenProvider,
source§fn get_id_token(&self, audience: &str) -> Result<IdTokenOrRequest, Error>
fn get_id_token(&self, audience: &str) -> Result<IdTokenOrRequest, Error>
Attempts to retrieve an id token that can be used when communicating via IAP etc.
source§fn get_id_token_with_access_token<S>(
&self,
audience: &str,
response: AccessTokenResponse<S>
) -> Result<IdTokenRequest, Error>
fn get_id_token_with_access_token<S>( &self, audience: &str, response: AccessTokenResponse<S> ) -> Result<IdTokenRequest, Error>
Some token sources require a access token to be used to generte a id token.
If
get_id_token
returns a AccessTokenResponse
, this method should be called.source§impl<P> TokenProvider for CachedTokenProvider<P>where
P: TokenProvider,
impl<P> TokenProvider for CachedTokenProvider<P>where
P: TokenProvider,
source§fn get_token_with_subject<'a, S, I, T>(
&self,
subject: Option<T>,
scopes: I
) -> Result<TokenOrRequest, Error>
fn get_token_with_subject<'a, S, I, T>( &self, subject: Option<T>, scopes: I ) -> Result<TokenOrRequest, Error>
Like
TokenProvider::get_token
, but allows the JWT
“subject”
to be passed in.source§fn parse_token_response<S>(
&self,
hash: u64,
response: Response<S>
) -> Result<Token, Error>
fn parse_token_response<S>( &self, hash: u64, response: Response<S> ) -> Result<Token, Error>
Once a response has been received for a token request, call this method
to deserialize the token (and potentially store it in a local cache for
reuse until it expires).
source§fn get_token<'a, S, I>(&self, scopes: I) -> Result<TokenOrRequest, Error>
fn get_token<'a, S, I>(&self, scopes: I) -> Result<TokenOrRequest, Error>
Attempts to retrieve a token that can be used in an API request, if we
haven’t already retrieved a token for the specified scopes, or the token
has expired, an HTTP request is returned that can be used to retrieve a
token. Read more
Auto Trait Implementations§
impl<P> !Freeze for CachedTokenProvider<P>
impl<P> RefUnwindSafe for CachedTokenProvider<P>where
P: RefUnwindSafe,
impl<P> Send for CachedTokenProvider<P>where
P: Send,
impl<P> Sync for CachedTokenProvider<P>where
P: Sync,
impl<P> Unpin for CachedTokenProvider<P>where
P: Unpin,
impl<P> UnwindSafe for CachedTokenProvider<P>where
P: UnwindSafe,
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
Mutably borrows from an owned value. Read more