Allow Bearer prefix on authorization tokens (#2854)

Signed-off-by: Skye <me@skye.vg>
Co-authored-by: Geometrically <18202329+Geometrically@users.noreply.github.com>
This commit is contained in:
Skye
2024-10-28 04:04:17 +09:00
committed by GitHub
parent f5a201dd94
commit b5aeef7ebf

View File

@@ -154,10 +154,15 @@ pub fn extract_authorization_header(
) -> Result<&str, AuthenticationError> { ) -> Result<&str, AuthenticationError> {
let headers = req.headers(); let headers = req.headers();
let token_val: Option<&HeaderValue> = headers.get(AUTHORIZATION); let token_val: Option<&HeaderValue> = headers.get(AUTHORIZATION);
token_val let token_val = token_val
.ok_or_else(|| AuthenticationError::InvalidAuthMethod)? .ok_or_else(|| AuthenticationError::InvalidAuthMethod)?
.to_str() .to_str()
.map_err(|_| AuthenticationError::InvalidCredentials) .map_err(|_| AuthenticationError::InvalidCredentials)?;
Ok(if let Some(token) = token_val.strip_prefix("Bearer ") {
token
} else {
token_val
})
} }
pub async fn check_is_moderator_from_headers<'a, 'b, E>( pub async fn check_is_moderator_from_headers<'a, 'b, E>(