Module jwt

Module jwt 

Source
Expand description

JWT (JSON Web Token) Module | JWT (JSON Web Token) 模块

Provides complete JWT functionality including generation, validation, and parsing. 提供完整的 JWT 功能,包括生成、验证和解析。

§Features | 功能特性

  • Multiple algorithms support (HS256, HS384, HS512, RS256, etc.) 支持多种算法(HS256, HS384, HS512, RS256 等)
  • Custom claims support | 支持自定义声明
  • Expiration time validation | 过期时间验证
  • Token refresh | Token 刷新

§Usage Example | 使用示例

use sa_token_core::token::jwt::{JwtManager, JwtClaims};

// Create JWT manager | 创建 JWT 管理器
let jwt_manager = JwtManager::new("your-secret-key");

// Generate JWT token | 生成 JWT token
let mut claims = JwtClaims::new("user_123");
claims.set_expiration(3600); // 1 hour | 1小时
let token = jwt_manager.generate(&claims)?;

// Validate and parse JWT token | 验证并解析 JWT token
let decoded_claims = jwt_manager.validate(&token)?;
println!("User ID: {}", decoded_claims.login_id);

Structs§

JwtClaims
JWT Claims | JWT 声明
JwtManager
JWT Manager | JWT 管理器

Enums§

JwtAlgorithm
JWT Algorithm | JWT 算法