diff --git a/src/security/auth_api/types.rs b/src/security/auth_api/types.rs index 15187be9..e59c173e 100644 --- a/src/security/auth_api/types.rs +++ b/src/security/auth_api/types.rs @@ -489,3 +489,25 @@ impl AuthenticatedUser { .collect() } } + +#[axum::async_trait] +impl axum::extract::FromRequestParts for AuthenticatedUser +where + S: Send + Sync, +{ + type Rejection = (axum::http::StatusCode, axum::Json); + + async fn from_request_parts( + parts: &mut axum::http::request::Parts, + _state: &S, + ) -> Result { + parts + .extensions + .get::() + .cloned() + .ok_or(( + axum::http::StatusCode::UNAUTHORIZED, + axum::Json(serde_json::json!({"error": "Authentication required"})), + )) + } +}