Ready to initiate OpenID login
This commit is contained in:
1
moneymgr_backend/src/extractors/mod.rs
Normal file
1
moneymgr_backend/src/extractors/mod.rs
Normal file
@ -0,0 +1 @@
|
||||
pub mod money_session;
|
35
moneymgr_backend/src/extractors/money_session.rs
Normal file
35
moneymgr_backend/src/extractors/money_session.rs
Normal file
@ -0,0 +1,35 @@
|
||||
use crate::constants;
|
||||
use crate::utils::rand_utils::rand_string;
|
||||
use actix_session::Session;
|
||||
use actix_web::dev::Payload;
|
||||
use actix_web::{Error, FromRequest, HttpRequest};
|
||||
use futures_util::future::{Ready, ready};
|
||||
|
||||
/// Money session
|
||||
///
|
||||
/// Basic wrapper around actix-session extractor
|
||||
pub struct MoneySession(Session);
|
||||
|
||||
impl MoneySession {
|
||||
/// Generate OpenID state for this session
|
||||
pub fn gen_oidc_state(&self) -> anyhow::Result<String> {
|
||||
let random_string = rand_string(50);
|
||||
self.0
|
||||
.insert(constants::sessions::OIDC_STATE_KEY, random_string.clone())?;
|
||||
Ok(random_string)
|
||||
}
|
||||
}
|
||||
|
||||
impl FromRequest for MoneySession {
|
||||
type Error = Error;
|
||||
type Future = Ready<Result<Self, Error>>;
|
||||
|
||||
#[inline]
|
||||
fn from_request(req: &HttpRequest, _: &mut Payload) -> Self::Future {
|
||||
ready(
|
||||
Session::from_request(req, &mut Payload::None)
|
||||
.into_inner()
|
||||
.map(MoneySession),
|
||||
)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user