doc: multiple authorizers

This commit is contained in:
cduvray 2023-08-23 08:16:55 +02:00
parent cc7969db08
commit cf6e3270b2
2 changed files with 9 additions and 1 deletions

View file

@ -47,6 +47,11 @@ JWT authoriser Layer for Axum and Tonic.
# }; # };
``` ```
## Multiple Authorizers
A layer can be built using multiple authorizers (`IntoLayer` is implemented for `[Authorizer<C>; N]` and for `Vec<Authorizer<C>>`).
The authorizers are sequentially applied until one of them validates the token. If no authorizer validates it the request is rejected.
## Validation ## Validation
Validation configuration object. Validation configuration object.

View file

@ -217,6 +217,9 @@ where
type RequestBody = B; type RequestBody = B;
type Future = BoxFuture<'static, Result<Request<B>, AuthError>>; type Future = BoxFuture<'static, Result<Request<B>, AuthError>>;
/// The authorizers are sequentially applied (check_auth) until one of them validates the token.
/// If no authorizer validates the token the request is rejected.
///
fn authorize(&self, mut request: Request<B>) -> Self::Future { fn authorize(&self, mut request: Request<B>) -> Self::Future {
let tkns_auths: Vec<(String, Arc<Authorizer<C>>)> = self let tkns_auths: Vec<(String, Arc<Authorizer<C>>)> = self
.auths .auths
@ -244,7 +247,7 @@ where
Ok(request) Ok(request)
} }
Err(err) => Err(err), // TODO: error containing all errors (not just the last one) Err(err) => Err(err), // TODO: error containing all errors (not just the last one) or to choose one?
} }
}) })
} }