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>,
}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 警告
Implementations§
Source§impl JwtClaims
impl JwtClaims
pub fn new(sub: impl Into<String>, exp: i64) -> JwtClaims
pub fn with_issuer(self, iss: impl Into<String>) -> JwtClaims
pub fn with_roles(self, roles: Vec<String>) -> JwtClaims
pub fn with_permissions(self, permissions: Vec<String>) -> JwtClaims
Sourcepub fn with_user_id(self, user_id: i64) -> JwtClaims
pub fn with_user_id(self, user_id: i64) -> JwtClaims
设置用户 ID(v0.2.1 新增)
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<JwtClaims, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
fn deserialize<__D>(
__deserializer: __D,
) -> Result<JwtClaims, <__D as Deserializer<'de>>::Error>where
__D: Deserializer<'de>,
Deserialize this value from the given Serde deserializer. Read more
Source§impl Serialize for JwtClaims
impl Serialize for JwtClaims
Source§fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
fn serialize<__S>(
&self,
__serializer: __S,
) -> Result<<__S as Serializer>::Ok, <__S as Serializer>::Error>where
__S: Serializer,
Serialize this value into the given Serde serializer. 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
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
Source§impl<T> Instrument for T
impl<T> Instrument for T
Source§fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
fn instrument(self, span: Span) -> Instrumented<Self> ⓘ
Source§fn in_current_span(self) -> Instrumented<Self> ⓘ
fn in_current_span(self) -> Instrumented<Self> ⓘ
Source§impl<T> IntoEither for T
impl<T> IntoEither for T
Source§fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
Converts
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read more