docs: 完善文档 cookieAutoFillPrefix 配置项描述

This commit is contained in:
click33 2025-04-09 12:47:54 +08:00
parent 713ac4d6e6
commit 662398af6a
3 changed files with 26 additions and 8 deletions

View File

@ -21,7 +21,7 @@
- [集成 Redis](/up/integ-redis)
- [前后端分离](/up/not-cookie)
- [自定义 Token 风格](/up/token-style)
- [自定义 Token 前缀](/up/token-prefix)
- [Token 提交前缀](/up/token-prefix)
- [同端互斥登录](/up/mutex-login)
- [记住我模式](/up/remember-me)
- [登录参数 & 注销参数](/up/login-parameter)

View File

@ -1,4 +1,4 @@
# 自定义 Token 前缀
# Token 提交前缀
### 需求场景
@ -18,7 +18,7 @@
<!------------- tab:yaml 风格 ------------->
``` yaml
sa-token:
# token前缀
# 指定 token 提交时的前缀
token-prefix: Bearer
```
<!------------- tab:properties 风格 ------------->
@ -31,9 +31,27 @@ sa-token.token-prefix=Bearer
此时 Sa-Token 便可在读取 Token 时裁剪掉 `Bearer`,成功获取`xxxx-xxxx-xxxx-xxxx`。
注:**Token前缀 与 Token值 之间必须有一个空格**
### Cookie 模式自动填充前缀
由于`Cookie`中无法存储空格字符,所以配置 Token 前缀后Cookie 模式将会失效,无法成功提交带有前缀的 token。
如果需要在这种场景下仍然使用 Cookie 模式验证 token可以使用 `cookieAutoFillPrefix` 配置项打开 Cookie 模式自动填充前缀:
<!---------------------------- tabs:start ---------------------------->
<!------------- tab:yaml 风格 ------------->
``` yaml
sa-token:
# 指定 Cookie 模式下自动填充 token 提交前缀
cookie-auto-fill-prefix: true
```
<!------------- tab:properties 风格 ------------->
``` properties
# 指定 Cookie 模式下自动填充 token 提交前缀
sa-token.cookie-auto-fill-prefix=true
```
<!---------------------------- tabs:end ---------------------------->
> [!WARNING| label:注意点]
> 1. Token前缀 与 Token值 之间必须有一个空格。
> 2. 一旦配置了 Token前缀则前端提交 `Token` 时,必须带有前缀,否则会导致框架无法读取 Token。
> 3. 由于`Cookie`中无法存储空格字符,所以配置 Token 前缀后Cookie 模式将会失效,此时只能将 Token 提交到`header`里进行传输。

View File

@ -142,7 +142,7 @@ public class SaTokenConfigure {
| tokenSessionCheckLogin | Boolean | true | 获取 `Token-Session` 时是否必须登录 如果配置为true会在每次获取 `Token-Session` 时校验是否登录),[详解](/use/config?id=配置项详解tokenSessionCheckLogin) |
| autoRenew | Boolean | true | 是否打开自动续签 如果此值为true框架会在每次直接或间接调用 `getLoginId()` 时进行一次过期检查与续签操作),[参考token有效期详解](/fun/token-timeout) |
| tokenPrefix | String | null | token前缀例如填写 `Bearer` 实际传参 `satoken: Bearer xxxx-xxxx-xxxx-xxxx` [参考自定义Token前缀](/up/token-prefix) |
| cookieAutoFillPrefix | Boolean | false | cookie 模式是否自动填充 token 前缀 |
| cookieAutoFillPrefix | Boolean | false | cookie 模式是否自动填充 token 提交前缀 |
| isPrint | Boolean | true | 是否在初始化配置时打印版本字符画 |
| isLog | Boolean | false | 是否打印操作日志 |
| logLevel | String | trace | 日志等级trace、debug、info、warn、error、fatal此值与 logLevelInt 联动 |