Available on crate feature auth only.
Expand description

Add authorization to requests using the Authorization header.

Example

use tower_http::auth::AddAuthorizationLayer;
use hyper::{Request, Response, Body, Error};
use http::{StatusCode, header::AUTHORIZATION};
use tower::{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
    .ready()
    .await?
    .call(Request::new(Body::empty()))
    .await?;

assert_eq!(StatusCode::OK, response.status());

Structs

Middleware that adds authorization all requests using the Authorization header.
Layer that applies AddAuthorization which adds authorization to all requests using the Authorization header.