feat: add Request/Response objects for MFA verification endpoints

This commit is contained in:
xystrive 2024-07-25 13:12:13 +01:00
parent 317dbe1ed1
commit 530ed90171
No known key found for this signature in database
GPG Key ID: 5EC5BBA34DEE94B7
2 changed files with 55 additions and 6 deletions

View File

@ -35,3 +35,26 @@ pub struct LoginSchema {
pub login_source: Option<String>,
pub gift_code_sku_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct VerifyMFALoginSchema {
pub ticket: String,
pub code: String,
pub login_source: Option<String>,
pub gift_code_sku_id: Option<String>,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub enum VerifyMFALoginResponse {
Success { token: String, user_settings: LoginSettings },
UserSuspended { suspended_user_token: String }
}
#[derive(Debug, Clone, Serialize, Deserialize)]
#[serde(rename_all = "snake_case")]
pub struct LoginSettings {
pub locale: String,
pub theme: String,
}

View File

@ -1,6 +1,6 @@
use std::fmt::Display;
use serde::{Serialize, Deserialize};
use serde::{Deserialize, Serialize};
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
@ -24,14 +24,14 @@ impl Display for MfaRequiredSchema {
#[serde(rename_all = "snake_case")]
pub struct MfaVerificationSchema {
pub ticket: String,
pub methods: Vec<MfaMethod>
pub methods: Vec<MfaMethod>,
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
pub struct MfaMethod {
#[serde(rename = "type")]
pub kind: MfaType,
pub kind: AuthenticatorType,
#[serde(skip_serializing_if = "Option::is_none")]
pub challenge: Option<String>,
#[serde(skip_serializing_if = "Option::is_none")]
@ -40,7 +40,7 @@ pub struct MfaMethod {
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq, Hash)]
#[serde(rename_all = "snake_case")]
pub enum MfaType {
pub enum AuthenticatorType {
TOTP,
SMS,
Backup,
@ -48,11 +48,27 @@ pub enum MfaType {
Password,
}
impl Display for AuthenticatorType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
AuthenticatorType::TOTP => "totp",
AuthenticatorType::SMS => "sms",
AuthenticatorType::Backup => "backup",
AuthenticatorType::WebAuthn => "webauthn",
AuthenticatorType::Password => "password",
}
)
}
}
#[derive(Debug, Clone, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub struct MfaVerifySchema {
pub ticket: String,
pub mfa_type: MfaType,
pub mfa_type: AuthenticatorType,
pub data: String,
}
@ -60,3 +76,13 @@ pub struct MfaVerifySchema {
pub struct MfaTokenSchema {
pub token: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SendMfaSmsSchema {
pub ticket: String,
}
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SendMfaSmsResponse {
pub phone: String,
}