Revert authentication payload change
parent: tbd commit: 16b4bc2
1 | use Error; |
2 | use Error; |
3 | use ; |
4 | |
5 | use crate; |
6 | use |
7 | |
8 | AuthenticationTokenRequest, AuthenticationTokenResponse, RegisterAccountRequest, |
9 | TokenExtensionRequest, |
10 | , |
11 | , | InstanceAuthenticator
12 | ; |
13 | |
14 | use ConnectionState; |
15 | |
16 | pub async |
17 | message_type: &str, |
18 | message: &NetworkMessage, |
19 | state: &ConnectionState, |
20 | |
21 | match message_type |
22 | "giterated_models::messages::authentication::RegisterAccountRequest" => |
23 | register_account_request |
24 | .handle_message |
25 | .await?; |
26 | |
27 | Ok |
28 | |
29 | "giterated_models::messages::authentication::AuthenticationTokenRequest" => |
30 | authentication_token_request |
31 | .handle_message |
32 | .await?; |
33 | |
34 | Ok |
35 | |
36 | "giterated_models::messages::authentication::TokenExtensionRequest" => |
37 | token_extension_request |
38 | .handle_message |
39 | .await?; |
40 | |
41 | Ok |
42 | |
43 | _ => Ok, |
44 | |
45 | |
46 | |
47 | async |
48 | State | : ,
49 | Message | : ,
50 | instance: AuthenticatedInstance, |
51 | |
52 | if *instance.inner != connection_state.instance |
53 | return Err; |
54 | |
55 | |
56 | let mut user_backend = connection_state.user_backend.lock .await; |
57 | |
58 | let response = user_backend |
59 | .register |
60 | .await |
61 | .map_err?; |
62 | drop; |
63 | |
64 | connection_state |
65 | .send |
66 | .await |
67 | .map_err?; |
68 | |
69 | Ok |
70 | |
71 | |
72 | async |
73 | State | : ,
74 | Message | : ,
75 | instance: AuthenticatedInstance, |
76 | |
77 | if request.instance != connection_state.instance |
78 | // We need to perform the authentication request on behalf of |
79 | // the user. TODO: Oauth-style flow |
80 | let mut connections = connection_state.instance_connections.lock .await; |
81 | |
82 | let issued_for = instance.inner .clone; |
83 | |
84 | let connection = connections.get_or_open .unwrap; |
85 | |
86 | let private_key = |
87 | let mut file = open |
88 | connection_state.config |
89 | .as_str |
90 | .unwrap, |
91 | |
92 | .await |
93 | .unwrap; |
94 | |
95 | let mut key = String new; |
96 | file.read_to_string .await.unwrap; |
97 | |
98 | key |
99 | ; |
100 | |
101 | info!; |
102 | |
103 | let authenticator = InstanceAuthenticator |
104 | instance: connection_state.instance.clone, |
105 | private_key, |
106 | ; |
107 | |
108 | let response = request_local |
109 | .authenticate |
110 | . |
111 | .await |
112 | .unwrap; |
113 | drop; |
114 | |
115 | connection_state |
116 | .send |
117 | .await |
118 | .map_err?; |
119 | |
120 | return Ok; |
121 | |
122 | |
123 | let mut user_backend = connection_state.user_backend.lock .await; |
124 | |
125 | let response = user_backend |
126 | .login |
127 | .await |
128 | .map_err?; |
129 | |
130 | connection_state |
131 | .send |
132 | .await |
133 | .map_err?; |
134 | |
135 | Ok |
136 | |
137 | |
138 | async |
139 | State | : ,
140 | Message | : ,
141 | instance: AuthenticatedInstance, |
142 | |
143 | let issued_for = instance.inner .clone; |
144 | |
145 | let mut token_granter = connection_state.auth_granter.lock .await; |
146 | |
147 | let response = token_granter |
148 | .extension_request |
149 | .await |
150 | .map_err?; |
151 | |
152 | connection_state |
153 | .send |
154 | .await |
155 | .map_err?; |
156 | |
157 | Ok |
158 | |
159 | |
160 | |
161 | |
162 | |
163 | InvalidRequest, |
164 | |
165 | SameInstance, |
166 | |
167 | Registration, |
168 | |
169 | Sending, |
170 | |
171 | TokenIssuance, |
172 | |
173 |