Skip to main content

potree_auth/authentication/http/
extractors.rs

1use axum::extract::FromRequestParts;
2use http::request::Parts;
3
4use super::super::application::service::AuthenticationService;
5use super::state::State;
6use crate::common::utils::http::render_error::RenderError;
7
8impl<S> FromRequestParts<S> for State
9where
10    S: Send + Sync,
11{
12    type Rejection = RenderError;
13
14    async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
15        let state = parts
16            .extensions
17            .get::<State>()
18            .ok_or(RenderError::StateExtraction)?;
19
20        Ok(state.clone())
21    }
22}
23
24impl<S> FromRequestParts<S> for AuthenticationService
25where
26    S: Send + Sync,
27{
28    type Rejection = RenderError;
29
30    async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
31        let state = State::from_request_parts(parts, state).await?;
32        Ok(state.authentication_service)
33    }
34}