elminate generic argument in ruma_wrapper::auth

Signed-off-by: Jason Volk <jason@zemos.net>
This commit is contained in:
Jason Volk 2024-06-04 18:30:51 +00:00
parent 0e3d192ad2
commit 73718a1208
2 changed files with 4 additions and 7 deletions

View file

@ -4,7 +4,7 @@ use axum::RequestPartsExt;
use axum_extra::{headers::Authorization, typed_header::TypedHeaderRejectionReason, TypedHeader}; use axum_extra::{headers::Authorization, typed_header::TypedHeaderRejectionReason, TypedHeader};
use http::uri::PathAndQuery; use http::uri::PathAndQuery;
use ruma::{ use ruma::{
api::{client::error::ErrorKind, AuthScheme, IncomingRequest}, api::{client::error::ErrorKind, AuthScheme},
CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId, CanonicalJsonValue, OwnedDeviceId, OwnedServerName, OwnedUserId, UserId,
}; };
use tracing::warn; use tracing::warn;
@ -26,11 +26,7 @@ pub(super) struct Auth {
pub(super) appservice_info: Option<RegistrationInfo>, pub(super) appservice_info: Option<RegistrationInfo>,
} }
pub(super) async fn auth<T>(request: &mut Request) -> Result<Auth> pub(super) async fn auth(request: &mut Request, metadata: &ruma::api::Metadata) -> Result<Auth> {
where
T: IncomingRequest,
{
let metadata = T::METADATA;
let token = match &request.auth { let token = match &request.auth {
Some(TypedHeader(Authorization(bearer))) => Some(bearer.token()), Some(TypedHeader(Authorization(bearer))) => Some(bearer.token()),
None => request.query.access_token.as_deref(), None => request.query.access_token.as_deref(),

View file

@ -45,8 +45,9 @@ where
type Rejection = Error; type Rejection = Error;
async fn from_request(request: hyper::Request<axum::body::Body>, _state: &S) -> Result<Self, Self::Rejection> { async fn from_request(request: hyper::Request<axum::body::Body>, _state: &S) -> Result<Self, Self::Rejection> {
let meta = T::METADATA;
let mut request: Request = extract(request).await?; let mut request: Request = extract(request).await?;
let auth: Auth = auth::auth::<T>(&mut request).await?; let auth: Auth = auth::auth(&mut request, &meta).await?;
let body = make_body::<T>(&mut request, &auth)?; let body = make_body::<T>(&mut request, &auth)?;
Ok(Ruma { Ok(Ruma {
body, body,