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

ambee/giterated

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

Update for auth

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨3ef0383

⁨giterated-models/src/messages/authentication.rs⁩ - ⁨2216⁩ 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 impl MessageTarget for RegisterAccountRequest {
20 fn target(&self) -> Option<Instance> {
21 None
22 }
23 }
24
25 #[derive(Clone, Debug, Serialize, Deserialize)]
26 pub struct RegisterAccountResponse {
27 pub token: String,
28 }
29
30 /// An authentication token request.
31 ///
32 /// AKA Login Request
33 ///
34 /// # Authentication
35 /// - Instance Authentication
36 /// - Identifies the Instance to issue the token for
37 /// # Authorization
38 /// - Credentials ([`crate::backend::AuthBackend`]-based)
39 /// - Identifies the User account to issue a token for
40 /// - Decrypts user private key to issue to
41 #[derive(Clone, Debug, Serialize, Deserialize)]
42 pub struct AuthenticationTokenRequest {
43 pub instance: Instance,
44 pub issued_for: Option<Instance>,
45 pub username: String,
46 pub password: String,
47 }
48
49 impl MessageTarget for AuthenticationTokenRequest {
50 fn target(&self) -> Option<Instance> {
51 Some(self.instance.clone())
52 }
53 }
54
55 #[derive(Clone, Debug, Serialize, Deserialize)]
56 pub struct AuthenticationTokenResponse {
57 pub token: UserAuthenticationToken,
58 }
59
60 /// An authentication token extension request.
61 ///
62 /// # Authentication
63 /// - Instance Authentication
64 /// - Identifies the Instance to issue the token for
65 /// - User Authentication
66 /// - Authenticates the validity of the token
67 /// # Authorization
68 /// - Token-based
69 /// - Validates authorization using token's authenticity
70 #[derive(Clone, Debug, Serialize, Deserialize)]
71 pub struct TokenExtensionRequest {
72 pub token: UserAuthenticationToken,
73 }
74
75 impl MessageTarget for TokenExtensionRequest {
76 fn target(&self) -> Option<Instance> {
77 // todo!
78 None
79 }
80 }
81
82 #[derive(Clone, Debug, Serialize, Deserialize)]
83 pub struct TokenExtensionResponse {
84 pub new_token: Option<String>,
85 }
86