Module tower_async_http::auth::add_authorization
source · Available on crate feature
auth only.Expand description
Add authorization to requests using the Authorization header.
Example
use tower_async_http::validate_request::{ValidateRequestHeader, ValidateRequestHeaderLayer};
use tower_async_http::auth::AddAuthorizationLayer;
use hyper::{Request, Response, Body, Error};
use http::{StatusCode, header::AUTHORIZATION};
use tower_async::{Service, ServiceExt, ServiceBuilder, service_fn};
let mut client = ServiceBuilder::new()
// Use basic auth with the given username and password
.layer(AddAuthorizationLayer::basic("username", "password"))
.service(service_that_requires_auth);
// Make a request, we don't have to add the `Authorization` header manually
let response = client
.call(Request::new(Body::empty()))
.await?;
assert_eq!(StatusCode::OK, response.status());Structs
- Middleware that adds authorization all requests using the
Authorizationheader. - Layer that applies
AddAuthorizationwhich adds authorization to all requests using theAuthorizationheader.