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