pub struct JwtTokenIssuer { /* private fields */ }Expand description
JWT token issuer — the default ITokenIssuer.
HS256 only. The token is signed with HS256 and verified by this
crate’s JwtAuth, whose Validation::default() also expects HS256, so
issuer and verifier agree out of the box. Asymmetric algorithms (RSA/EC)
are not supported by this type: using one requires both a custom
ITokenIssuer and a custom IAuthenticationHandler (the host’s
jwt_middleware always verifies with Validation::default()).
Mints a token carrying sub, roles, permissions, the caller’s extra
claims, and the framework-managed jti / iat / exp. The jti is what
ISessionStore::revoke later invalidates, so a login endpoint only needs:
let issued = issuer.issue(TokenClaims::new(&user.id)).await?;
sessions.revoke(&issued.jti).await?; // logoutHostBuilder::add_authentication() registers one from the configured
Jwt.Secret / Jwt.ExpirationMinutes; register a custom ITokenIssuer in
DI to replace it.
Implementations§
Source§impl JwtTokenIssuer
impl JwtTokenIssuer
Sourcepub fn from_secret(secret: impl AsRef<[u8]>, default_lifetime: Duration) -> Self
pub fn from_secret(secret: impl AsRef<[u8]>, default_lifetime: Duration) -> Self
Build an HS256 issuer from a shared secret — the same secret
JwtAuth verifies with.
default_lifetime applies when TokenClaims::expires_in is None;
DEFAULT_TOKEN_LIFETIME (1 hour) is the framework default.
Sourcepub fn with_issuer(self, issuer: impl Into<String>) -> Self
pub fn with_issuer(self, issuer: impl Into<String>) -> Self
Set the iss claim.
Sourcepub fn with_audience(self, audience: impl Into<String>) -> Self
pub fn with_audience(self, audience: impl Into<String>) -> Self
Set the aud claim.