pub struct DataCloudToken { /* private fields */ }Expand description
Data Cloud JWT (DC JWT) for Hyper gRPC authentication.
Obtained by exchanging an OAuth Access Token at /services/a360/token.
Sent as the Authorization: Bearer <jwt> header with every gRPC call
to the Hyper query engine.
The DC JWT has a ~2-hour lifetime (exp claim), but is proactively
refreshed much earlier (every ~15 minutes by default) so that the
underlying OAuth Access Token is revalidated before Salesforce’s
server-side inactivity timeout can invalidate it.
Implementations§
Source§impl DataCloudToken
impl DataCloudToken
Sourcepub fn from_response(
response: DataCloudTokenResponse,
) -> SalesforceAuthResult<Self>
pub fn from_response( response: DataCloudTokenResponse, ) -> SalesforceAuthResult<Self>
Creates a DC JWT from a /services/a360/token response.
§Errors
- Returns
SalesforceAuthError::Authorizationifresponsecarries botherroranderror_descriptionfields. - Returns
SalesforceAuthError::TokenParseifresponse.access_tokenis empty, or ifresponse.instance_urlcannot be parsed as a URL (after prependinghttps://when the scheme is missing).
Sourcepub fn bearer_token(&self) -> String
pub fn bearer_token(&self) -> String
Returns the bearer token string for the Authorization header.
Format: "Bearer <dc_jwt>"
Sourcepub fn access_token(&self) -> &str
pub fn access_token(&self) -> &str
Returns just the DC JWT value (without the type prefix).
Sourcepub fn token_type(&self) -> &str
pub fn token_type(&self) -> &str
Returns the token type (e.g., “Bearer”).
Sourcepub fn tenant_url(&self) -> &Url
pub fn tenant_url(&self) -> &Url
Returns the Data Cloud tenant URL.
Sourcepub fn tenant_url_str(&self) -> &str
pub fn tenant_url_str(&self) -> &str
Returns the tenant URL as a string (for the audience gRPC header).
Sourcepub fn created_at(&self) -> DateTime<Utc>
pub fn created_at(&self) -> DateTime<Utc>
Returns when this DC JWT was obtained.
Sourcepub fn expires_at(&self) -> DateTime<Utc>
pub fn expires_at(&self) -> DateTime<Utc>
Returns the DC JWT expiration time.
Sourcepub fn remaining_lifetime(&self) -> Duration
pub fn remaining_lifetime(&self) -> Duration
Returns the remaining lifetime of this DC JWT.
Sourcepub fn is_valid(&self) -> bool
pub fn is_valid(&self) -> bool
Checks if the DC JWT is still valid (not expired).
Returns true if the DC JWT has at least 300 seconds (5 minutes) of
remaining lifetime. This buffer ensures callers never use a DC JWT
that is about to expire.
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
Checks if the DC JWT is expired.
Sourcepub fn needs_refresh(&self, threshold_secs: i64, max_age_secs: i64) -> bool
pub fn needs_refresh(&self, threshold_secs: i64, max_age_secs: i64) -> bool
Checks if the DC JWT should be proactively refreshed.
Mirrors the C++ IsDCJWTExpiringSoon logic: returns true when
either the DC JWT is near its hard expiry OR it has exceeded the
maximum age. This ensures:
- The OAuth Access Token is revalidated regularly (catching server-side inactivity timeouts)
- The DC JWT is replaced well before its ~2-hour hard expiry
§Arguments
threshold_secs- Refresh when the DC JWT has fewer than this many seconds remaining (default: 300 = 5 minutes)max_age_secs- Refresh when the DC JWT is older than this many seconds (default: 900 = 15 minutes)
Sourcepub fn tenant_id(&self) -> SalesforceAuthResult<String>
pub fn tenant_id(&self) -> SalesforceAuthResult<String>
Extracts the tenant ID from the DC JWT payload.
The tenant ID is stored in the audienceTenantId claim of the JWT.
§Errors
Returns SalesforceAuthError::TokenParse if:
- The JWT does not have exactly three dot-separated parts.
- The payload segment is not valid base64url (via
base64_url_decode). - The decoded payload is not valid JSON (via the
Fromconversion fromserde_json::Error). - The payload object is missing a string-valued
audienceTenantIdclaim.
Sourcepub fn lakehouse_name(
&self,
dataspace: Option<&str>,
) -> SalesforceAuthResult<String>
pub fn lakehouse_name( &self, dataspace: Option<&str>, ) -> SalesforceAuthResult<String>
Returns the lakehouse name for Hyper connection.
Format: "lakehouse:<tenant_id>;<dataspace>"
§Errors
Propagates any SalesforceAuthError::TokenParse from
Self::tenant_id (malformed JWT structure, non-base64url payload,
non-JSON payload, or missing audienceTenantId claim).
Trait Implementations§
Source§impl Clone for DataCloudToken
impl Clone for DataCloudToken
Source§fn clone(&self) -> DataCloudToken
fn clone(&self) -> DataCloudToken
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more