pub struct JwtService { /* private fields */ }Expand description
JWT 服务
Implementations§
Source§impl JwtService
impl JwtService
Sourcepub fn verify_token<T: DeserializeOwned + 'static>(
&self,
token: &str,
) -> JwtResult<T>
pub fn verify_token<T: DeserializeOwned + 'static>( &self, token: &str, ) -> JwtResult<T>
Sourcepub fn generate_access_token(
&self,
user_id: &str,
claims: AccessTokenClaims,
) -> JwtResult<String>
pub fn generate_access_token( &self, user_id: &str, claims: AccessTokenClaims, ) -> JwtResult<String>
Sourcepub fn verify_access_token(&self, token: &str) -> JwtResult<JwtClaims>
pub fn verify_access_token(&self, token: &str) -> JwtResult<JwtClaims>
Sourcepub fn generate_refresh_token(
&self,
user_id: &str,
session_id: &str,
version: u32,
) -> JwtResult<String>
pub fn generate_refresh_token( &self, user_id: &str, session_id: &str, version: u32, ) -> JwtResult<String>
Sourcepub fn verify_refresh_token(&self, token: &str) -> JwtResult<RefreshTokenClaims>
pub fn verify_refresh_token(&self, token: &str) -> JwtResult<RefreshTokenClaims>
Sourcepub fn decode_unchecked<T: DeserializeOwned>(&self, token: &str) -> JwtResult<T>
pub fn decode_unchecked<T: DeserializeOwned>(&self, token: &str) -> JwtResult<T>
Sourcepub fn get_remaining_ttl(&self, token: &str) -> JwtResult<i64>
pub fn get_remaining_ttl(&self, token: &str) -> JwtResult<i64>
Source§impl JwtService
impl JwtService
Sourcepub fn generate_token_pair(
&self,
user_id: &str,
access_claims: AccessTokenClaims,
session_id: &str,
) -> JwtResult<TokenPair>
pub fn generate_token_pair( &self, user_id: &str, access_claims: AccessTokenClaims, session_id: &str, ) -> JwtResult<TokenPair>
Sourcepub fn rotate_token_pair(
&self,
refresh_token: &str,
new_access_claims: Option<AccessTokenClaims>,
) -> JwtResult<TokenPair>
pub fn rotate_token_pair( &self, refresh_token: &str, new_access_claims: Option<AccessTokenClaims>, ) -> JwtResult<TokenPair>
轮换刷新令牌
使用旧的刷新令牌生成新的令牌对,并递增版本号
§Arguments
refresh_token- 旧的刷新令牌new_access_claims- 新的访问令牌 Claims(可选)
Trait Implementations§
Source§impl Clone for JwtService
impl Clone for JwtService
Source§fn clone(&self) -> JwtService
fn clone(&self) -> JwtService
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for JwtService
impl RefUnwindSafe for JwtService
impl Send for JwtService
impl Sync for JwtService
impl Unpin for JwtService
impl UnsafeUnpin for JwtService
impl UnwindSafe for JwtService
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