/
generated.rs
414 lines (350 loc) · 14.3 KB
/
generated.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
#![allow(dead_code)]
pub mod api {
use actix_swagger::{Answer, Api};
use actix_web::{
dev::{AppService, Factory, HttpServiceFactory},
http::Method,
FromRequest,
};
use std::future::Future;
pub struct AuthmenowPublicApi {
api: Api,
}
impl AuthmenowPublicApi {
pub fn new() -> Self {
AuthmenowPublicApi { api: Api::new() }
}
}
impl HttpServiceFactory for AuthmenowPublicApi {
fn register(self, config: &mut AppService) {
self.api.register(config);
}
}
impl AuthmenowPublicApi {
pub fn bind_oauth_authorize_request<F, T, R>(mut self, handler: F) -> Self
where
F: Factory<T, R, Answer<'static, super::paths::oauth_authorize_request::Response>>,
T: FromRequest + 'static,
R: Future<Output = Answer<'static, super::paths::oauth_authorize_request::Response>>
+ 'static,
{
self.api = self
.api
.bind("/oauth/authorize".to_owned(), Method::GET, handler);
self
}
pub fn bind_register_request<F, T, R>(mut self, handler: F) -> Self
where
F: Factory<T, R, Answer<'static, super::paths::register_request::Response>>,
T: FromRequest + 'static,
R: Future<Output = Answer<'static, super::paths::register_request::Response>> + 'static,
{
self.api = self
.api
.bind("/register/request".to_owned(), Method::POST, handler);
self
}
pub fn bind_register_confirmation<F, T, R>(mut self, handler: F) -> Self
where
F: Factory<T, R, Answer<'static, super::paths::register_confirmation::Response>>,
T: FromRequest + 'static,
R: Future<Output = Answer<'static, super::paths::register_confirmation::Response>>
+ 'static,
{
self.api = self
.api
.bind("/register/confirmation".to_owned(), Method::POST, handler);
self
}
pub fn bind_session_get<F, T, R>(mut self, handler: F) -> Self
where
F: Factory<T, R, Answer<'static, super::paths::SessionGetResponse>>,
T: FromRequest + 'static,
R: Future<Output = Answer<'static, super::paths::SessionGetResponse>> + 'static,
{
self.api = self.api.bind("/session".to_owned(), Method::GET, handler);
self
}
pub fn bind_session_create<F, T, R>(mut self, handler: F) -> Self
where
F: Factory<T, R, Answer<'static, super::paths::SessionCreateResponse>>,
T: FromRequest + 'static,
R: Future<Output = Answer<'static, super::paths::SessionCreateResponse>> + 'static,
{
self.api = self.api.bind("/session".to_owned(), Method::POST, handler);
self
}
pub fn bind_session_delete<F, T, R>(mut self, handler: F) -> Self
where
F: Factory<T, R, Answer<'static, super::paths::SessionDeleteResponse>>,
T: FromRequest + 'static,
R: Future<Output = Answer<'static, super::paths::SessionDeleteResponse>> + 'static,
{
self.api = self
.api
.bind("/session".to_owned(), Method::DELETE, handler);
self
}
}
impl Default for AuthmenowPublicApi {
fn default() -> Self {
let api = AuthmenowPublicApi::new();
// add default handlers to response 501, if handler not binded
api
}
}
}
pub mod components {
pub mod parameters {
use serde::{Deserialize, Serialize};
/// response_type is set to code indicating that you want an authorization code as the response.
#[derive(Debug, Serialize, Deserialize)]
pub enum OAuthResponseType {
#[serde(rename = "code")]
Code,
}
/// The client_id is the identifier for your app.
/// You will have received a client_id when first registering your app with the service.
pub type OAuthClientId = uuid::Uuid;
/// The redirect_uri may be optional depending on the API, but is highly recommended.
/// This is the URL to which you want the user to be redirected after the authorization is complete.
/// This must match the redirect URL that you have previously registered with the service.
pub type OAuthRedirectUri = String;
/// Include one or more scope values (space-separated) to request additional levels of access.
/// The values will depend on the particular service.
pub type OAuthScope = String;
/// The state parameter serves two functions.
/// When the user is redirected back to your app, whatever value you include as the state will also be included in the redirect.
/// This gives your app a chance to persist data between the user being directed to the authorization server and back again,
/// such as using the state parameter as a session key. This may be used to indicate what action in the app to perform after authorization is complete,
/// for example, indicating which of your app’s pages to redirect to after authorization. This also serves as a CSRF protection mechanism.
/// When the user is redirected back to your app, double check that the state value matches what you set it to originally.
/// This will ensure an attacker can’t intercept the authorization flow.
pub type OAuthState = String;
}
pub mod responses {
use serde::{Deserialize, Serialize};
/// User authenticated in Authmenow
#[derive(Debug, Serialize, Deserialize)]
pub struct UserAuthenticated {
pub username: Option<String>,
#[serde(rename = "displayName")]
pub display_name: Option<String>,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct UserAnonymous {}
/// Registration link sent to email, now user can find out when the link expires
#[derive(Debug, Serialize, Deserialize)]
pub struct RegistrationRequestCreated {
/// UTC Unix TimeStamp when the link expires
#[serde(rename = "expiresAt")]
pub expires_at: i64,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum RegisterFailedError {
#[serde(rename = "email_already_registered")]
EmailAlreadyRegistered,
#[serde(rename = "invalid_form")]
InvalidForm,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RegisterFailed {
pub error: RegisterFailedError,
}
#[derive(Debug, Serialize, Deserialize)]
pub enum RegisterConfirmationFailedError {
#[serde(rename = "code_invalid_or_expired")]
CodeInvalidOrExpired,
#[serde(rename = "email_already_activated")]
EmailAlreadyActivated,
#[serde(rename = "invalid_form")]
InvalidForm,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RegisterConfirmationFailed {
pub error: RegisterConfirmationFailedError,
}
}
pub mod request_bodies {
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
pub struct Register {
pub email: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct RegisterConfirmation {
#[serde(rename = "confirmationCode")]
pub confirmation_code: String,
#[serde(rename = "firstName")]
pub first_name: String,
#[serde(rename = "lastName")]
pub last_name: String,
pub password: String,
}
#[derive(Debug, Serialize, Deserialize)]
pub struct SessionCreate {
pub email: String,
pub password: String,
}
}
}
pub mod paths {
use super::components;
use actix_swagger::{Answer, ContentType};
use actix_web::http::StatusCode;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SessionGetResponse {
Ok(components::responses::UserAuthenticated),
NotAuthorized(components::responses::UserAnonymous),
}
impl SessionGetResponse {
#[inline]
pub fn answer<'a>(self) -> Answer<'a, Self> {
let status = match self {
Self::Ok(_) => StatusCode::OK,
Self::NotAuthorized(_) => StatusCode::UNAUTHORIZED,
};
Answer::new(self)
.status(status)
.content_type(Some(ContentType::Json))
}
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SessionCreateResponse {
/// Session successfully created
Ok,
}
impl SessionCreateResponse {
#[inline]
pub fn answer<'a>(self) -> Answer<'a, Self> {
let status = match self {
Self::Ok => StatusCode::OK,
};
Answer::new(self)
.status(status)
.content_type(Some(ContentType::Json))
}
}
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum SessionDeleteResponse {
/// Session successfully deleted
Ok,
}
impl SessionDeleteResponse {
#[inline]
pub fn answer<'a>(self) -> Answer<'a, Self> {
let status = match self {
Self::Ok => StatusCode::OK,
};
Answer::new(self)
.status(status)
.content_type(Some(ContentType::Json))
}
}
pub mod register_request {
use super::components::responses;
use actix_swagger::{Answer, ContentType};
use actix_web::http::StatusCode;
use serde::Serialize;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum Response {
Created(responses::RegistrationRequestCreated),
BadRequest(responses::RegisterFailed),
Unexpected,
}
impl Response {
#[inline]
pub fn answer<'a>(self) -> Answer<'a, Self> {
let status = match self {
Self::Created(_) => StatusCode::CREATED,
Self::BadRequest(_) => StatusCode::BAD_REQUEST,
Self::Unexpected => StatusCode::INTERNAL_SERVER_ERROR,
};
let content_type = match self {
Self::Unexpected => None,
_ => Some(ContentType::Json),
};
Answer::new(self).status(status).content_type(content_type)
}
}
}
pub mod register_confirmation {
use super::components::responses;
use actix_swagger::{Answer, ContentType};
use actix_web::http::StatusCode;
use serde::Serialize;
#[derive(Debug, Serialize)]
#[serde(untagged)]
pub enum Response {
Created,
BadRequest(responses::RegisterConfirmationFailed),
Unexpected,
}
impl Response {
#[inline]
pub fn answer<'a>(self) -> Answer<'a, Self> {
let status = match self {
Self::Created => StatusCode::CREATED,
Self::BadRequest(_) => StatusCode::BAD_REQUEST,
Self::Unexpected => StatusCode::INTERNAL_SERVER_ERROR,
};
let content_type = match self {
Self::Unexpected => None,
_ => Some(ContentType::Json),
};
Answer::new(self).status(status).content_type(content_type)
}
}
}
pub mod oauth_authorize_request {
use super::components::parameters;
use actix_swagger::Answer;
use actix_web::http::StatusCode;
use serde::{Deserialize, Serialize};
#[derive(Debug, Serialize, Deserialize)]
#[serde(untagged)]
pub enum Response {
/// User redirected to `redirect_uri` with `error` or `code`
///
/// ### Possible errors:
/// - If the user denies the authorization request, the server will redirect the user back to the redirect URL with error=`access_denied` in the query string, and no code will be present. It is up to the app to decide what to display to the user at this point.
/// - `invalid_request` — The request is missing a required parameter, includes an invalid parameter value, or is otherwise malformed.
/// - `unsupported_response_type` — The authorization server does not support obtaining an authorization code using this method.
/// - `invalid_scope` — The requested scope is invalid, unknown, or malformed.
/// - `server_error` — The authorization server encountered an unexpected condition which prevented it from fulfilling the request.
/// - `temporarily_unavailable` — The authorization server is currently unable to handle the request due to a temporary overloading or maintenance of the server.
///
/// [OAuth2 Possible Errors](https://www.oauth.com/oauth2-servers/server-side-apps/possible-errors/)
SeeOther,
BadRequest,
NotFound,
InternalServerError,
}
impl Response {
#[inline]
pub fn answer<'a>(self) -> Answer<'a, Self> {
let status = match self {
Self::SeeOther => StatusCode::SEE_OTHER,
Self::NotFound => StatusCode::NOT_FOUND,
Self::BadRequest => StatusCode::BAD_REQUEST,
Self::InternalServerError => StatusCode::INTERNAL_SERVER_ERROR,
};
Answer::new(self).status(status)
}
}
#[derive(Debug, Serialize, Deserialize)]
pub struct QueryStruct {
pub response_type: parameters::OAuthResponseType,
pub client_id: parameters::OAuthClientId,
pub redirect_uri: parameters::OAuthRedirectUri,
pub scope: Option<parameters::OAuthScope>,
pub state: Option<parameters::OAuthState>,
}
pub type Query = actix_web::web::Query<QueryStruct>;
}
}