Skip to main content

comdirect_rest_api/oauth2/
config.rs

1use std::fmt;
2use std::future::Future;
3use std::pin::Pin;
4use std::sync::Arc;
5
6/// Configuration required to authenticate with the Comdirect REST API.
7#[derive(Clone)]
8pub struct ComdirectConfig {
9    /// The username or zugangsnummer.
10    pub user: String,
11    /// The password or PIN.
12    pub password: String,
13    /// The OAuth2 Client ID provided by Comdirect.
14    pub client_id: String,
15    /// The OAuth2 Client Secret provided by Comdirect.
16    pub client_secret: String,
17    /// Optional callback invoked whenever a new refresh token is obtained.
18    /// This allows the consumer to persist the token for future sessions.
19    pub on_refresh_token: Option<Arc<dyn Fn(String) + Send + Sync>>,
20    /// Async callback invoked when a Push-TAN challenge is triggered.
21    /// The session creation will wait for this callback to complete before starting its internal timer.
22    pub on_awaits_user_confirm:
23        Arc<dyn Fn() -> Pin<Box<dyn Future<Output = ()> + Send>> + Send + Sync>,
24}
25
26impl fmt::Debug for ComdirectConfig {
27    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28        f.debug_struct("ComdirectConfig")
29            .field("user", &self.user)
30            .field("client_id", &self.client_id)
31            .field("has_password", &!self.password.is_empty())
32            .field("has_client_secret", &!self.client_secret.is_empty())
33            .field("has_refresh_callback", &self.on_refresh_token.is_some())
34            .finish()
35    }
36}