You've already forked AstralRinth
forked from didirus/AstralRinth
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:
@@ -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>(
|
||||||
|
|||||||
Reference in New Issue
Block a user