use serde::{Deserialize, Serialize}; use crate::model::{authenticated::UserAuthenticationToken, instance::Instance}; use super::MessageTarget; /// An account registration request. /// /// # Authentication /// - Instance Authentication /// - **ONLY ACCEPTED WHEN SAME-INSTANCE** #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RegisterAccountRequest { pub username: String, pub email: Option, pub password: String, } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct RegisterAccountResponse { pub token: String, } /// An authentication token request. /// /// AKA Login Request /// /// # Authentication /// - Instance Authentication /// - Identifies the Instance to issue the token for /// # Authorization /// - Credentials ([`crate::backend::AuthBackend`]-based) /// - Identifies the User account to issue a token for /// - Decrypts user private key to issue to #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AuthenticationTokenRequest { pub instance: Instance, pub username: String, pub password: String, } impl MessageTarget for AuthenticationTokenRequest { fn target(&self) -> Option { Some(self.instance.clone()) } } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct AuthenticationTokenResponse { pub token: UserAuthenticationToken, } /// An authentication token extension request. /// /// # Authentication /// - Instance Authentication /// - Identifies the Instance to issue the token for /// - User Authentication /// - Authenticates the validity of the token /// # Authorization /// - Token-based /// - Validates authorization using token's authenticity #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TokenExtensionRequest { pub token: UserAuthenticationToken, } impl MessageTarget for TokenExtensionRequest { fn target(&self) -> Option { // todo! None } } #[derive(Clone, Debug, Serialize, Deserialize)] pub struct TokenExtensionResponse { pub new_token: Option, }