use axum::{
async_trait,
extract::FromRequestParts,
http::{request::Parts, StatusCode},
};
use tracing::error;
#[derive(Clone)]
#[allow(dead_code)]
pub struct Authenticated;
#[async_trait]
impl<S> FromRequestParts<S> for Authenticated
where
S: Send + Sync,
{
type Rejection = StatusCode;
async fn from_request_parts(parts: &mut Parts, _state: &S) -> Result<Self, Self::Rejection> {
parts.extensions.get::<Authenticated>().map(|_| Authenticated).ok_or_else(|| {
error!(
"Authentication marker missing from request extensions for path: {}",
parts.uri.path()
);
StatusCode::UNAUTHORIZED
})
}
}