Slight genericity and boundary improvement.

This commit is contained in:
2026-10-10 15:54:23 +02:00
parent d584d4926b
commit 5f85713892
5 changed files with 35 additions and 31 deletions
+4 -4
View File
@@ -1,7 +1,7 @@
use axum::extract::FromRef;
use sqlx::PgPool;
use super::{AuthScheme, Authorizer};
use super::{AuthScheme, Authorizer, Principal};
use crate::{
crypto::hash_secret,
repository::{self, RepositoryError},
@@ -21,7 +21,7 @@ impl AuthScheme for Bearer {
}
}
impl<S> Authorizer<S> for Bearer
impl<S, T> Authorizer<S, T> for Bearer
where
PgPool: FromRef<S>,
S: Send + Sync,
@@ -29,7 +29,7 @@ where
async fn authorize(
credentials: Self::Credentials,
state: &S,
) -> Result<crate::domain::Authorization, Self::Error> {
) -> Result<Principal<T>, Self::Error> {
let pool = PgPool::from_ref(state);
let token_hash = hash_secret(&credentials);
@@ -38,7 +38,7 @@ where
.map_err(BearerError::Repository)?
.ok_or(BearerError::InvalidCredentials)?;
Ok(crate::domain::Authorization::new(token.user_id))
Ok(Principal::<T>::new(token.user_id))
}
}