guards: added TotpRequest guard
This commit is contained in:
parent
8658966b41
commit
1e42208e6b
2 changed files with 28 additions and 1 deletions
|
|
@ -5,6 +5,7 @@ mod jwt;
|
||||||
mod need_setup;
|
mod need_setup;
|
||||||
mod refresh_token;
|
mod refresh_token;
|
||||||
mod reset_password_token;
|
mod reset_password_token;
|
||||||
|
mod totp_request;
|
||||||
|
|
||||||
pub use self::jwt::*;
|
pub use self::jwt::*;
|
||||||
pub use access_token::AccessToken;
|
pub use access_token::AccessToken;
|
||||||
|
|
@ -12,4 +13,5 @@ pub use basic_auth::BasicAuth;
|
||||||
pub use completed_setup::CompletedSetup;
|
pub use completed_setup::CompletedSetup;
|
||||||
pub use need_setup::NeedSetup;
|
pub use need_setup::NeedSetup;
|
||||||
pub use refresh_token::RefreshToken;
|
pub use refresh_token::RefreshToken;
|
||||||
pub use reset_password_token::RocketResetPasswordToken;
|
pub use reset_password_token::RocketResetPasswordToken;
|
||||||
|
pub use totp_request::TotpRequest;
|
||||||
|
|
|
||||||
25
crates/ezidam/src/guards/totp_request.rs
Normal file
25
crates/ezidam/src/guards/totp_request.rs
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
use rocket::request::{FromRequest, Outcome};
|
||||||
|
use rocket::Request;
|
||||||
|
use users::totp_login_request::{TOTP_REQUEST_COOKIE_NAME, TOTP_REQUEST_LEN};
|
||||||
|
|
||||||
|
pub struct TotpRequest(pub String);
|
||||||
|
|
||||||
|
#[rocket::async_trait]
|
||||||
|
impl<'r> FromRequest<'r> for TotpRequest {
|
||||||
|
type Error = std::convert::Infallible;
|
||||||
|
|
||||||
|
async fn from_request(request: &'r Request<'_>) -> Outcome<Self, Self::Error> {
|
||||||
|
match request.cookies().get(TOTP_REQUEST_COOKIE_NAME) {
|
||||||
|
Some(cookie) => {
|
||||||
|
let value = cookie.value();
|
||||||
|
|
||||||
|
if value.len() == TOTP_REQUEST_LEN {
|
||||||
|
Outcome::Success(Self(value.to_string()))
|
||||||
|
} else {
|
||||||
|
Outcome::Forward(())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
None => Outcome::Forward(()),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Add table
Add a link
Reference in a new issue