pub struct JwtClaims {
pub sub: String,
pub exp: i64,
pub iat: i64,
pub iss: Option<String>,
pub roles: Vec<String>,
pub permissions: Vec<String>,
pub user_id: Option<i64>,
pub token_use: Option<String>,
}Fields§
§sub: String§exp: i64§iat: i64§iss: Option<String>§roles: Vec<String>§permissions: Vec<String>§user_id: Option<i64>用户 ID(v0.2.1 新增,修复 Critical S-2)
Some(id):携带用户 ID,verify_token 可恢复正确 user.idNone:兼容旧 token;verify_token 会回退为 0 并通过 tracing 警告
token_use: Option<String>令牌用途(v4.8.0 新增,修复 Critical C-2 令牌类型混淆)
Some("access"):访问令牌Some("refresh"):刷新令牌None:旧版令牌(仅 verify_token 兼容;refresh_token 严格拒绝)
修复前访问/刷新令牌共用同一 claims 结构且无类型区分,黑帽审计实证: 窃取的访问令牌可送入 refresh 端点无限续期(exp 永续重置)。
Implementations§
Source§impl JwtClaims
impl JwtClaims
pub fn new(sub: impl Into<String>, exp: i64) -> Self
pub fn with_issuer(self, iss: impl Into<String>) -> Self
pub fn with_roles(self, roles: Vec<String>) -> Self
pub fn with_permissions(self, permissions: Vec<String>) -> Self
Sourcepub fn with_user_id(self, user_id: i64) -> Self
pub fn with_user_id(self, user_id: i64) -> Self
设置用户 ID(v0.2.1 新增)
Sourcepub fn with_token_use(self, token_use: &str) -> Self
pub fn with_token_use(self, token_use: &str) -> Self
设置令牌用途(v4.8.0 新增,修复 Critical C-2):"access" 或 "refresh"
Sourcepub fn is_token_use(&self, token_use: &str) -> bool
pub fn is_token_use(&self, token_use: &str) -> bool
是否为指定用途的令牌
pub fn is_expired(&self) -> bool
Trait Implementations§
Source§impl<'de> Deserialize<'de> for JwtClaims
impl<'de> Deserialize<'de> for JwtClaims
Source§fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Auto Trait Implementations§
impl Freeze for JwtClaims
impl RefUnwindSafe for JwtClaims
impl Send for JwtClaims
impl Sync for JwtClaims
impl Unpin for JwtClaims
impl UnsafeUnpin for JwtClaims
impl UnwindSafe for JwtClaims
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more