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: StringToken 名称(例如在 header 或 cookie 中的键名)
timeout: i64Token 有效期(秒),-1 表示永久有效
active_timeout: i64Token 最低活跃频率(秒),-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是否允许同一账号并发登录
在多人登录同一账号时,是否共享一个 token(默认 false,对齐 Java)
token_style: TokenStyleToken 风格(uuid、simple-uuid、random-32、random-64、random-128)
is_log: 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: boolJWT 生成失败时是否回退为 UUID(默认 true);失败时始终 tracing::warn
enable_nonce: bool是否启用防重放攻击(nonce 机制)
nonce_timeout: i64Nonce 有效期(秒),-1 表示使用 token timeout
enable_refresh_token: bool是否启用 Refresh Token
refresh_token_timeout: i64Refresh 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: boollogout 时是否保留 Token-Session
Implementations§
Source§impl SaTokenConfig
impl SaTokenConfig
pub fn builder() -> SaTokenConfigBuilder
pub fn timeout_duration(&self) -> Option<Duration>
Sourcepub fn make_key(&self, suffix: &str, id: &str) -> String
pub fn make_key(&self, suffix: &str, id: &str) -> String
构造存储键:拼接 storage_key_prefix 与后缀 例如:make_key(“token:”, “abc123”) → “sa:token:abc123”
Sourcepub fn key_prefix(&self) -> &str
pub fn key_prefix(&self) -> &str
获取存储键前缀
Trait Implementations§
Source§impl Clone for SaTokenConfig
impl Clone for SaTokenConfig
Source§fn clone(&self) -> SaTokenConfig
fn clone(&self) -> SaTokenConfig
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more