Slight genericity and boundary improvement.
This commit is contained in:
@@ -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))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user