pub struct JwtManager { /* private fields */ }Expand description
JWT Manager | JWT 管理器
Manages JWT token generation, validation, and parsing 管理 JWT token 的生成、验证和解析
Implementations§
Source§impl JwtManager
impl JwtManager
Sourcepub fn new(secret: impl Into<String>) -> Self
pub fn new(secret: impl Into<String>) -> Self
Create new JWT manager with HS256 algorithm | 创建使用 HS256 算法的新 JWT 管理器
§Arguments | 参数
secret- Secret key | 密钥
Sourcepub fn with_algorithm(
secret: impl Into<String>,
algorithm: JwtAlgorithm,
) -> Self
pub fn with_algorithm( secret: impl Into<String>, algorithm: JwtAlgorithm, ) -> Self
Create JWT manager with custom algorithm | 创建使用自定义算法的 JWT 管理器
Sourcepub fn set_issuer(self, issuer: impl Into<String>) -> Self
pub fn set_issuer(self, issuer: impl Into<String>) -> Self
Set issuer | 设置签发者
Sourcepub fn set_audience(self, audience: impl Into<String>) -> Self
pub fn set_audience(self, audience: impl Into<String>) -> Self
Set audience | 设置受众
Sourcepub fn generate(&self, claims: &JwtClaims) -> SaTokenResult<String>
pub fn generate(&self, claims: &JwtClaims) -> SaTokenResult<String>
Sourcepub fn validate(&self, token: &str) -> SaTokenResult<JwtClaims>
pub fn validate(&self, token: &str) -> SaTokenResult<JwtClaims>
Sourcepub fn decode_without_validation(&self, token: &str) -> SaTokenResult<JwtClaims>
pub fn decode_without_validation(&self, token: &str) -> SaTokenResult<JwtClaims>
Decode JWT without validation (unsafe) | 不验证解码 JWT(不安全)
Warning: This does not validate the signature! 警告:这不会验证签名!
Sourcepub fn refresh(&self, token: &str, extend_seconds: i64) -> SaTokenResult<String>
pub fn refresh(&self, token: &str, extend_seconds: i64) -> SaTokenResult<String>
Refresh JWT token | 刷新 JWT token
Creates a new token with updated expiration time 创建具有更新过期时间的新 token
§Arguments | 参数
token- Original JWT token | 原始 JWT tokenextend_seconds- Seconds to extend | 延长的秒数
Sourcepub fn extract_login_id(&self, token: &str) -> SaTokenResult<String>
pub fn extract_login_id(&self, token: &str) -> SaTokenResult<String>
Extract user ID from token without full validation | 从 token 提取用户 ID(无需完整验证)
Useful for quick user identification 用于快速用户识别
Trait Implementations§
Source§impl Clone for JwtManager
impl Clone for JwtManager
Source§fn clone(&self) -> JwtManager
fn clone(&self) -> JwtManager
Returns a duplicate of the value. Read more
1.0.0§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 JwtManager
impl RefUnwindSafe for JwtManager
impl Send for JwtManager
impl Sync for JwtManager
impl Unpin for JwtManager
impl UnwindSafe for JwtManager
Blanket Implementations§
§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§unsafe fn clone_to_uninit(&self, dest: *mut u8)
unsafe fn clone_to_uninit(&self, dest: *mut u8)
🔬This is a nightly-only experimental API. (
clone_to_uninit)