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 const fn permissive() -> Self
pub const 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 const fn standard() -> Self
pub const 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 const fn strict() -> Self
pub const 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 moreSource§impl Debug for AuthConfig
impl Debug for AuthConfig
Source§impl<'de> Deserialize<'de> for AuthConfig
impl<'de> Deserialize<'de> for AuthConfig
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Auto Trait Implementations§
impl Freeze for AuthConfig
impl RefUnwindSafe for AuthConfig
impl Send for AuthConfig
impl Sync for AuthConfig
impl Unpin for AuthConfig
impl UnsafeUnpin for AuthConfig
impl UnwindSafe for AuthConfig
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
Source§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more