auth: Add tracing around token validation

This commit is contained in:
Lennart
2024-10-09 00:30:42 +02:00
parent e7b290149d
commit c2dbd9d0b9

View File

@@ -10,6 +10,7 @@ use std::{
pin::Pin, pin::Pin,
sync::Arc, sync::Arc,
}; };
use tracing::{info_span, Instrument};
pub struct AuthenticationMiddleware<AP: AuthenticationProvider> { pub struct AuthenticationMiddleware<AP: AuthenticationProvider> {
auth_provider: Arc<AP>, auth_provider: Arc<AP>,
@@ -67,8 +68,10 @@ where
if let Ok(auth) = Authorization::<Basic>::parse(req.request()) { if let Ok(auth) = Authorization::<Basic>::parse(req.request()) {
let user_id = auth.as_ref().user_id(); let user_id = auth.as_ref().user_id();
if let Some(password) = auth.as_ref().password() { if let Some(password) = auth.as_ref().password() {
if let Ok(Some(user)) = if let Ok(Some(user)) = auth_provider
auth_provider.validate_user_token(user_id, password).await .validate_user_token(user_id, password)
.instrument(info_span!("validate_user_token"))
.await
{ {
req.extensions_mut().insert(user); req.extensions_mut().insert(user);
} }