JavaScript is disabled, refresh for a better experience. ambee/giterated

ambee/giterated

Git repository hosting, collaboration, and discovery for the Fediverse.

Automatically populate the target instance field from the request using MessageTarget trait

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨37da513

⁨giterated-models/src/messages/authentication.rs⁩ - ⁨2065⁩ bytes
Raw
1 use serde::{Deserialize, Serialize};
2
3 use crate::model::{authenticated::UserAuthenticationToken, instance::Instance};
4
5 use super::MessageTarget;
6
7 /// An account registration request.
8 ///
9 /// # Authentication
10 /// - Instance Authentication
11 /// - **ONLY ACCEPTED WHEN SAME-INSTANCE**
12 #[derive(Clone, Debug, Serialize, Deserialize)]
13 pub struct RegisterAccountRequest {
14 pub username: String,
15 pub email: Option<String>,
16 pub password: String,
17 }
18
19 #[derive(Clone, Debug, Serialize, Deserialize)]
20 pub struct RegisterAccountResponse {
21 pub token: String,
22 }
23
24 /// An authentication token request.
25 ///
26 /// AKA Login Request
27 ///
28 /// # Authentication
29 /// - Instance Authentication
30 /// - Identifies the Instance to issue the token for
31 /// # Authorization
32 /// - Credentials ([`crate::backend::AuthBackend`]-based)
33 /// - Identifies the User account to issue a token for
34 /// - Decrypts user private key to issue to
35 #[derive(Clone, Debug, Serialize, Deserialize)]
36 pub struct AuthenticationTokenRequest {
37 pub instance: Instance,
38 pub username: String,
39 pub password: String,
40 }
41
42 impl MessageTarget for AuthenticationTokenRequest {
43 fn target(&self) -> Option<Instance> {
44 Some(self.instance.clone())
45 }
46 }
47
48 #[derive(Clone, Debug, Serialize, Deserialize)]
49 pub struct AuthenticationTokenResponse {
50 pub token: UserAuthenticationToken,
51 }
52
53 /// An authentication token extension request.
54 ///
55 /// # Authentication
56 /// - Instance Authentication
57 /// - Identifies the Instance to issue the token for
58 /// - User Authentication
59 /// - Authenticates the validity of the token
60 /// # Authorization
61 /// - Token-based
62 /// - Validates authorization using token's authenticity
63 #[derive(Clone, Debug, Serialize, Deserialize)]
64 pub struct TokenExtensionRequest {
65 pub token: UserAuthenticationToken,
66 }
67
68 impl MessageTarget for TokenExtensionRequest {
69 fn target(&self) -> Option<Instance> {
70 // todo!
71 None
72 }
73 }
74
75 #[derive(Clone, Debug, Serialize, Deserialize)]
76 pub struct TokenExtensionResponse {
77 pub new_token: Option<String>,
78 }
79