pub struct JwtCache { /* private fields */ }Expand description
A bounded cache of validated tokens.
Implementations§
Source§impl JwtCache
impl JwtCache
Sourcepub fn new(enabled: bool, max_lifetime_secs: u64) -> Option<Self>
pub fn new(enabled: bool, max_lifetime_secs: u64) -> Option<Self>
Build a cache, or None if the configuration turns it off.
A zero lifetime disables it, as in PostgREST – an entry that expires the moment it is written is only overhead.
Sourcepub fn clear(&self)
pub fn clear(&self)
Forget every token held.
Done by the cache itself whenever the key set it is used with changes; for a host that wants to revoke for some other reason.
Sourcepub fn stats(&self) -> CacheStats
pub fn stats(&self) -> CacheStats
The lookups answered so far, for a host to export as a metric.
Sourcepub fn authenticate(
&self,
auth_header: Option<&str>,
config: &JwtConfig,
) -> Result<AuthResult, JwtError>
pub fn authenticate( &self, auth_header: Option<&str>, config: &JwtConfig, ) -> Result<AuthResult, JwtError>
Authenticate, consulting the cache.
Falls through to crate::authenticate for anything not cacheable: a
request with no token at all, and a token already at or past its own
expiry.
Sourcepub fn authenticate_with_outcome(
&self,
auth_header: Option<&str>,
config: &JwtConfig,
) -> (Result<AuthResult, JwtError>, CacheOutcome)
pub fn authenticate_with_outcome( &self, auth_header: Option<&str>, config: &JwtConfig, ) -> (Result<AuthResult, JwtError>, CacheOutcome)
authenticate, saying whether the cache
answered.
A separate method rather than a change to that one’s return type, so that every caller of it builds unchanged. The verdict is the same either way; the outcome is for a span or a metric to record.