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
use serde::{Deserialize, Serialize};

/// MFA request/response data
#[derive(Serialize, Deserialize, Debug, Clone)]
#[serde(untagged)]
pub enum MFAData {
    Password { password: String },
    Recovery { recovery_code: String },
    Totp { totp_code: String },
}

/// MFA method
#[derive(Deserialize, Debug, Clone, Eq, PartialEq)]
pub enum MFAMethod {
    Password,
    Recovery,
    Totp,
}

/// MFA recovery code
pub type MFARecoveryCode = String;

/// MFA status
#[derive(Deserialize, Debug, Clone)]
pub struct MFAStatus {
    pub email_otp: bool,
    pub trusted_handover: bool,
    pub email_mfa: bool,
    pub totp_mfa: bool,
    pub security_key_mfa: bool,
    pub recovery_active: bool,
}

/// TOTP secret response
#[derive(Deserialize, Debug, Clone)]
pub struct TOTPSecret {
    pub secret: String,
}

/// Multi-factor auth ticket
#[derive(Deserialize, Debug, Clone)]
pub struct MFATicket {
    /// Unique Id
    #[serde(rename = "_id")]
    pub id: String,

    /// Account Id
    pub account_id: String,

    /// Unique Token
    pub token: String,

    /// Whether this ticket has been validated
    /// (can be used for account actions)
    pub validated: bool,

    /// Whether this ticket is authorised
    /// (can be used to log a user in)
    pub authorised: bool,

    /// TOTP code at time of ticket creation
    pub last_totp_code: Option<String>,
}