refactor: Adjust auth check logic structure

This commit is contained in:
Ginger authored and Ellis Git committed 2026-10-05 14:22:53 +00:00
1 parent 4d4693494b
commit 3a20ad7ff2
4 files changed
+209 -224

No files matched your search

+13 -4
View File
@@ -8,7 +8,7 @@ use axum::{
use conduwuit::{Error, Result, err};
use ruma::{
CanonicalJsonObject,
api::{IncomingRequest, IncomingRequestExt},
api::{IncomingRequest, IncomingRequestExt, auth_scheme::AuthScheme},
};
use serde::Deserialize;
@@ -92,13 +92,22 @@ where
let request = hyper::Request::from_parts(parts, body.as_ref());
// Check authentication
let auth =
R::Authentication::authenticate::<R, &[u8]>(services, &request, auth_query).await?;
let authentication =
R::Authentication::extract_authentication(&request).map_err(|err| {
err!(Request(Unauthorized(warn!(
path = request.uri().path(),
err = err.into(),
"Failed to extract authentication"
))))
})?;
let identity =
R::Authentication::check::<R>(services, &request, authentication, auth_query).await?;
// Deserialize the body
let body = R::try_from_http_request(request, &borrowed_path)
.map_err(|e| err!(Request(BadJson(debug_warn!("{e}")))))?;
Ok(Self { body, json_body, identity: auth })
Ok(Self { body, json_body, identity })
}
}