Expand description
Basic HTTP authentication middleware for securing web application endpoints.
This module provides middleware for implementing RFC 7617 Basic HTTP Authentication. It supports both static user credentials and dynamic verification functions, allowing flexible authentication strategies. The middleware validates credentials from the Authorization header and can inject user objects into request extensions for use by downstream handlers.
§Examples
ⓘ
use tako::middleware::basic_auth::BasicAuth;
use tako::middleware::IntoMiddleware;
// Single user.
let auth = BasicAuth::single("admin", "password");
let mw = auth.into_middleware();
// Multiple users with custom realm.
let multi = BasicAuth::multiple([
("alice", "secret1"),
("bob", "secret2"),
]).realm("Admin Area");
// Dynamic verify callback — returns `bool`, not a user object.
let dynamic = BasicAuth::with_verify(|username, password| {
username == "user" && password == "pass"
});Structs§
Type Aliases§
- Basic
Auth Verify Fn - Basic HTTP authentication middleware configuration.