pub struct BasicAuthConfig {Show 13 fields
pub realm: String,
pub validator: Arc<dyn UserValidator>,
pub cache: Option<Arc<AuthCache>>,
pub path_filter: Option<Arc<PathFilter>>,
pub max_header_size: usize,
pub log_failures: bool,
pub custom_error_handler: Option<CustomErrorHandler>,
pub max_concurrent_validations: Option<usize>,
pub validation_timeout: Option<Duration>,
pub rate_limit_per_ip: Option<(usize, Duration)>,
pub client_ip_header: Option<String>,
pub enable_metrics: bool,
pub log_usernames_in_production: bool,
}Expand description
Basic authentication config
Fields§
§realm: StringAuthentication realm (for WWW-Authenticate header)
validator: Arc<dyn UserValidator>User validator
cache: Option<Arc<AuthCache>>Auth result cache (optional)
path_filter: Option<Arc<PathFilter>>Path filter (optional)
max_header_size: usizeRequest header size limit (bytes)
log_failures: boolLog details on authentication failure
custom_error_handler: Option<CustomErrorHandler>Custom error handler
max_concurrent_validations: Option<usize>Maximum concurrent authentication validations
validation_timeout: Option<Duration>Validation timeout
rate_limit_per_ip: Option<(usize, Duration)>Rate limiting: (max_requests, time_window)
client_ip_header: Option<String>Header to read the client IP from for rate limiting (e.g.
"x-forwarded-for"). When set, the first address in the header is used
instead of the transport peer address. Only enable behind a trusted
proxy, since clients can spoof this header.
enable_metrics: boolEnable metrics collection
log_usernames_in_production: boolLog usernames in production (security risk)
Implementations§
Source§impl BasicAuthConfig
impl BasicAuthConfig
Sourcepub fn new(validator: Arc<dyn UserValidator>) -> Self
pub fn new(validator: Arc<dyn UserValidator>) -> Self
Create new basic auth config
Sourcepub fn with_cache(self, cache_config: CacheConfig) -> AuthResult<Self>
pub fn with_cache(self, cache_config: CacheConfig) -> AuthResult<Self>
Create auth config with cache config
Sourcepub fn disable_cache(self) -> Self
pub fn disable_cache(self) -> Self
Disable cache
Sourcepub fn path_filter(self, filter: PathFilter) -> Self
pub fn path_filter(self, filter: PathFilter) -> Self
Set path filter
Sourcepub fn max_header_size(self, size: usize) -> Self
pub fn max_header_size(self, size: usize) -> Self
Set max request header size
Sourcepub fn log_failures(self, enabled: bool) -> Self
pub fn log_failures(self, enabled: bool) -> Self
Enable or disable logging on authentication failure
Sourcepub fn custom_error_handler<F>(self, handler: F) -> Self
pub fn custom_error_handler<F>(self, handler: F) -> Self
Set custom error handler function
Sourcepub fn max_concurrent_validations(self, max: usize) -> Self
pub fn max_concurrent_validations(self, max: usize) -> Self
Set maximum concurrent validations
Sourcepub fn validation_timeout(self, timeout: Duration) -> Self
pub fn validation_timeout(self, timeout: Duration) -> Self
Set validation timeout
Sourcepub fn rate_limit_per_ip(self, max_requests: usize, window: Duration) -> Self
pub fn rate_limit_per_ip(self, max_requests: usize, window: Duration) -> Self
Set rate limiting per IP
Sourcepub fn client_ip_header(self, header: impl Into<String>) -> Self
pub fn client_ip_header(self, header: impl Into<String>) -> Self
Set the header to read the client IP from for rate limiting (e.g.
"x-forwarded-for"). Only enable this behind a trusted proxy, since
clients can otherwise spoof the header to evade or forge rate limits.
Sourcepub fn enable_metrics(self, enabled: bool) -> Self
pub fn enable_metrics(self, enabled: bool) -> Self
Enable or disable metrics collection
Sourcepub fn log_usernames_in_production(self, enabled: bool) -> Self
pub fn log_usernames_in_production(self, enabled: bool) -> Self
Enable or disable logging usernames in production (security risk)
Sourcepub fn validate(&self) -> AuthResult<()>
pub fn validate(&self) -> AuthResult<()>
Enhanced config validation