-
Notifications
You must be signed in to change notification settings - Fork 116
/
Copy pathno_auth.rs
33 lines (29 loc) · 1013 Bytes
/
no_auth.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
//! ------ No special authentication ------
use rocket::serde::json::Json;
use rocket::{
get,
request::{self, FromRequest, Outcome},
};
use rocket_okapi::{openapi, request::OpenApiFromRequest};
#[derive(OpenApiFromRequest)]
pub struct NoSpecialAuthentication;
#[rocket::async_trait]
impl<'a> FromRequest<'a> for NoSpecialAuthentication {
type Error = &'static str;
async fn from_request(
_request: &'a request::Request<'_>,
) -> request::Outcome<Self, Self::Error> {
Outcome::Success(NoSpecialAuthentication)
}
}
/// # No special authentication
/// This is most often used then you have something that it not related to authentication.
/// For example database connections, or other managed (static) data.
/// <https://rocket.rs/v0.5/guide/state/>
#[openapi]
#[get("/no_auth")]
pub fn no_special_auth(something: NoSpecialAuthentication) -> Json<&'static str> {
// Use `something` here
let _use_value = something;
Json("No special authentication needed.")
}