Skip to content

Commit

Permalink
docs: fix incorrect description in jwt keyfunc (#799)
Browse files Browse the repository at this point in the history
Co-authored-by: Jiun Lee <[email protected]>
  • Loading branch information
justlorain and Skyenought authored Oct 5, 2023
1 parent 83b80c7 commit 34bdbe9
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ authMiddleware, err := jwt.New(&jwt.HertzJWTMiddleware{

### KeyFunc

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.
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.

**Note: `KeyFunc` only takes effect when the token is parsed, not when the token is issued**

Function signatures:

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

### TokenLookup

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.
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.

Sample Code:

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,9 @@ authMiddleware, err := jwt.New(&jwt.HertzJWTMiddleware{

### KeyFunc

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

**注意:`KeyFunc` 只在解析 token 时生效,签发 token 时不生效**

函数签名:

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

### TokenLookup

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

示例代码:

Expand Down

1 comment on commit 34bdbe9

@vercel
Copy link

@vercel vercel bot commented on 34bdbe9 Oct 5, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.