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

ambee/giterated

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

Add docs

Amber - ⁨2⁩ years ago

parent: tbd commit: ⁨51aad53

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