Start Matrix client authentication
This commit is contained in:
37
matrixgw_backend/src/extractors/matrix_client_extractor.rs
Normal file
37
matrixgw_backend/src/extractors/matrix_client_extractor.rs
Normal file
@@ -0,0 +1,37 @@
|
||||
use crate::extractors::auth_extractor::AuthExtractor;
|
||||
use crate::matrix_connection::matrix_client::MatrixClient;
|
||||
use crate::matrix_connection::matrix_manager::MatrixManagerMsg;
|
||||
use actix_web::dev::Payload;
|
||||
use actix_web::{FromRequest, HttpRequest, web};
|
||||
use ractor::ActorRef;
|
||||
|
||||
pub struct MatrixClientExtractor {
|
||||
pub auth: AuthExtractor,
|
||||
pub client: MatrixClient,
|
||||
}
|
||||
|
||||
impl FromRequest for MatrixClientExtractor {
|
||||
type Error = actix_web::Error;
|
||||
type Future = futures_util::future::LocalBoxFuture<'static, Result<Self, Self::Error>>;
|
||||
|
||||
fn from_request(req: &HttpRequest, payload: &mut Payload) -> Self::Future {
|
||||
let req = req.clone();
|
||||
let mut payload = payload.take();
|
||||
Box::pin(async move {
|
||||
let auth = AuthExtractor::from_request(&req, &mut payload).await?;
|
||||
|
||||
let matrix_manager_actor =
|
||||
web::Data::<ActorRef<MatrixManagerMsg>>::from_request(&req, &mut Payload::None)
|
||||
.await?;
|
||||
let client = ractor::call!(
|
||||
matrix_manager_actor,
|
||||
MatrixManagerMsg::GetClient,
|
||||
auth.user.email.clone()
|
||||
)
|
||||
.expect("Failed to query manager actor!")
|
||||
.expect("Failed to get client!");
|
||||
|
||||
Ok(Self { auth, client })
|
||||
})
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user