pub struct JwtClaims {
pub iss: Option<String>,
pub aud: Option<String>,
pub sub: String,
pub jti: Option<String>,
pub iat: i64,
pub exp: i64,
pub nbf: Option<i64>,
pub custom: HashMap<String, Value>,
}Expand description
标准 JWT Claims
Fields§
§iss: Option<String>签发者 (iss)
aud: Option<String>受众 (aud)
sub: String主题 (sub) - 通常是用户 ID
jti: Option<String>JWT ID (jti) - 唯一标识符
iat: i64签发时间 (iat)
exp: i64过期时间 (exp)
nbf: Option<i64>生效时间 (nbf)
custom: HashMap<String, Value>自定义声明
Implementations§
Source§impl JwtClaims
impl JwtClaims
Sourcepub fn with_issuer(self, issuer: impl Into<String>) -> Self
pub fn with_issuer(self, issuer: impl Into<String>) -> Self
设置签发者
Sourcepub fn with_audience(self, audience: impl Into<String>) -> Self
pub fn with_audience(self, audience: impl Into<String>) -> Self
设置受众
Sourcepub fn with_not_before(self, nbf: i64) -> Self
pub fn with_not_before(self, nbf: i64) -> Self
设置生效时间
Sourcepub fn with_custom_claim(self, key: impl Into<String>, value: Value) -> Self
pub fn with_custom_claim(self, key: impl Into<String>, value: Value) -> Self
添加自定义声明
Sourcepub fn is_expired(&self) -> bool
pub fn is_expired(&self) -> bool
检查令牌是否已过期
Sourcepub fn is_valid_now(&self) -> bool
pub fn is_valid_now(&self) -> bool
检查令牌是否已生效
Sourcepub fn expires_at(&self) -> DateTime<Utc>
pub fn expires_at(&self) -> DateTime<Utc>
获取过期时间作为 DateTime
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