JwtManager

Struct JwtManager 

Source
pub struct JwtManager { /* private fields */ }
Expand description

JWT Manager | JWT 管理器

Manages JWT token generation, validation, and parsing 管理 JWT token 的生成、验证和解析

Implementations§

Source§

impl JwtManager

Source

pub fn new(secret: impl Into<String>) -> Self

Create new JWT manager with HS256 algorithm | 创建使用 HS256 算法的新 JWT 管理器

§Arguments | 参数
  • secret - Secret key | 密钥
Source

pub fn with_algorithm( secret: impl Into<String>, algorithm: JwtAlgorithm, ) -> Self

Create JWT manager with custom algorithm | 创建使用自定义算法的 JWT 管理器

Source

pub fn set_issuer(self, issuer: impl Into<String>) -> Self

Set issuer | 设置签发者

Source

pub fn set_audience(self, audience: impl Into<String>) -> Self

Set audience | 设置受众

Source

pub fn generate(&self, claims: &JwtClaims) -> SaTokenResult<String>

Generate JWT token | 生成 JWT token

§Arguments | 参数
  • claims - JWT claims | JWT 声明
§Returns | 返回

JWT token string | JWT token 字符串

Source

pub fn validate(&self, token: &str) -> SaTokenResult<JwtClaims>

Validate and parse JWT token | 验证并解析 JWT token

§Arguments | 参数
  • token - JWT token string | JWT token 字符串
§Returns | 返回

Decoded JWT claims | 解码的 JWT 声明

Source

pub fn decode_without_validation(&self, token: &str) -> SaTokenResult<JwtClaims>

Decode JWT without validation (unsafe) | 不验证解码 JWT(不安全)

Warning: This does not validate the signature! 警告:这不会验证签名!

Source

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 token
  • extend_seconds - Seconds to extend | 延长的秒数
Source

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

Source§

fn clone(&self) -> JwtManager

Returns a duplicate of the value. Read more
1.0.0§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more

Auto Trait Implementations§

Blanket Implementations§

§

impl<T> Any for T
where T: 'static + ?Sized,

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

impl<T> Borrow<T> for T
where T: ?Sized,

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

impl<T> BorrowMut<T> for T
where T: ?Sized,

§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
§

impl<T> CloneToUninit for T
where T: Clone,

§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
§

impl<T, U> Into<U> for T
where U: From<T>,

§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
§

impl<T> ToOwned for T
where T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more