Skip to main content

Session

Struct Session 

Source
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};
use std::io::{self, Write};

let session = Session::new("client-id", "client-secret", "username", "pin")?;

session
    .login(|challenge| async move {
        println!("challenge {}", challenge.challenge_id);
        println!("Approve the Push-TAN in your Comdirect app first.");
        print!("Press Enter after approval... ");
        let _ = io::stdout().flush();
        let mut line = String::new();
        let _ = io::stdin().read_line(&mut line);
        TanAction::ConfirmPushTan
    })
    .await?;

let balances = session.accounts().get_balances().await?;
println!("{} accounts", balances.values.len());

Implementations§

Source§

impl Session

Source

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.

Source

pub fn from_config(config: SessionConfig) -> Result<Self>

Creates a session from explicit SessionConfig.

Source

pub fn accounts(&self) -> AccountsApi

Returns a copyable endpoint client for account operations.

Source

pub fn brokerage(&self) -> BrokerageApi

Returns a copyable endpoint client for brokerage operations.

Source

pub async fn set_state_change_callback<F>(&self, callback: F)
where F: Fn(SessionStateType, SessionStateType) + Send + Sync + 'static,

Registers a callback invoked on session state transitions.

Source

pub async fn set_refresh_token_callback<F>(&self, callback: F)
where F: Fn(String) + Send + Sync + 'static,

Registers a callback invoked whenever a new refresh token is issued.

Source

pub async fn state(&self) -> SessionStateType

Reads the current authorization state.

Source

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.

Source

pub async fn login<F, Fut>(&self, callback: F) -> Result<()>
where F: Fn(LoginChallenge) -> Fut + Send + Sync, Fut: Future<Output = TanAction> + Send,

Performs interactive login and asks the callback how to answer TAN challenges.

The callback is awaited before TAN completion is submitted. For ConfirmPushTan, return only after the user has actually confirmed the challenge externally (for example via a frontend “I’ve allowed it” action).

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.

Source

pub async fn shutdown(&self)

Stops background refresh tasks and marks the session unauthorized.

Call this before process shutdown to ensure refresh workers are cancelled deterministically.

Trait Implementations§

Source§

impl Clone for Session

Source§

fn clone(&self) -> Session

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> PolicyExt for T
where T: ?Sized,

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more