mirror of
https://github.com/TECHNOFAB11/jwt-authorizer.git
synced 2025-12-11 23:50:07 +01:00
refactor: AsyncAuthorizer::authorize, map - > filter_map
This commit is contained in:
parent
e815d35a55
commit
20f7eff01e
1 changed files with 7 additions and 9 deletions
|
|
@ -218,24 +218,22 @@ where
|
||||||
type Future = BoxFuture<'static, Result<Request<B>, AuthError>>;
|
type Future = BoxFuture<'static, Result<Request<B>, AuthError>>;
|
||||||
|
|
||||||
fn authorize(&self, mut request: Request<B>) -> Self::Future {
|
fn authorize(&self, mut request: Request<B>) -> Self::Future {
|
||||||
let tkns_auths: Vec<(Option<String>, Arc<Authorizer<C>>)> = self
|
let tkns_auths: Vec<(String, Arc<Authorizer<C>>)> = self
|
||||||
.auths
|
.auths
|
||||||
.iter()
|
.iter()
|
||||||
.map(|a| (a.extract_token(request.headers()), a.clone()))
|
.filter_map(|a| a.extract_token(request.headers()).map(|t| (t, a.clone())))
|
||||||
.collect();
|
.collect();
|
||||||
|
|
||||||
if !tkns_auths.iter().any(|(t, _)| t.is_some()) {
|
if tkns_auths.is_empty() {
|
||||||
return Box::pin(future::ready(Err(AuthError::MissingToken())));
|
return Box::pin(future::ready(Err(AuthError::MissingToken())));
|
||||||
}
|
}
|
||||||
|
|
||||||
Box::pin(async move {
|
Box::pin(async move {
|
||||||
let mut token_data: Result<TokenData<C>, AuthError> = Err(AuthError::NoAuthorizer());
|
let mut token_data: Result<TokenData<C>, AuthError> = Err(AuthError::NoAuthorizer());
|
||||||
for (tkn, auth) in tkns_auths {
|
for (token, auth) in tkns_auths {
|
||||||
if let Some(token) = tkn {
|
token_data = auth.check_auth(token.as_str()).await;
|
||||||
token_data = auth.check_auth(token.as_str()).await;
|
if token_data.is_ok() {
|
||||||
if token_data.is_ok() {
|
break;
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
match token_data {
|
match token_data {
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue