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

ambee/giterated

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

Major connection refactor base

Type: Refactor

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨8dcc111

⁨src/messages/authentication.rs⁩ - ⁨2770⁩ bytes
Raw
1 use serde::{Deserialize, Serialize};
2
3 use crate::model::authenticated::UserAuthenticationToken;
4
5 use super::InstanceAuthenticated;
6
7 /// An authentication message.
8 ///
9 /// View request documentation, authentication, and authorization
10 /// details in the associated type, [`AuthenticationRequest`].
11 #[derive(Clone, Serialize, Deserialize)]
12 pub enum AuthenticationMessage {
13 Request(AuthenticationRequest),
14 Response(AuthenticationResponse),
15 }
16
17 #[derive(Clone, Serialize, Deserialize)]
18 pub enum AuthenticationRequest {
19 /// An account registration request.
20 ///
21 /// # Authentication
22 /// - Instance Authentication
23 /// - **ONLY ACCEPTED WHEN SAME-INSTANCE**
24 RegisterAccount(RegisterAccountRequest),
25
26 /// An authentication token request.
27 ///
28 /// AKA Login Request
29 ///
30 /// # Authentication
31 /// - Instance Authentication
32 /// - Identifies the Instance to issue the token for
33 /// # Authorization
34 /// - Credentials ([`crate::backend::AuthBackend`]-based)
35 /// - Identifies the User account to issue a token for
36 /// - Decrypts user private key to issue to
37 AuthenticationToken(AuthenticationTokenRequest),
38
39 /// An authentication token extension request.
40 ///
41 /// # Authentication
42 /// - Instance Authentication
43 /// - Identifies the Instance to issue the token for
44 /// - User Authentication
45 /// - Authenticates the validity of the token
46 /// # Authorization
47 /// - Token-based
48 /// - Validates authorization using token's authenticity
49 TokenExtension(TokenExtensionRequest),
50 }
51
52 #[derive(Clone, Serialize, Deserialize)]
53 pub enum AuthenticationResponse {
54 RegisterAccount(RegisterAccountResponse),
55 AuthenticationToken(AuthenticationTokenResponse),
56 TokenExtension(TokenExtensionResponse),
57 }
58
59 /// See [`AuthenticationRequest::RegisterAccount`]'s documentation.
60 #[derive(Clone, Serialize, Deserialize)]
61 pub struct RegisterAccountRequest {
62 pub username: String,
63 pub email: Option<String>,
64 pub password: String,
65 }
66
67 #[derive(Clone, Debug, Serialize, Deserialize)]
68 pub struct RegisterAccountResponse {
69 pub token: String,
70 }
71
72 /// See [`AuthenticationRequest::AuthenticationToken`]'s documentation.
73 #[derive(Clone, Serialize, Deserialize)]
74 pub struct AuthenticationTokenRequest {
75 pub username: String,
76 pub password: String,
77 }
78
79 #[derive(Clone, Serialize, Deserialize)]
80 pub struct AuthenticationTokenResponse {
81 pub token: String,
82 }
83
84 /// See [`AuthenticationRequest::TokenExtension`]'s documentation.
85 #[derive(Clone, Serialize, Deserialize)]
86 pub struct TokenExtensionRequest {
87 pub token: UserAuthenticationToken,
88 }
89
90 #[derive(Clone, Serialize, Deserialize)]
91 pub struct TokenExtensionResponse {
92 pub new_token: Option<String>,
93 }
94