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:
parent
f5a201dd94
commit
b5aeef7ebf
@ -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>(
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user