Skip to main content

SaTokenConfig

Struct SaTokenConfig 

Source
pub struct SaTokenConfig {
Show 30 fields pub token_name: String, pub timeout: i64, pub active_timeout: i64, pub dynamic_active_timeout: bool, pub auto_renew: bool, pub is_concurrent: bool, pub is_share: bool, pub token_style: TokenStyle, pub is_log: bool, pub is_read_cookie: bool, pub is_read_header: bool, pub is_read_body: bool, pub jwt_secret_key: Option<String>, pub jwt_algorithm: Option<String>, pub jwt_issuer: Option<String>, pub jwt_audience: Option<String>, pub jwt_fallback_on_error: bool, pub enable_nonce: bool, pub nonce_timeout: i64, pub enable_refresh_token: bool, pub refresh_token_timeout: i64, pub storage_key_prefix: String, pub max_login_count: i64, pub overflow_logout_mode: LogoutMode, pub replaced_login_exit_mode: ReplacedLoginExitMode, pub replaced_range: ReplacedRange, pub right_now_create_token_session: bool, pub token_session_check_login: bool, pub logout_range: LogoutRange, pub is_logout_keep_token_session: bool,
}
Expand description

sa-token 配置

Fields§

§token_name: String

Token 名称(例如在 header 或 cookie 中的键名)

§timeout: i64

Token 有效期(秒),-1 表示永久有效

§active_timeout: i64

Token 最低活跃频率(秒),-1 表示不限制

超过该间隔未活跃则 token 冻结(TokenInactive);配合 auto_renew 时亦用于续签时长。

§dynamic_active_timeout: bool

是否启用 per-token 动态 active_timeout(对齐 Java dynamicActiveTimeout,Phase2 完善)

§auto_renew: bool

是否开启自动续签(默认 true,对齐 Java SaTokenConfig)

如果设置为 true,在以下场景会自动续签 token:

  • 调用 get_token_info() 时
  • 中间件验证 token 时
  • 调用无参数的 StpUtil 方法时

续签时长由 active_timeout 决定:

  • 如果 active_timeout > 0,则续签 active_timeout 秒
  • 如果 active_timeout <= 0,则续签 timeout 秒
§is_concurrent: bool

是否允许同一账号并发登录

§is_share: bool

在多人登录同一账号时,是否共享一个 token(默认 false,对齐 Java)

§token_style: TokenStyle

Token 风格(uuid、simple-uuid、random-32、random-64、random-128)

§is_log: bool

是否输出操作日志

§is_read_cookie: bool

是否从 cookie 中读取 token

§is_read_header: bool

是否从 header 中读取 token

§is_read_body: bool

是否从请求体中读取 token

§jwt_secret_key: Option<String>

JWT 密钥(如果使用 JWT)

§jwt_algorithm: Option<String>

JWT 算法(默认 HS256)

§jwt_issuer: Option<String>

JWT 签发者

§jwt_audience: Option<String>

JWT 受众

§jwt_fallback_on_error: bool

JWT 生成失败时是否回退为 UUID(默认 true);失败时始终 tracing::warn

§enable_nonce: bool

是否启用防重放攻击(nonce 机制)

§nonce_timeout: i64

Nonce 有效期(秒),-1 表示使用 token timeout

§enable_refresh_token: bool

是否启用 Refresh Token

§refresh_token_timeout: i64

Refresh Token 有效期(秒),默认 7 天

§storage_key_prefix: String

存储键前缀(用于 Redis/数据库等存储后端的键命名) 默认 “sa:”,所有存储键将以此为前缀,如 “sa:token:”、“sa:session:” 等 注意:此字段与 token_prefix(HTTP header 中的 Bearer 前缀)不同

§max_login_count: i64

同一账号最大登录数量,-1 表示不限制

§overflow_logout_mode: LogoutMode

超出 max_login_count 时的下线模式

§replaced_login_exit_mode: ReplacedLoginExitMode

非并发顶号时:踢旧设备还是拒绝新登录

§replaced_range: ReplacedRange

顶号范围:当前设备类型或全部设备

§right_now_create_token_session: bool

登录时是否立即创建 Token-Session

§token_session_check_login: bool

获取 Token-Session 时是否校验 token 登录态

§logout_range: LogoutRange

默认 logout 范围(预留)

§is_logout_keep_token_session: bool

logout 时是否保留 Token-Session

Implementations§

Source§

impl SaTokenConfig

Source

pub fn builder() -> SaTokenConfigBuilder

Source

pub fn timeout_duration(&self) -> Option<Duration>

Source

pub fn make_key(&self, suffix: &str, id: &str) -> String

构造存储键:拼接 storage_key_prefix 与后缀 例如:make_key(“token:”, “abc123”) → “sa:token:abc123”

Source

pub fn key_prefix(&self) -> &str

获取存储键前缀

Trait Implementations§

Source§

impl Clone for SaTokenConfig

Source§

fn clone(&self) -> SaTokenConfig

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

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

Performs copy-assignment from source. Read more
Source§

impl Debug for SaTokenConfig

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for SaTokenConfig

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for SaTokenConfig

Source§

fn deserialize<__D>(__deserializer: __D) -> Result<Self, __D::Error>
where __D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl Serialize for SaTokenConfig

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more

Auto Trait Implementations§

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

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

Source§

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
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,

Source§

impl<T> From<T> for T

Source§

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
Source§

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

Source§

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
Source§

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

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

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

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

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

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

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