poem_openapi/auth/
bearer.rs1use poem::{
2 web::headers::{Authorization, HeaderMapExt},
3 Request, Result,
4};
5
6use crate::{auth::BearerAuthorization, error::AuthorizationError};
7
8pub struct Bearer {
10 pub token: String,
12}
13
14impl BearerAuthorization for Bearer {
15 fn from_request(req: &Request) -> Result<Self> {
16 if let Some(auth) = req
17 .headers()
18 .typed_get::<Authorization<poem::web::headers::authorization::Bearer>>()
19 {
20 return Ok(Bearer {
21 token: auth.token().to_string(),
22 });
23 }
24
25 Err(AuthorizationError.into())
26 }
27}