Client Authentication Middleware
This crate provides client authentication for HTTP and gRPC APIs. Features include:
- Automatic token renewal when expired in a background task
- Thread-safe token management with interior mutability
reqwestintegration by using a wrappedHttpClienttonicintegration via Interceptors- Support for OAuth2 Client Credential flow
- Support for Bearer Token authentication
- Based on the
oauth2crate - Safe defaults - does not follow redirects and hides sensitive data in Debug
- More flows coming soon!
Example
In the following example we create a middle::HttpClient that wraps a reqwest::Client.
The token is kept fresh with a background task of the ClientCredentialAuthorizer, so that the client always sends authorized requests.
use FromStr;
use SimpleClientCredentialAuthorizerBuilder;
use Client;
use Url;
async
Tonic Integration
ALl Authorizers implemented by the middle crate, implement tonic::service::Interceptor if the tonic feature is enabled.
use ;
use BearerTokenAuthorizer;
use Endpoint;
async
Feature Flags
- all: Includes
rustls-tls,tonic,client-credentials, andruntime-tokio. - default: Includes
rustls-tls,client-credentials, andruntime-tokio. - rustls-tls: Enables
reqwest/rustls-tlsandreqwest/rustls-tls-native-roots. - tonic: Implement
tonic::service::Interceptorfor all Authorizers - runtime-tokio: Enables the
tokioruntime (currently the only supported async runtime). Some Authorizers depend on an async runtime to spawn refresh tasks. - client-credentials: Enables the
ClientCredentialAuthorizerfor the OAuth2 Client Credential flow