bitwarden_core/auth/api/request/
auth_request_token_request.rs1use bitwarden_api_api::Configuration;
2use serde::{Deserialize, Serialize};
3use uuid::Uuid;
4
5use crate::{
6 DeviceType,
7 auth::{api::response::IdentityTokenResponse, login::LoginError},
8};
9
10#[derive(Serialize, Deserialize)]
11pub(crate) struct AuthRequestTokenRequest {
12 scope: String,
13 client_id: String,
14 #[serde(rename = "deviceType")]
15 device_type: u8,
16 #[serde(rename = "deviceIdentifier")]
17 device_identifier: String,
18 #[serde(rename = "deviceName")]
19 device_name: String,
20 grant_type: String,
21 #[serde(rename = "username")]
22 email: String,
23 #[serde(rename = "authRequest")]
24 auth_request_id: Uuid,
25 #[serde(rename = "password")]
26 access_code: String,
27}
28
29#[allow(dead_code)]
30impl AuthRequestTokenRequest {
31 pub(crate) fn new(
32 email: &str,
33 auth_request_id: &Uuid,
34 access_code: &str,
35 device_type: DeviceType,
36 device_identifier: &str,
37 ) -> Self {
38 Self {
39 scope: "api offline_access".to_string(),
40 client_id: "web".to_string(),
41 device_type: device_type as u8,
42 device_identifier: device_identifier.to_string(),
43 device_name: "chrome".to_string(),
44 grant_type: "password".to_string(),
45 email: email.to_string(),
46 auth_request_id: *auth_request_id,
47 access_code: access_code.to_string(),
48 }
49 }
50
51 pub(crate) async fn send(
52 &self,
53 identity_config: &Configuration,
54 ) -> Result<IdentityTokenResponse, LoginError> {
55 super::send_identity_connect_request(identity_config, &self).await
56 }
57}