poem_openapi/auth/
basic.rs1use poem::{
2 web::headers::{Authorization, HeaderMapExt},
3 Request, Result,
4};
5
6use crate::{auth::BasicAuthorization, error::AuthorizationError};
7
8#[derive(Debug)]
10pub struct Basic {
11 pub username: String,
13
14 pub password: String,
16}
17
18impl BasicAuthorization for Basic {
19 fn from_request(req: &Request) -> Result<Self> {
20 if let Some(auth) = req
21 .headers()
22 .typed_get::<Authorization<poem::web::headers::authorization::Basic>>()
23 {
24 return Ok(Basic {
25 username: auth.username().to_string(),
26 password: auth.password().to_string(),
27 });
28 }
29
30 Err(AuthorizationError.into())
31 }
32}