iet-auth-session-jwt
feature implementation official
Issues stateless JWT credentials with optional authoritative revocation.
CoreFeaturesIntegrationsStacksTooling
Used bynothing in the repository
iet-auth-session-jwtimplementationHS256 JWT mechanismDepends oniet-telemetrycontractiet-authcontractiet-corecontractiet-configcontractiet-config-macroscontract
How to use it
iet-auth-session-jwt issues and validates stateless HS256 JWT credentials through TokenIssuer and Authenticate. Plain JwtSessions cannot be revoked; calling with_revocations returns a RevocableJwt that checks an authoritative denylist on every request and adds Invalidate. Storage for that denylist is a separate adapter.
// crates/features/iet-auth-session-jwt/src/lib.rs
use ;
use ;
use Principal;
let jwt = new?
// Select authoritative revocation; required before calling `invalidate`.
.with_revocations;
let identity = Principal ;
let token = jwt.issue.await?; // independent per issue call
assert_eq!;
jwt.invalidate.await?; // rejected on next authenticate
assert!;
- Claims require
sub,iss,aud,iat,nbf,exp, and a UUIDv7jti; TTL is capped at 86400 seconds. JwtConfig.secretmust be at least 32 bytes; only length is checked, so supply real randomness.- Without
with_revocationsa token cannot be invalidated:JwtSessionshas noInvalidateimpl.
How it works
issue encodes HS256 claims with a UUIDv7 jti; authenticate decodes and validates them and, on RevocableJwt, also checks the SHA-256 digest against the denylist; invalidate records that digest until the token's expiry.
sequenceDiagram participant C as "Caller" participant J as "RevocableJwt" participant V as "TokenRevocations" C->>J: "issue identity" J-->>C: "Secret JWT" C->>J: "authenticate token" J->>J: "decode validate claims" J->>V: "revoked digest" V-->>J: "bool" J-->>C: "Principal or jwt.invalid" C->>J: "invalidate token" J->>V: "revoke digest expiry"
What it implements
- Implements
iet_auth::TokenIssuerfromiet-auth. - Implements
iet_auth::Authenticate<Secret<String>>fromiet-auth. - Implements
iet_auth::Invalidate<Secret<String>> (revocable form)fromiet-auth.
What's inside
Modules
src/config.rssrc/lib.rs
Public API
(root)
- struct
JwtSessions pub fn new(config: config::JwtConfig) -> AppResult<Self>— Key length is checked, not entropy. Supply a cryptographically random secret.pub fn with_revocations<R: TokenRevocations>(self, store: R) -> RevocableJwt<R>- struct
RevocableJwt— No Invalidate implementation exists for stateless JwtSessions: it cannot revoke. This wrapper explicitly selects authoritative revocation lookups on every request.
config
- struct
JwtConfig
Impl map
TokenIssuer for JwtSessionsAuthenticate<Secret<String>> for JwtSessionsTokenIssuer for RevocableJwt<R>Authenticate<Secret<String>> for RevocableJwt<R>Invalidate<Secret<String>> for RevocableJwt<R>
Depends on
External crates: jsonwebtoken, serde, sha2, uuid
Used by
- No other framework crate depends on it directly.
In this repository
- Not used by a checked-in example yet.
Source: crates/features/iet-auth-session-jwt