Skip to content

Commit

Permalink
Allow Bearer prefix on authorization tokens
Browse files Browse the repository at this point in the history
Signed-off-by: Skye <[email protected]>
  • Loading branch information
vgskye committed Oct 26, 2024
1 parent 9452061 commit 52ba7d4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions apps/labrinth/src/auth/validate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,10 +154,15 @@ pub fn extract_authorization_header(
) -> Result<&str, AuthenticationError> {
let headers = req.headers();
let token_val: Option<&HeaderValue> = headers.get(AUTHORIZATION);
token_val
let token_val = token_val
.ok_or_else(|| AuthenticationError::InvalidAuthMethod)?
.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>(
Expand Down

0 comments on commit 52ba7d4

Please sign in to comment.