pub struct TokenCache { /* private fields */ }Expand description
Thread-safe OAuth2 access-token cache with on-demand refresh.
Implementations§
Source§impl TokenCache
impl TokenCache
Sourcepub fn new(
config: OAuth2ExchangeConfig,
tls_connector: TlsConnector,
) -> Result<Self>
pub fn new( config: OAuth2ExchangeConfig, tls_connector: TlsConnector, ) -> Result<Self>
Create a new cache and perform the initial token exchange.
Called during CredentialStore::load()
which is synchronous. We bridge into async via
[tokio::runtime::Handle::current().block_on()].
§Errors
Returns ProxyError::OAuth2Exchange if the initial exchange fails
(DNS, TCP, TLS, non-200, malformed JSON). The calling code skips the
route so the proxy can still start for other routes.
Sourcepub async fn get_or_refresh(&self) -> Zeroizing<String>
pub async fn get_or_refresh(&self) -> Zeroizing<String>
Return a valid access token, refreshing if needed.
If the cached token is still valid (expires > 30 s from now), returns the cached value without any network call.
If expired, attempts one exchange. On failure, returns the stale token with a warning — better to try a possibly-expired token than to fail the request outright.