cyaxon_authifier/models/mfa/mod.rs
1use self::totp::Totp;
2
3pub mod totp;
4
5/// Whether a boolean is false
6// fn is_false(t: &bool) -> bool {
7// !t
8// }
9
10/// MFA configuration
11#[derive(Default, Debug, Serialize, Deserialize, Clone)]
12pub struct MultiFactorAuthentication {
13 /// Allow password-less email OTP login
14 /// (1-Factor)
15 // #[serde(skip_serializing_if = "is_false", default)]
16 // pub enable_email_otp: bool,
17
18 /// Allow trusted handover
19 /// (1-Factor)
20 // #[serde(skip_serializing_if = "is_false", default)]
21 // pub enable_trusted_handover: bool,
22
23 /// Allow email MFA
24 /// (2-Factor)
25 // #[serde(skip_serializing_if = "is_false", default)]
26 // pub enable_email_mfa: bool,
27
28 /// TOTP MFA token, enabled if present
29 /// (2-Factor)
30 #[serde(skip_serializing_if = "Totp::is_empty", default)]
31 pub totp_token: Totp,
32
33 /// Security Key MFA token, enabled if present
34 /// (2-Factor)
35 // #[serde(skip_serializing_if = "Option::is_none")]
36 // pub security_key_token: Option<String>,
37
38 /// Recovery codes
39 #[serde(skip_serializing_if = "Vec::is_empty", default)]
40 pub recovery_codes: Vec<String>,
41}
42
43/// MFA method
44#[derive(Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
45#[cfg_attr(feature = "schemas", derive(JsonSchema))]
46pub enum MFAMethod {
47 Password,
48 Recovery,
49 Totp,
50}
51
52/// MFA response
53#[derive(Debug, Serialize, Deserialize)]
54#[cfg_attr(feature = "schemas", derive(JsonSchema))]
55#[serde(untagged)]
56pub enum MFAResponse {
57 Password { password: String },
58 Recovery { recovery_code: String },
59 Totp { totp_code: String },
60}