From 662398af6a9bc2d965e01da23b1869c1c71ffad4 Mon Sep 17 00:00:00 2001 From: click33 <2393584716@qq.com> Date: Wed, 9 Apr 2025 12:47:54 +0800 Subject: [PATCH] =?UTF-8?q?docs:=20=E5=AE=8C=E5=96=84=E6=96=87=E6=A1=A3=20?= =?UTF-8?q?cookieAutoFillPrefix=20=E9=85=8D=E7=BD=AE=E9=A1=B9=E6=8F=8F?= =?UTF-8?q?=E8=BF=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sa-token-doc/_sidebar.md | 2 +- sa-token-doc/up/token-prefix.md | 30 ++++++++++++++++++++++++------ sa-token-doc/use/config.md | 2 +- 3 files changed, 26 insertions(+), 8 deletions(-) diff --git a/sa-token-doc/_sidebar.md b/sa-token-doc/_sidebar.md index 347414f2..2d1c2b93 100644 --- a/sa-token-doc/_sidebar.md +++ b/sa-token-doc/_sidebar.md @@ -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) diff --git a/sa-token-doc/up/token-prefix.md b/sa-token-doc/up/token-prefix.md index 67f25980..0d824f8d 100644 --- a/sa-token-doc/up/token-prefix.md +++ b/sa-token-doc/up/token-prefix.md @@ -1,4 +1,4 @@ -# 自定义 Token 前缀 +# Token 提交前缀 ### 需求场景 @@ -18,7 +18,7 @@ ``` yaml sa-token: - # token前缀 + # 指定 token 提交时的前缀 token-prefix: Bearer ``` @@ -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 模式自动填充前缀: + + + +``` yaml +sa-token: + # 指定 Cookie 模式下自动填充 token 提交前缀 + cookie-auto-fill-prefix: true +``` + +``` properties +# 指定 Cookie 模式下自动填充 token 提交前缀 +sa-token.cookie-auto-fill-prefix=true +``` + -> [!WARNING| label:注意点] -> 1. Token前缀 与 Token值 之间必须有一个空格。 -> 2. 一旦配置了 Token前缀,则前端提交 `Token` 时,必须带有前缀,否则会导致框架无法读取 Token。 -> 3. 由于`Cookie`中无法存储空格字符,所以配置 Token 前缀后,Cookie 模式将会失效,此时只能将 Token 提交到`header`里进行传输。 diff --git a/sa-token-doc/use/config.md b/sa-token-doc/use/config.md index 64a01142..8e099a3a 100644 --- a/sa-token-doc/use/config.md +++ b/sa-token-doc/use/config.md @@ -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 联动 |