Skip to content

Commit 34bdbe9

Browse files
docs: fix incorrect description in jwt keyfunc (#799)
Co-authored-by: Jiun Lee <[email protected]>
1 parent 83b80c7 commit 34bdbe9

File tree

2 files changed

+8
-4
lines changed
  • content
    • en/docs/hertz/tutorials/basic-feature/middleware
    • zh/docs/hertz/tutorials/basic-feature/middleware

2 files changed

+8
-4
lines changed

content/en/docs/hertz/tutorials/basic-feature/middleware/jwt.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ authMiddleware, err := jwt.New(&jwt.HertzJWTMiddleware{
201201

202202
### KeyFunc
203203

204-
The program executes with `KeyFunc` as a parameter to `jwt.Parse()`, which is responsible for providing the signing key for token parsing. By customizing the logic of `KeyFunc`, you can perform some custom operations before parsing the token, such as checking the validity of the signing method, selecting the corresponding signing key, storing the token in the request context, etc.
204+
The program executes with `KeyFunc` as a parameter to `jwt.Parse()`, which is responsible for providing the signing key for token parsing. By customizing the logic of `KeyFunc`, you can perform some custom operations before parsing the token, such as checking the validity of the signing method.
205+
206+
**Note: `KeyFunc` only takes effect when the token is parsed, not when the token is issued**
205207

206208
Function signatures:
207209

@@ -442,7 +444,7 @@ auth.GET("/refresh_token", authMiddleware.RefreshHandler)
442444

443445
### TokenLookup
444446

445-
There are four options for declaring the source of a token as a key-value pair, with the default value being `header:Authorization`. If more than one token source is declared, the first that satisfies the input format is selected while the rest are ignored.
447+
There are four options for declaring the source of a token as a key-value pair, with the default value being `header:Authorization`. If more than one token source is declared, the first that satisfies the input format is selected, separated by `,`. If the token is not obtained, it will continue to obtain token from the next declared data source.
446448

447449
Sample Code:
448450

content/zh/docs/hertz/tutorials/basic-feature/middleware/jwt.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,9 @@ authMiddleware, err := jwt.New(&jwt.HertzJWTMiddleware{
201201

202202
### KeyFunc
203203

204-
程序执行时 `KeyFunc` 作为 `jwt.Parse()` 的参数,负责为 token 解析提供签名密钥,通过自定义 `KeyFunc` 的逻辑,可以在解析 token 之前完成一些自定义的操作,如:校验签名方法的有效性、选择对应的签名密钥、将 token 存入请求上下文等。
204+
程序执行时 `KeyFunc` 作为 `jwt.Parse()` 的参数,负责为 token 解析提供签名密钥,通过自定义 `KeyFunc` 的逻辑,可以在解析 token 之前完成一些自定义的操作,如:校验签名方法的有效性。
205+
206+
**注意:`KeyFunc` 只在解析 token 时生效,签发 token 时不生效**
205207

206208
函数签名:
207209

@@ -442,7 +444,7 @@ auth.GET("/refresh_token", authMiddleware.RefreshHandler)
442444

443445
### TokenLookup
444446

445-
通过键值对的形式声明 token 的获取源,有四种可选的方式,默认值为 header:Authorization,如果同时声明了多个数据源则以 `` 为分隔线,第一个满足输入格式的数据源将被选择,其余忽略
447+
通过键值对的形式声明 token 的获取源,有四种可选的方式,默认值为 header:Authorization,如果同时声明了多个数据源则以 `,` 为分隔线,第一个满足输入格式的数据源将被选择,如果没有获取到 token 则继续从下一个声明的数据源获取
446448

447449
示例代码:
448450

0 commit comments

Comments
 (0)