Skip to main content

quarlus_security/
config.rs

1/// Security configuration for JWT validation and JWKS cache.
2#[derive(Clone, Debug)]
3pub struct SecurityConfig {
4    /// URL of the JWKS endpoint (e.g., https://auth.example.com/.well-known/jwks.json)
5    pub jwks_url: String,
6
7    /// Expected issuer in the "iss" claim
8    pub issuer: String,
9
10    /// Expected audience in the "aud" claim
11    pub audience: String,
12
13    /// JWKS cache TTL in seconds (default: 3600)
14    pub jwks_cache_ttl_secs: u64,
15}
16
17impl SecurityConfig {
18    /// Create a new SecurityConfig with the given parameters and default cache TTL of 3600s.
19    pub fn new(jwks_url: impl Into<String>, issuer: impl Into<String>, audience: impl Into<String>) -> Self {
20        Self {
21            jwks_url: jwks_url.into(),
22            issuer: issuer.into(),
23            audience: audience.into(),
24            jwks_cache_ttl_secs: 3600,
25        }
26    }
27
28    /// Set the JWKS cache TTL in seconds.
29    pub fn with_cache_ttl(mut self, ttl_secs: u64) -> Self {
30        self.jwks_cache_ttl_secs = ttl_secs;
31        self
32    }
33}