rocket_authorization/
oauth.rs

1use super::{AuthError, Authorization, Request};
2
3#[derive(Debug, Clone, PartialEq)]
4pub struct OAuth {
5    pub token: String,
6}
7
8#[rocket::async_trait]
9impl Authorization for OAuth {
10    const KIND: &'static str = "Bearer";
11
12    async fn parse(_: &str, credential: &str, _: &Request) -> Result<Self, AuthError> {
13        let decoded_text = String::from_utf8(credential.into())
14            .map_err(|error| AuthError::Unprocessable(format!("UTF8 Parse Error: {error}")))?;
15
16        let token_str = decoded_text.trim();
17        if token_str.is_empty() {
18            return Err(AuthError::HeaderMissing);
19        }
20
21        Ok(OAuth {
22            token: token_str.into(),
23        })
24    }
25}