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