bitwarden_core/auth/api/response/
identity_success_response.rs

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
use std::{collections::HashMap, num::NonZeroU32};

use bitwarden_api_identity::models::KdfType;
use serde::{Deserialize, Serialize};
use serde_json::Value;

#[derive(Serialize, Deserialize, Debug, PartialEq)]
pub struct IdentityTokenSuccessResponse {
    pub access_token: String,
    pub expires_in: u64,
    pub refresh_token: Option<String>,
    token_type: String,

    #[serde(rename = "privateKey", alias = "PrivateKey")]
    pub(crate) private_key: Option<String>,
    #[serde(alias = "Key")]
    pub(crate) key: Option<String>,
    #[serde(rename = "twoFactorToken")]
    two_factor_token: Option<String>,
    #[serde(alias = "Kdf")]
    kdf: KdfType,
    #[serde(
        rename = "kdfIterations",
        alias = "KdfIterations",
        default = "bitwarden_crypto::default_pbkdf2_iterations"
    )]
    kdf_iterations: NonZeroU32,

    #[serde(rename = "resetMasterPassword", alias = "ResetMasterPassword")]
    pub reset_master_password: bool,
    #[serde(rename = "forcePasswordReset", alias = "ForcePasswordReset")]
    pub force_password_reset: bool,
    #[serde(rename = "apiUseKeyConnector", alias = "ApiUseKeyConnector")]
    api_use_key_connector: Option<bool>,
    #[serde(rename = "keyConnectorUrl", alias = "KeyConnectorUrl")]
    key_connector_url: Option<String>,

    /// Stores unknown api response fields
    extra: Option<HashMap<String, Value>>,
}

#[cfg(test)]
mod test {
    use bitwarden_crypto::default_pbkdf2_iterations;

    use super::*;

    impl Default for IdentityTokenSuccessResponse {
        fn default() -> Self {
            Self {
                access_token: Default::default(),
                expires_in: Default::default(),
                refresh_token: Default::default(),
                token_type: Default::default(),
                private_key: Default::default(),
                key: Default::default(),
                two_factor_token: Default::default(),
                kdf: KdfType::default(),
                kdf_iterations: default_pbkdf2_iterations(),
                reset_master_password: Default::default(),
                force_password_reset: Default::default(),
                api_use_key_connector: Default::default(),
                key_connector_url: Default::default(),
                extra: Default::default(),
            }
        }
    }
}