Skip to main content

AuthSession

Trait AuthSession 

Source
pub trait AuthSession: Send + Sync {
    // Required methods
    fn access_token<'life0, 'async_trait>(
        &'life0 self,
    ) -> Pin<Box<dyn Future<Output = AuthResult<Cow<'_, str>>> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait;
    fn instance_url(&self) -> &str;

    // Provided method
    fn invalidate<'life0, 'life1, 'async_trait>(
        &'life0 self,
        stale_token: &'life1 str,
    ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
       where Self: 'async_trait,
             'life0: 'async_trait,
             'life1: 'async_trait { ... }
}
Expand description

Abstraction over a Salesforce authentication session.

An implementation holds whatever credentials the chosen flow needs, produces a bearer access token on demand (refreshing if necessary), and reports the instance URL that REST requests should target.

The trait is Send + Sync and uses async_trait to remain dyn-compatible — the client stores Arc<dyn AuthSession> so handlers don’t care which flow was configured.

Required Methods§

Source

fn access_token<'life0, 'async_trait>( &'life0 self, ) -> Pin<Box<dyn Future<Output = AuthResult<Cow<'_, str>>> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait,

Returns a valid bearer access token. Implementations may refresh expired tokens transparently here; that is why the method is async.

Source

fn instance_url(&self) -> &str

Returns the instance URL for REST requests, e.g. https://my-org.my.salesforce.com. No trailing slash.

Provided Methods§

Source

fn invalidate<'life0, 'life1, 'async_trait>( &'life0 self, stale_token: &'life1 str, ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where Self: 'async_trait, 'life0: 'async_trait, 'life1: 'async_trait,

Invalidates a cached token that the SDK has determined is no longer valid (typically because Salesforce returned 401 INVALID_SESSION_ID when it was used).

The next access_token call should mint a fresh token. The stale_token parameter lets implementations compare-and-swap — only clear the cache if the cached value still matches what the caller actually used. This avoids blowing away a newer token that another concurrent task may have refreshed in the meantime.

Default impl is a no-op for static or stateless sessions (StaticTokenAuth) where there is nothing to invalidate. Stateful flows (JwtAuth, RefreshTokenAuth, ClientCredentialsAuth) override to clear their cached token.

stale_token is borrowed for the duration of the call only — implementations should compare it against their cached value and not retain it.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§