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

ambee/giterated

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

Begin new protocol refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨26651b1

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