pub struct AuthConfig {
pub required: bool,
pub token_expiry_secs: u64,
pub signing_key: Option<SigningKey>,
pub issuer: Option<String>,
pub audience: Option<String>,
pub clock_skew_secs: u64,
}Expand description
Authentication configuration
Defines what authentication requirements must be met for a request.
Fields§
§required: boolIf true, authentication is required for all requests
token_expiry_secs: u64Token lifetime in seconds (for validation purposes)
signing_key: Option<SigningKey>Signing key for JWT signature verification.
If None, signature verification is disabled (NOT RECOMMENDED for production).
Use SigningKey::hs256() or SigningKey::rs256_pem() to enable verification.
issuer: Option<String>Expected issuer (iss claim).
If set, tokens must have this value in their iss claim.
audience: Option<String>Expected audience (aud claim).
If set, tokens must have this value in their aud claim.
clock_skew_secs: u64Clock skew tolerance in seconds.
Allow this many seconds of clock difference when validating exp/nbf claims. Default: 60 seconds
Implementations§
Source§impl AuthConfig
impl AuthConfig
Sourcepub fn permissive() -> Self
pub fn permissive() -> Self
Create a permissive authentication configuration (auth optional)
- Authentication optional
- Token expiry: 3600 seconds (1 hour)
- No signature verification (for testing only)
Sourcepub fn standard() -> Self
pub fn standard() -> Self
Create a standard authentication configuration (auth required)
- Authentication required
- Token expiry: 3600 seconds (1 hour)
- No signature verification (configure
signing_keyfor production)
Sourcepub fn strict() -> Self
pub fn strict() -> Self
Create a strict authentication configuration (auth required, short expiry)
- Authentication required
- Token expiry: 1800 seconds (30 minutes)
- No signature verification (configure
signing_keyfor production)
Sourcepub fn with_hs256(secret: &str) -> Self
pub fn with_hs256(secret: &str) -> Self
Create a configuration with HS256 signing key.
This is the recommended configuration for production when using symmetric key signing (internal services).
Sourcepub fn with_rs256_pem(pem: &str) -> Self
pub fn with_rs256_pem(pem: &str) -> Self
Create a configuration with RS256 signing key from PEM.
This is the recommended configuration for production when using asymmetric key signing (external identity providers).
Sourcepub fn with_issuer(self, issuer: &str) -> Self
pub fn with_issuer(self, issuer: &str) -> Self
Set the expected issuer.
Sourcepub fn with_audience(self, audience: &str) -> Self
pub fn with_audience(self, audience: &str) -> Self
Set the expected audience.
Sourcepub const fn has_signing_key(&self) -> bool
pub const fn has_signing_key(&self) -> bool
Check if signature verification is enabled.
Trait Implementations§
Source§impl Clone for AuthConfig
impl Clone for AuthConfig
Source§fn clone(&self) -> AuthConfig
fn clone(&self) -> AuthConfig
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more