chore: migrate authifier into codebase (#658)
Co-authored-by: izzy <me@insrt.uk> Signed-off-by: Zomatree <me@zomatree.live> Signed-off-by: izzy <me@insrt.uk>
This commit is contained in:
88
crates/core/models/src/v0/sessions.rs
Normal file
88
crates/core/models/src/v0/sessions.rs
Normal file
@@ -0,0 +1,88 @@
|
||||
use iso8601_timestamp::Timestamp;
|
||||
|
||||
use crate::v0::{MFAMethod, MFAResponse};
|
||||
|
||||
auto_derived!(
|
||||
pub struct Session {
|
||||
/// Unique Id
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
|
||||
/// User Id
|
||||
pub user_id: String,
|
||||
|
||||
/// Session token
|
||||
pub token: String,
|
||||
|
||||
/// Display name
|
||||
pub name: String,
|
||||
|
||||
/// When the session was last logged in
|
||||
pub last_seen: Timestamp,
|
||||
|
||||
/// Where the session is originating from
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub origin: Option<String>,
|
||||
|
||||
/// Web Push subscription
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub subscription: Option<WebPushSubscription>,
|
||||
}
|
||||
|
||||
/// Web Push subscription
|
||||
pub struct WebPushSubscription {
|
||||
pub endpoint: String,
|
||||
pub p256dh: String,
|
||||
pub auth: String,
|
||||
}
|
||||
|
||||
/// # Edit Data
|
||||
pub struct DataEditSession {
|
||||
/// Session friendly name
|
||||
pub friendly_name: String,
|
||||
}
|
||||
|
||||
pub struct SessionInfo {
|
||||
#[serde(rename = "_id")]
|
||||
pub id: String,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
/// # Login Data
|
||||
#[serde(untagged)]
|
||||
pub enum DataLogin {
|
||||
Email {
|
||||
/// Email
|
||||
email: String,
|
||||
/// Password
|
||||
password: String,
|
||||
/// Friendly name used for the session
|
||||
friendly_name: Option<String>,
|
||||
},
|
||||
MFA {
|
||||
/// Unvalidated or authorised MFA ticket
|
||||
///
|
||||
/// Used to resolve the correct account
|
||||
mfa_ticket: String,
|
||||
/// Valid MFA response
|
||||
///
|
||||
/// This will take precedence over the `password` field where applicable
|
||||
mfa_response: Option<MFAResponse>,
|
||||
/// Friendly name used for the session
|
||||
friendly_name: Option<String>,
|
||||
},
|
||||
}
|
||||
|
||||
#[serde(tag = "result")]
|
||||
pub enum ResponseLogin {
|
||||
Success(Session),
|
||||
MFA {
|
||||
ticket: String,
|
||||
allowed_methods: Vec<MFAMethod>,
|
||||
},
|
||||
Disabled {
|
||||
user_id: String,
|
||||
},
|
||||
}
|
||||
|
||||
);
|
||||
Reference in New Issue
Block a user