pub struct JwtDecoder { /* private fields */ }Expand description
JWT token decoder. Verifies signatures and validates claims.
All validation is synchronous — revocation checks happen in JwtLayer.
Cloning is cheap — state is stored behind Arc.
Implementations§
Source§impl JwtDecoder
impl JwtDecoder
Sourcepub fn from_config(config: &JwtConfig) -> Self
pub fn from_config(config: &JwtConfig) -> Self
Creates a JwtDecoder from YAML configuration.
Uses HmacSigner (HS256) with the configured secret.
Sourcepub fn decode<T: DeserializeOwned>(&self, token: &str) -> Result<Claims<T>>
pub fn decode<T: DeserializeOwned>(&self, token: &str) -> Result<Claims<T>>
Decodes and validates a JWT token string, returning typed Claims<T>.
Validation order:
- Split into 3 parts (
header.payload.signature) - Decode header, check algorithm matches the verifier
- Verify HMAC signature
- Decode and deserialize payload into
Claims<T> - Enforce
exp(always required; missingexpis treated as expired) - Check
nbf(if present) - Check
iss(ifrequire_issueris configured) - Check
aud(ifrequire_audienceis configured)
Clock skew tolerance (leeway) is applied to steps 5 and 6.
§Errors
Returns Error::unauthorized with a JwtError source for:
malformed tokens, invalid headers, algorithm mismatch, invalid signatures,
expired tokens, not-yet-valid tokens, issuer mismatch, or audience mismatch.
Missing exp is treated as expired.
Trait Implementations§
Source§impl Clone for JwtDecoder
impl Clone for JwtDecoder
Source§impl From<&JwtEncoder> for JwtDecoder
Creates a JwtDecoder that shares the signing key and validation config
of an existing JwtEncoder. Useful when encoder and decoder are wired
from the same JwtConfig value.
impl From<&JwtEncoder> for JwtDecoder
Creates a JwtDecoder that shares the signing key and validation config
of an existing JwtEncoder. Useful when encoder and decoder are wired
from the same JwtConfig value.