use axum::http::HeaderMap;
use axum::http::header::AUTHORIZATION;
pub trait ApiTokenStore: Send + Sync + 'static {
type UserId: Clone + Send + Sync + 'static;
type Error: std::fmt::Display + Send + Sync + 'static;
fn resolve_token(
&self,
token: &str,
) -> impl std::future::Future<Output = Result<Option<Self::UserId>, Self::Error>> + Send;
}
pub fn authorization_bearer(headers: &HeaderMap) -> Option<&str> {
let hdr = headers.get(AUTHORIZATION)?.to_str().ok()?;
let prefix = "Bearer ";
let rest = hdr.strip_prefix(prefix)?;
let token = rest.trim();
if token.is_empty() {
return None;
}
Some(token)
}