pub struct SharedTokenProvider { /* private fields */ }Expand description
Thread-safe wrapper around DataCloudTokenProvider.
Allows sharing the DC JWT provider between multiple tasks/threads
while ensuring exclusive access during token operations. All access
is protected by a tokio::sync::Mutex.
§Example
use hyperdb_api_salesforce::{SalesforceAuthConfig, AuthMode, SharedTokenProvider};
let provider = SharedTokenProvider::new(config)?;
// Can be cloned and shared between tasks
let provider_clone = provider.clone();
tokio::spawn(async move {
let dc_jwt = provider_clone.get_token().await.unwrap();
// use dc_jwt.bearer_token() as the Authorization header
});Implementations§
Sourcepub fn new(config: SalesforceAuthConfig) -> SalesforceAuthResult<Self>
pub fn new(config: SalesforceAuthConfig) -> SalesforceAuthResult<Self>
Creates a new shared DC JWT provider.
§Errors
Propagates any error from DataCloudTokenProvider::new:
configuration validation failures or HTTP client construction
failures (surfaced as SalesforceAuthError::Http).
Sourcepub async fn get_token(&self) -> SalesforceAuthResult<DataCloudToken>
pub async fn get_token(&self) -> SalesforceAuthResult<DataCloudToken>
Gets a valid DC JWT.
§Errors
Propagates any error from DataCloudTokenProvider::get_token
(HTTP failure, authorization rejection, JWT signing error, or
token-parse failure during the refresh cycle).
Sourcepub async fn refresh_token(&self) -> SalesforceAuthResult<DataCloudToken>
pub async fn refresh_token(&self) -> SalesforceAuthResult<DataCloudToken>
Forces a DC JWT refresh (reuses OAuth Access Token if still valid).
§Errors
Propagates any error from DataCloudTokenProvider::refresh_token.
Sourcepub async fn force_refresh(&self) -> SalesforceAuthResult<DataCloudToken>
pub async fn force_refresh(&self) -> SalesforceAuthResult<DataCloudToken>
Forces a full refresh (both OAuth Access Token and DC JWT).
§Errors
Propagates any error from DataCloudTokenProvider::force_refresh.
Sourcepub async fn bearer_token(&self) -> Option<String>
pub async fn bearer_token(&self) -> Option<String>
Returns the DC JWT bearer token string if a valid DC JWT is cached.
Sourcepub async fn tenant_url(&self) -> Option<String>
pub async fn tenant_url(&self) -> Option<String>
Returns the tenant URL if a valid DC JWT is cached.
Sourcepub async fn lakehouse_name(&self) -> SalesforceAuthResult<Option<String>>
pub async fn lakehouse_name(&self) -> SalesforceAuthResult<Option<String>>
Returns the lakehouse name for Hyper connection.
§Errors
Propagates SalesforceAuthError::TokenParse from
DataCloudTokenProvider::lakehouse_name if the cached DC JWT’s
tenant URL cannot be parsed into a valid lakehouse identifier.
Trait Implementations§
Source§fn clone(&self) -> SharedTokenProvider
fn clone(&self) -> SharedTokenProvider
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more