Available on crate features
auth and auth-jwt only.Expand description
JWT (JSON Web Token) validation.
Provides JWT validation using the jsonwebtoken crate with support for
HS256 (HMAC) and RS256 (RSA) algorithms.
§Example
ⓘ
use allframe_core::auth::{JwtValidator, JwtConfig, Authenticator};
use serde::Deserialize;
#[derive(Debug, Clone, Deserialize)]
struct MyClaims {
sub: String,
email: Option<String>,
role: Option<String>,
}
// Create validator with HS256
let config = JwtConfig::hs256("my-secret-key")
.with_issuer("my-app")
.with_leeway(60);
let validator = JwtValidator::<MyClaims>::new(config);
// Validate a token
let claims = validator.authenticate("eyJ...").await?;
println!("User: {}", claims.sub);Structs§
- JwtConfig
- Configuration for JWT validation.
- JwtValidator
- JWT token validator.
- Standard
Claims - Standard JWT claims structure.
Enums§
- JwtAlgorithm
- JWT algorithm to use for validation.