1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
use ;
use *;
/// Client for authenticating Bitwarden users.
///
/// Handles unauthenticated operations to obtain access tokens from the Identity API.
/// After successful authentication, use the returned tokens to create an authenticated core client.
///
/// # Lifecycle
///
/// 1. Create `LoginClient` via `AuthClient`
/// 2. Call login method
/// 3. Use returned tokens with authenticated core client
///
/// # Password Login Example
///
/// ```rust,no_run
/// # use bitwarden_auth::{AuthClient, login::login_via_password::PasswordLoginRequest};
/// # use bitwarden_auth::login::models::{LoginRequest, LoginDeviceRequest, LoginResponse};
/// # use bitwarden_core::{Client, ClientSettings, DeviceType};
/// # async fn example(email: String, password: String) -> Result<(), Box<dyn std::error::Error>> {
/// // Create auth client
/// let client = Client::new(None);
/// let auth_client = AuthClient::new(client);
///
/// // Configure client settings and create login client
/// let settings = ClientSettings {
/// identity_url: "https://identity.bitwarden.com".to_string(),
/// api_url: "https://api.bitwarden.com".to_string(),
/// user_agent: "MyApp/1.0".to_string(),
/// device_type: DeviceType::SDK,
/// device_identifier: None,
/// bitwarden_client_version: None,
/// bitwarden_package_type: None,
/// };
/// let login_client = auth_client.login(settings);
///
/// // Get user's KDF config
/// let prelogin = login_client.get_password_prelogin(email.clone()).await?;
///
/// // Login with credentials
/// let response = login_client.login_via_password(PasswordLoginRequest {
/// login_request: LoginRequest {
/// client_id: "connector".to_string(),
/// device: LoginDeviceRequest {
/// device_type: DeviceType::SDK,
/// device_identifier: "device-id".to_string(),
/// device_name: "My Device".to_string(),
/// device_push_token: None,
/// },
/// },
/// email,
/// password,
/// prelogin_response: prelogin,
/// }).await?;
///
/// // Use tokens from response for authenticated requests
/// match response {
/// LoginResponse::Authenticated(success) => {
/// let access_token = success.access_token;
/// // Use access_token for authenticated requests
/// }
/// }
/// # Ok(())
/// # }
/// ```