Skip to main content

BasicAuthConfig

Struct BasicAuthConfig 

Source
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: String

Authentication 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: usize

Request header size limit (bytes)

§log_failures: bool

Log 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: bool

Enable metrics collection

§log_usernames_in_production: bool

Log usernames in production (security risk)

Implementations§

Source§

impl BasicAuthConfig

Source

pub fn new(validator: Arc<dyn UserValidator>) -> Self

Create new basic auth config

Source

pub fn realm(self, realm: String) -> Self

Set authentication realm

Source

pub fn with_cache(self, cache_config: CacheConfig) -> AuthResult<Self>

Create auth config with cache config

Source

pub fn disable_cache(self) -> Self

Disable cache

Source

pub fn path_filter(self, filter: PathFilter) -> Self

Set path filter

Source

pub fn max_header_size(self, size: usize) -> Self

Set max request header size

Source

pub fn log_failures(self, enabled: bool) -> Self

Enable or disable logging on authentication failure

Source

pub fn custom_error_handler<F>(self, handler: F) -> Self
where F: Fn(&AuthError, &str) -> HttpResponse + Send + Sync + 'static,

Set custom error handler function

Source

pub fn max_concurrent_validations(self, max: usize) -> Self

Set maximum concurrent validations

Source

pub fn validation_timeout(self, timeout: Duration) -> Self

Set validation timeout

Source

pub fn rate_limit_per_ip(self, max_requests: usize, window: Duration) -> Self

Set rate limiting per IP

Source

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.

Source

pub fn enable_metrics(self, enabled: bool) -> Self

Enable or disable metrics collection

Source

pub fn log_usernames_in_production(self, enabled: bool) -> Self

Enable or disable logging usernames in production (security risk)

Source

pub fn validate(&self) -> AuthResult<()>

Enhanced config validation

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.