poem_openapi/auth/
basic.rsuse poem::{
web::headers::{Authorization, HeaderMapExt},
Request, Result,
};
use crate::{auth::BasicAuthorization, error::AuthorizationError};
#[derive(Debug)]
pub struct Basic {
pub username: String,
pub password: String,
}
impl BasicAuthorization for Basic {
fn from_request(req: &Request) -> Result<Self> {
if let Some(auth) = req
.headers()
.typed_get::<Authorization<poem::web::headers::authorization::Basic>>()
{
return Ok(Basic {
username: auth.username().to_string(),
password: auth.password().to_string(),
});
}
Err(AuthorizationError.into())
}
}