ic_auth_client/option.rs
1//! Authentication client options and configuration types.
2//!
3//! This module provides the main configuration structures for authentication flows,
4//! including login options and idle timeout handling.
5
6use crate::{
7 callback::{OnError, OnSuccess},
8 idle_manager::IdleManagerOptions,
9};
10
11#[cfg(feature = "native")]
12pub mod native;
13#[cfg(feature = "wasm-js")]
14pub mod wasm_js;
15
16/// Options for the [`AuthClient::login_with_options`].
17#[derive(Clone, Default, bon::Builder)]
18#[builder(on(String, into))]
19pub struct AuthClientLoginOptions {
20 /// The URL of the identity provider.
21 pub identity_provider: Option<String>,
22
23 /// Expiration of the authentication in nanoseconds.
24 pub max_time_to_live: Option<u64>,
25
26 /// If present, indicates whether or not the Identity Provider should allow the user to authenticate and/or register using a temporary key/PIN identity.
27 ///
28 /// Authenticating dapps may want to prevent users from using Temporary keys/PIN identities because Temporary keys/PIN identities are less secure than Passkeys (webauthn credentials) and because Temporary keys/PIN identities generally only live in a browser database (which may get cleared by the browser/OS).
29 pub allow_pin_authentication: Option<bool>,
30
31 /// Origin for Identity Provider to use while generating the delegated identity. For II, the derivation origin must authorize this origin by setting a record at `<derivation-origin>/.well-known/ii-alternative-origins`.
32 ///
33 /// See: <https://github.com/dfinity/internet-identity/blob/main/docs/ii-spec.mdx#alternative-frontend-origins>
34 pub derivation_origin: Option<String>,
35
36 /// Auth Window feature config string.
37 ///
38 /// # Example
39 /// ```ignore
40 /// toolbar=0,location=0,menubar=0,width=500,height=500,left=100,top=100
41 /// ```
42 pub window_opener_features: Option<String>,
43
44 /// Callback once login has completed.
45 #[builder(into)]
46 pub on_success: Option<OnSuccess>,
47
48 /// Callback in case authentication fails.
49 #[builder(into)]
50 pub on_error: Option<OnError>,
51
52 /// Timeout for the authentication process. If not provided, 5 minutes will be used.
53 pub timeout: Option<std::time::Duration>,
54
55 /// Extra values to be passed in the login request during the authorize-ready phase.
56 pub custom_values: Option<serde_json::Map<String, serde_json::Value>>,
57}
58
59/// Options for handling idle timeouts.
60#[derive(Default, Clone, Debug, bon::Builder)]
61pub struct IdleOptions {
62 /// If set to `true`, disables the idle timeout functionality.
63 pub disable_idle: Option<bool>,
64 /// If set to `true`, disables the default idle timeout callback.
65 pub disable_default_idle_callback: Option<bool>,
66 /// Options for the [`IdleManager`] that handles idle timeouts.
67 pub idle_manager_options: IdleManagerOptions,
68}