pub struct Session { /* private fields */ }Expand description
Stateful comdirect API session with automatic token refresh.
The session encapsulates auth orchestration, transient-error retries, background refresh supervision, and endpoint access.
§Example
use comdirect_rest_api::{Session, TanAction};
let session = Session::new("client-id", "client-secret", "username", "pin")?;
session
.login(|challenge| async move {
println!("challenge {}", challenge.challenge_id);
TanAction::ConfirmPushTan
})
.await?;
let balances = session.accounts().get_balances().await?;
println!("{} accounts", balances.values.len());Implementations§
Source§impl Session
impl Session
Sourcepub fn new(
client_id: impl Into<String>,
client_secret: impl Into<String>,
username: impl Into<String>,
password: impl Into<String>,
) -> Result<Self>
pub fn new( client_id: impl Into<String>, client_secret: impl Into<String>, username: impl Into<String>, password: impl Into<String>, ) -> Result<Self>
Creates a session using default runtime settings.
Sourcepub fn from_config(config: SessionConfig) -> Result<Self>
pub fn from_config(config: SessionConfig) -> Result<Self>
Creates a session from explicit SessionConfig.
Sourcepub fn accounts(&self) -> AccountsApi
pub fn accounts(&self) -> AccountsApi
Returns a copyable endpoint client for account operations.
Sourcepub fn brokerage(&self) -> BrokerageApi
pub fn brokerage(&self) -> BrokerageApi
Returns a copyable endpoint client for brokerage operations.
Sourcepub async fn set_state_change_callback<F>(&self, callback: F)
pub async fn set_state_change_callback<F>(&self, callback: F)
Registers a callback invoked on session state transitions.
Sourcepub async fn set_refresh_token_callback<F>(&self, callback: F)
pub async fn set_refresh_token_callback<F>(&self, callback: F)
Registers a callback invoked whenever a new refresh token is issued.
Sourcepub async fn state(&self) -> SessionStateType
pub async fn state(&self) -> SessionStateType
Reads the current authorization state.
Sourcepub async fn try_restore(&self, refresh_token: &str) -> Result<()>
pub async fn try_restore(&self, refresh_token: &str) -> Result<()>
Performs non-interactive login using a persisted refresh token.
This is the preferred startup path for long-running services because it avoids interactive TAN prompts during cold start.
Sourcepub async fn login<F, Fut>(&self, callback: F) -> Result<()>
pub async fn login<F, Fut>(&self, callback: F) -> Result<()>
Performs interactive login and asks the callback how to answer TAN challenges.
Use this for initial bootstrap of refresh tokens. Persist the refresh
token from set_refresh_token_callback and switch to Self::try_restore
for subsequent restarts.