This is an automated email from the ASF dual-hosted git repository.

wenming pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/apisix.git


The following commit(s) were added to refs/heads/master by this push:
     new de41e9c49 docs: improve `jwt-auth` plugin docs and update docs for 
anonymous consumer (#11865)
de41e9c49 is described below

commit de41e9c49c40e963027896e19edced1601aabdfd
Author: Traky Deng <[email protected]>
AuthorDate: Tue Apr 8 16:10:26 2025 +0800

    docs: improve `jwt-auth` plugin docs and update docs for anonymous consumer 
(#11865)
---
 docs/en/latest/plugins/jwt-auth.md | 892 ++++++++++++++++++++++++++++++++-----
 docs/zh/latest/plugins/jwt-auth.md | 868 ++++++++++++++++++++++++++++++++----
 2 files changed, 1556 insertions(+), 204 deletions(-)

diff --git a/docs/en/latest/plugins/jwt-auth.md 
b/docs/en/latest/plugins/jwt-auth.md
index f52d3cec5..773a304e9 100644
--- a/docs/en/latest/plugins/jwt-auth.md
+++ b/docs/en/latest/plugins/jwt-auth.md
@@ -6,7 +6,7 @@ keywords:
   - Plugin
   - JWT Auth
   - jwt-auth
-description: This document contains information about the Apache APISIX 
jwt-auth Plugin.
+description: The jwt-auth Plugin supports the use of JSON Web Token (JWT) as a 
mechanism for clients to authenticate themselves before accessing Upstream 
resources.
 ---
 
 <!--
@@ -28,48 +28,55 @@ description: This document contains information about the 
Apache APISIX jwt-auth
 #
 -->
 
+<head>
+  <link rel="canonical" href="https://docs.api7.ai/hub/jwt-auth"; />
+</head>
+
 ## Description
 
-The `jwt-auth` Plugin is used to add [JWT](https://jwt.io/) authentication to 
a [Service](../terminology/service.md) or a [Route](../terminology/route.md).
+The `jwt-auth` Plugin supports the use of [JSON Web Token 
(JWT)](https://jwt.io/) as a mechanism for clients to authenticate themselves 
before accessing Upstream resources.
+
+Once enabled, the Plugin exposes an endpoint to create JWT credentials by 
[Consumers](../terminology/consumer.md). The process generates a token that 
client requests should carry to identify themselves to APISIX. The token can be 
included in the request URL query string, request header, or cookie. APISIX 
will then verify the token to determine if a request should be allowed or 
denied to access Upstream resources.
 
-A [Consumer](../terminology/consumer.md) of the service then needs to provide 
a key through a query string, a request header or a cookie to verify its 
request.
+When a Consumer is successfully authenticated, APISIX adds additional headers, 
such as `X-Consumer-Username`, `X-Credential-Indentifier`, and other Consumer 
custom headers if configured, to the request, before proxying it to the 
Upstream service. The Upstream service will be able to differentiate between 
consumers and implement additional logics as needed. If any of these values is 
not available, the corresponding header will not be added.
 
 ## Attributes
 
-For Consumer:
+For Consumer/Credential:
 
 | Name          | Type    | Required                                           
   | Default | Valid values                | Description                        
                                                                                
                                                                         |
 
|---------------|---------|-------------------------------------------------------|---------|-----------------------------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| key           | string  | True                                               
   |         |                             | Unique key for a Consumer.         
                                                                                
                                                                         |
-| secret        | string  | False                                              
   |         |                             | The encryption key. If 
unspecified, auto generated in the background. This field supports saving the 
value in Secret Manager using the [APISIX Secret](../terminology/secret.md) 
resource.       |
+| key           | string  | True                                               
   |         |     non-empty       | Unique key for a Consumer.                 
                                                                                
                                                                 |
+| secret        | string  | False                                              
   |         |        non-empty        | Shared key used to sign and verify the 
JWT when the algorithm is symmetric. Required when using `HS256` or `HS512` as 
the algorithm. If unspecified, the secret will be auto-generated. This field 
supports saving the value in Secret Manager using the [APISIX 
Secret](../terminology/secret.md) resource.       |
 | public_key    | string  | True if `RS256` or `ES256` is set for the 
`algorithm` attribute. |         |                             | RSA or ECDSA 
public key. This field supports saving the value in Secret Manager using the 
[APISIX Secret](../terminology/secret.md) resource.                      |
-| algorithm     | string  | False                                              
   | "HS256" | ["HS256", "HS512", "RS256", "ES256"] | Encryption algorithm.     
                                                                                
                                                                                
  |
+| algorithm     | string  | False                                              
   | HS256 | ["HS256", "HS512", "RS256", "ES256"] | Encryption algorithm.       
                                                                                
                                                                                
|
 | exp           | integer | False                                              
   | 86400   | [1,...]                     | Expiry time of the token in 
seconds.                                                                        
                                                                                
|
 | base64_secret | boolean | False                                              
   | false   |                             | Set to true if the secret is 
base64 encoded.                                                                 
                                                                               |
-| lifetime_grace_period | integer | False                                      
   | 0       | [0,...]                     | Define the leeway in seconds to 
account for clock skew between the server that generated the jwt and the server 
validating it. Value should be zero (0) or a positive integer. |
+| lifetime_grace_period | integer | False                                      
   | 0       | [0,...]                     | Grace period in seconds. Used to 
account for clock skew between the server generating the JWT and the server 
validating the JWT.  |
+| key_claim_name | string | False                                              
   | key     |                             | The claim in the JWT payload that 
identifies the associated secret, such as `iss`. |
 
 NOTE: `encrypt_fields = {"secret"}` is also defined in the schema, which means 
that the field will be stored encrypted in etcd. See [encrypted storage 
fields](../plugin-develop.md#encrypted-storage-fields).
 
-For Route:
+For Routes or Services:
 
-| Name             | Type    | Required | Default       | Description          
                                                                                
                                                                |
-|------------------|---------|----------|---------------|----------------------------------------------------------------------------------------------------------------------------------------------------------------------|
-| header           | string  | False    | authorization | The header to get 
the token from.                                                                 
                                                                   |
-| query            | string  | False    | jwt           | The query string to 
get the token from. Lower priority than header.                                 
                                                                 |
-| cookie           | string  | False    | jwt           | The cookie to get 
the token from. Lower priority than query.                                      
                                                                   |
-| hide_credentials | boolean | False    | false         | Set to true will not 
pass the authorization request of header\query\cookie to the Upstream.          
                                                                |
-| key_claim_name   | string  | False    | key           | The name of the JWT 
claim that contains the user key (corresponds to Consumer's key attribute).     
                                                                 |
-| store_in_ctx     | boolean | False    | false         | Set to true will 
store the JWT payload in the request context (`ctx.jwt_auth_payload`). This 
allows lower-priority plugins that run afterwards on the same request to 
retrieve and use the JWT token. |
+| Name   | Type   | Required | Default       | Description                     
                                    |
+|--------|--------|----------|---------------|---------------------------------------------------------------------|
+| header | string | False    | authorization | The header to get the token 
from.                                   |
+| query  | string | False    | jwt           | The query string to get the 
token from. Lower priority than header. |
+| cookie | string | False    | jwt           | The cookie to get the token 
from. Lower priority than query.        |
+| hide_credentials| boolean | False    | false  | If true, do not pass the 
header, query, or cookie with JWT to Upstream services.  |
+| key_claim_name  | string  | False    | key     | The name of the JWT claim 
that contains the user key (corresponds to Consumer's key attribute). |
+| anonymous_consumer | string | False  | false  | Anonymous Consumer name. If 
configured, allow anonymous users to bypass the authentication.   |
+| store_in_ctx     | boolean | False    | false   | Set to true will store the 
JWT payload in the request context (`ctx.jwt_auth_payload`). This allows 
lower-priority plugins that run afterwards on the same request to retrieve and 
use the JWT token. |
 
 You can implement `jwt-auth` with [HashiCorp 
Vault](https://www.vaultproject.io/) to store and fetch secrets and RSA keys 
pairs from its [encrypted KV 
engine](https://developer.hashicorp.com/vault/docs/secrets/kv) using the 
[APISIX Secret](../terminology/secret.md) resource.
 
-## Enable Plugin
-
-To enable the Plugin, you have to create a Consumer object with the JWT token 
and configure your Route to use JWT authentication.
+## Examples
 
-First, you can create a Consumer object through the Admin API:
+The examples below demonstrate how you can work with the `jwt-auth` Plugin for 
different scenarios.
 
 :::note
+
 You can fetch the `admin_key` from `config.yaml` and save to an environment 
variable with the following command:
 
 ```bash
@@ -78,154 +85,827 @@ admin_key=$(yq '.deployment.admin.admin_key[0].key' 
conf/config.yaml | sed 's/"/
 
 :::
 
+### Use JWT for Consumer Authentication
+
+The following example demonstrates how to implement JWT for Consumer key 
authentication.
+
+Create a Consumer `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+Create `jwt-auth` Credential for the Consumer:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
+    }
+  }'
+```
+
+Create a Route with `jwt-auth` plugin:
+
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" 
-X PUT -d '
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/headers",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+To issue a JWT for `jack`, you could use [JWT.io's 
debugger](https://jwt.io/#debugger-io) or other utilities. If you are using 
[JWT.io's debugger](https://jwt.io/#debugger-io), do the following:
+
+* Select __HS256__ in the __Algorithm__ dropdown.
+* Update the secret in the __Verify Signature__ section to be 
`jack-hs256-secret`.
+* Update payload with Consumer key `jack-key`; and add `exp` or `nbf` in UNIX 
timestamp.
+
+  Your payload should look similar to the following:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+Copy the generated JWT under the __Encoded__ section and save to a variable:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
+
+Send a request to the Route with the JWT in the `Authorization` header:
+
+```shell
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
+```
+
+You should receive an `HTTP/1.1 200 OK` response similar to the following:
+
+```text
 {
-    "username": "jack",
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjY2NDk2NDAsImtleSI6ImphY2sta2V5In0.kdhumNWrZFxjUvYzWLt4lFr546PNsr9TXuf0Az5opoM",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/8.6.0",
+    "X-Amzn-Trace-Id": "Root=1-66ea951a-4d740d724bd2a44f174d4daf",
+    "X-Consumer-Username": "jack",
+    "X-Credential-Identifier": "cred-jack-jwt-auth",
+    "X-Forwarded-Host": "127.0.0.1"
+  }
+}
+```
+
+In 30 seconds, the token should expire. Send a request with the same token to 
verify:
+
+```shell
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
+```
+
+You should receive an `HTTP/1.1 401 Unauthorized` response similar to the 
following:
+
+```text
+{"message":"failed to verify jwt"}
+```
+
+### Carry JWT in Request Header, Query String, or Cookie
+
+The following example demonstrates how to accept JWT in specified header, 
query string, and cookie.
+
+Create a Consumer `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+Create `jwt-auth` Credential for the Consumer:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
     "plugins": {
-        "jwt-auth": {
-            "key": "user-key",
-            "secret": "my-secret-key"
-        }
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
     }
-}'
+  }'
 ```
 
-:::note
+Create a Route with `jwt-auth` Plugin, and specify that the request can either 
carry the token in the header, query, or the cookie:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/get",
+    "plugins": {
+      "jwt-auth": {
+        "header": "jwt-auth-header",
+        "query": "jwt-query",
+        "cookie": "jwt-cookie"
+      }
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+To issue a JWT for `jack`, you could use [JWT.io's 
debugger](https://jwt.io/#debugger-io) or other utilities. If you are using 
[JWT.io's debugger](https://jwt.io/#debugger-io), do the following:
+
+* Select __HS256__ in the __Algorithm__ dropdown.
+* Update the secret in the __Verify Signature__ section to be 
`jack-hs256-secret`.
+* Update payload with Consumer key `jack-key`; and add `exp` or `nbf` in UNIX 
timestamp.
+
+  Your payload should look similar to the following:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+Copy the generated JWT under the __Encoded__ section and save to a variable:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
 
-The `jwt-auth` Plugin uses the HS256 algorithm by default. To use the RS256 
algorithm, you can configure the public key and specify the algorithm:
+#### Verify With JWT in Header
+
+Sending request with JWT in the header:
+
+```shell
+curl -i "http://127.0.0.1:9080/get"; -H "jwt-auth-header: ${jwt_token}"
+```
+
+You should receive an `HTTP/1.1 200 OK` response similar to the following:
+
+```text
+{
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Host": "127.0.0.1",
+    "Jwt-Auth-Header": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ",
+    ...
+  },
+  ...
+}
+```
+
+#### Verify With JWT in Query String
+
+Sending request with JWT in the query string:
+
+```shell
+curl -i "http://127.0.0.1:9080/get?jwt-query=${jwt_token}";
+```
+
+You should receive an `HTTP/1.1 200 OK` response similar to the following:
+
+```text
+{
+  "args": {
+    "jwt-query": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ"
+  },
+  "headers": {
+    "Accept": "*/*",
+    ...
+  },
+  "origin": "127.0.0.1, 183.17.233.107",
+  "url": 
"http://127.0.0.1/get?jwt-query=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ";
+}
+```
+
+#### Verify With JWT in Cookie
+
+Sending request with JWT in the cookie:
 
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/consumers -H "X-API-KEY: $admin_key" 
-X PUT -d '
+curl -i "http://127.0.0.1:9080/get"; --cookie jwt-cookie=${jwt_token}
+```
+
+You should receive an `HTTP/1.1 200 OK` response similar to the following:
+
+```text
 {
-    "username": "kerouac",
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Cookie": 
"jwt-cookie=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ",
+    ...
+  },
+  ...
+}
+```
+
+### Manage Secrets in Environment Variables
+
+The following example demonstrates how to save `jwt-auth` Consumer key to an 
environment variable and reference it in configuration.
+
+APISIX supports referencing system and user environment variables configured 
through the [NGINX `env` 
directive](https://nginx.org/en/docs/ngx_core_module.html#env).
+
+Save the key to an environment variable:
+
+```shell
+JACK_JWT_AUTH_KEY=jack-key
+```
+
+Create a Consumer `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+Create `jwt-auth` Credential for the Consumer and reference the environment 
variable in the key:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
     "plugins": {
-        "jwt-auth": {
-            "key": "user-key",
-            "public_key": "-----BEGIN PUBLIC KEY-----\n……\n-----END PUBLIC 
KEY-----",
-            "algorithm": "RS256"
-        }
+      "jwt-auth": {
+        "key": "$env://JACK_JWT_AUTH_KEY",
+        "secret": "jack-hs256-secret"
+      }
     }
-}'
+  }'
 ```
 
-:::
+Create a Route with `jwt-auth` enabled:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/get",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+To issue a JWT for `jack`, you could use [JWT.io's 
debugger](https://jwt.io/#debugger-io) or other utilities. If you are using 
[JWT.io's debugger](https://jwt.io/#debugger-io), do the following:
+
+* Select __HS256__ in the __Algorithm__ dropdown.
+* Update the secret in the __Verify Signature__ section to be 
`jack-hs256-secret`.
+* Update payload with Consumer key `jack-key`; and add `exp` or `nbf` in UNIX 
timestamp.
+
+  Your payload should look similar to the following:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+Copy the generated JWT under the __Encoded__ section and save to a variable:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
 
-Once you have created a Consumer object, you can configure a Route to 
authenticate requests:
+Sending request with JWT in the header:
 
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X 
PUT -d '
+curl -i "http://127.0.0.1:9080/get"; -H "Authorization: ${jwt_token}"
+```
+
+You should receive an `HTTP/1.1 200 OK` response similar to the following:
+
+```text
 {
-    "methods": ["GET"],
-    "uri": "/index.html",
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTUxMzMxNTUsImtleSI6Imp3dC1rZXkifQ.jiKuaAJqHNSSQCjXRomwnQXmdkC5Wp5VDPRsJlh1WAQ",
+    ...
+  },
+  ...
+}
+```
+
+### Manage Secrets in Secret Manager
+
+The following example demonstrates how to manage `jwt-auth` Consumer key in 
[HashiCorp Vault](https://www.vaultproject.io) and reference it in Plugin 
configuration.
+
+Start a Vault development server in Docker:
+
+```shell
+docker run -d \
+  --name vault \
+  -p 8200:8200 \
+  --cap-add IPC_LOCK \
+  -e VAULT_DEV_ROOT_TOKEN_ID=root \
+  -e VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200 \
+  vault:1.9.0 \
+  vault server -dev
+```
+
+APISIX currently supports [Vault KV engine version 
1](https://developer.hashicorp.com/vault/docs/secrets/kv#kv-version-1). Enable 
it in Vault:
+
+```shell
+docker exec -i vault sh -c "VAULT_TOKEN='root' 
VAULT_ADDR='http://0.0.0.0:8200' vault secrets enable -path=kv -version=1 kv"
+```
+
+You should see a response similar to the following:
+
+```text
+Success! Enabled the kv secrets engine at: kv/
+```
+
+Create a secret and configure the Vault address and other connection 
information:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/secrets/vault/jwt"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "uri": "https://127.0.0.1:8200",
+    "prefix": "kv/apisix",
+    "token": "root"
+  }'
+```
+
+Create a Consumer `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+Create `jwt-auth` Credential for the Consumer and reference the secret in the 
key:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "$secret://vault/jwt/jack/jwt-key",
+        "secret": "vault-hs256-secret"
+      }
+    }
+  }'
+```
+
+Create a Route with `jwt-auth` enabled:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/get",
     "plugins": {
-        "jwt-auth": {}
+      "jwt-auth": {}
     },
     "upstream": {
-        "type": "roundrobin",
-        "nodes": {
-            "127.0.0.1:1980": 1
-        }
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
     }
-}'
+  }'
 ```
 
-<!--
-![create a consumer](../../../assets/images/plugin/jwt-auth-1.png)
-![enable jwt plugin](../../../assets/images/plugin/jwt-auth-2.png)
-![enable jwt from route or 
service](../../../assets/images/plugin/jwt-auth-3.png)
--->
+Set `jwt-auth` key value to be `jwt-vault-key` in Vault:
 
-## Example usage
+```shell
+docker exec -i vault sh -c "VAULT_TOKEN='root' 
VAULT_ADDR='http://0.0.0.0:8200' vault kv put kv/apisix/jack 
jwt-key=jwt-vault-key"
+```
 
-You need first to issue a JWT token using some tool such as [JWT.io's 
debugger](https://jwt.io/#debugger-io) or a programming language.
+You should see a response similar to the following:
 
-:::note
+```text
+Success! Data written to: kv/apisix/jack
+```
 
-When you are issuing a JWT token, you have to update the payload with `key` 
matching the credential key you would like to use; and `exp` or `nbf` in UNIX 
timestamp.
+To issue a JWT, you could use [JWT.io's debugger](https://jwt.io/#debugger-io) 
or other utilities. If you are using [JWT.io's 
debugger](https://jwt.io/#debugger-io), do the following:
 
-e.g. payload=`{"key": "user-key", "exp": 1727274983}`
+* Select __HS256__ in the __Algorithm__ dropdown.
+* Update the secret in the __Verify Signature__ section to be 
`vault-hs256-secret`.
+* Update payload with Consumer key `jwt-vault-key`; and add `exp` or `nbf` in 
UNIX timestamp.
 
-:::
+  Your payload should look similar to the following:
+
+  ```json
+  {
+    "key": "jwt-vault-key",
+    "nbf": 1729132271
+  }
+  ```
 
-You can now use this token while making requests:
+Copy the generated JWT under the __Encoded__ section and save to a variable:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqd3QtdmF1bHQta2V5IiwibmJmIjoxNzI5MTMyMjcxfQ.faiN93LNP1lGSXqAb4empNJKMRWop8-KgnU58VQn1EE
+```
+
+Sending request with the token as header:
 
 ```shell
-curl http://127.0.0.1:9080/index.html -H 'Authorization: 
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2NDA1MDgxMX0.Us8zh_4VjJXF-TmR5f8cif8mBU7SuefPlpxhH0jbPVI'
 -i
+curl -i "http://127.0.0.1:9080/get"; -H "Authorization: ${jwt_token}"
 ```
 
+You should receive an `HTTP/1.1 200 OK` response similar to the following:
+
+```text
+{
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqd3QtdmF1bHQta2V5IiwiZXhwIjoxNjk1MTM4NjM1fQ.Au2liSZ8eQXUJR3SJESwNlIfqZdNyRyxIJK03L4dk_g",
+    ...
+  },
+  ...
+}
 ```
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 13175
-...
-Accept-Ranges: bytes
 
-<!DOCTYPE html>
-<html lang="cn">
-...
+### Sign JWT with RS256 Algorithm
+
+The following example demonstrates how you can use asymmetric algorithms, such 
as RS256, to sign and validate JWT when implementing JWT for Consumer 
authentication. You will be generating RSA key pairs using 
[openssl](https://openssl-library.org/source/) and generating JWT using 
[JWT.io](https://jwt.io/#debugger-io) to better understand the composition of 
JWT.
+
+Generate a 2048-bit RSA private key and extract the corresponding public key 
in PEM format:
+
+```shell
+openssl genrsa -out jwt-rsa256-private.pem 2048
+openssl rsa -in jwt-rsa256-private.pem -pubout -out jwt-rsa256-public.pem
 ```
 
-Without the token, you will receive an error:
+You should see `jwt-rsa256-private.pem` and `jwt-rsa256-public.pem` generated 
in your current working directory.
+
+Visit [JWT.io's debugger](https://jwt.io/#debugger-io) and do the following:
+
+* Select __RS256__ in the __Algorithm__ dropdown.
+* Copy and paste the key content into the __Verify Signature__ section.
+* Update the payload with `key` matching the Consumer key you would like to 
use; and `exp` or `nbf` in UNIX timestamp.
+
+The configuration should look similar to the following:
+
+<br />
+<div style={{textAlign: 'center'}}>
+<img
+  src="https://static.apiseven.com/uploads/2024/12/12/SRe7AXMw_jwt_token.png";
+  alt="complete configuration of JWT generation on jwt.io"
+  width="70%"
+/>
+</div>
+<br />
+
+Copy the JWT on the left and save to an environment variable:
 
 ```shell
-HTTP/1.1 401 Unauthorized
-...
-{"message":"Missing JWT token in request"}
+jwt_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsImV4cCI6MTczNDIzMDQwMH0.XjqM0oszmCggwZs-8PUIlJv8wPJON1la2ET5v70E6TCE32Yq5ibrl-1azaK7IreAer3HtnVHeEfII2rR02v8xfR1TPIjU_oHov4qC-A4tLTbgqGVXI7fCy2WFm3PFh6MEKuRe6M3dCQtCAdkRRQrBr1gWFQZhV3TNeMmmtyIfuJpB7cp4DW5pYFsCcoE1Nw6Tz7dt8k0tPBTPI2Mv9AYfMJ30LHDscOaPNtz8YIk_TOkV9b9mhQudUJ7J_suCZMRxD3iL655jTp2gKsstGKdZa0_W9Reu4-HY3LSc5DS1XtfjuftpuUqgg9FvPU0mK_b0wT_Rq3lbYhcHb9GZ72qiQ
 ```
 
-You can also pass the token as query parameters:
+Create a Consumer `jack`:
 
 ```shell
-curl 
http://127.0.0.1:9080/index.html?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2NDA1MDgxMX0.Us8zh_4VjJXF-TmR5f8cif8mBU7SuefPlpxhH0jbPVI
 -i
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
 ```
 
+Create `jwt-auth` Credential for the Consumer and configure the RSA keys:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "algorithm": "RS256",
+        "public_key": "-----BEGIN PUBLIC 
KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnE0h4k/GWfEbYO/yE2MPjHtNKDLNz4mv1KNIPLxY2ccjPYOtjuug+iZ4MujLV59YfrHriTs0H8jweQfff3pRSMjyEK+4qWTY3TeKBXIEa3pVDeoedSJrgjLBVio6xH7et8ir+QScScfLaJHGB4/l3DDGyEhO782a9teY8brn5hsWX5uLmDJvxtTGAHYi847XOcx2UneW4tZ8wQ6JGBSiSg5qAHan4dFZ7CpixCNNqEcSK6EQ7lKOLeFGG8ys/dHBIEasU4oMlCuJH77+XQQ/shchy+vm9oZfP+grLZkV+nKAd8MQZsid7ZJ/fiB/BmnhGrjtIfh98jwxSx4DgdLhdwIDAQAB\n-----END
 PUBLIC KEY-----",
+        "private_key": "-----BEGIN PRIVATE 
KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCcTSHiT8ZZ8Rtg7/ITYw+Me00oMs3Pia/Uo0g8vFjZxyM9g62O66D6Jngy6MtXn1h+seuJOzQfyPB5B99/elFIyPIQr7ipZNjdN4oFcgRrelUN6h51ImuCMsFWKjrEft63yKv5BJxJx8tokcYHj+XcMMbISE7vzZr215jxuufmGxZfm4uYMm/G1MYAdiLzjtc5zHZSd5bi1nzBDokYFKJKDmoAdqfh0VnsKmLEI02oRxIroRDuUo4t4UYbzKz90cEgRqxTigyUK4kfvv5dBD+yFyHL6+b2hl8/6CstmRX6coB3wxBmyJ3tkn9+IH8GaeEauO0h+H3yPDFLHgOB0uF3AgMBAAECggEARpY68Daw0Funzq5uN70r/3iLztSqx8hZpQE
 [...]
+      }
+    }
+  }'
 ```
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 13175
-...
-Accept-Ranges: bytes
 
-<!DOCTYPE html>
-<html lang="cn">
-...
+:::tip
+
+You should add a newline character after the opening line and before the 
closing line, for example `-----BEGIN PRIVATE KEY-----\n......\n-----END 
PRIVATE KEY-----`.
+
+The key content can be directly concatenated.
+
+:::
+
+Create a Route with the `jwt-auth` Plugin:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/headers",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
 ```
 
-And also as cookies:
+To verify, send a request to the Route with the JWT in the `Authorization` 
header:
 
 ```shell
-curl http://127.0.0.1:9080/index.html --cookie 
jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2NDA1MDgxMX0.Us8zh_4VjJXF-TmR5f8cif8mBU7SuefPlpxhH0jbPVI
 -i
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
 ```
 
+You should receive an `HTTP/1.1 200 OK` response similar to the following:
+
+```json
+{
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsImV4cCI6MTczNDIzMDQwMH0.XjqM0oszmCggwZs-8PUIlJv8wPJON1la2ET5v70E6TCE32Yq5ibrl-1azaK7IreAer3HtnVHeEfII2rR02v8xfR1TPIjU_oHov4qC-A4tLTbgqGVXI7fCy2WFm3PFh6MEKuRe6M3dCQtCAdkRRQrBr1gWFQZhV3TNeMmmtyIfuJpB7cp4DW5pYFsCcoE1Nw6Tz7dt8k0tPBTPI2Mv9AYfMJ30LHDscOaPNtz8YIk_TOkV9b9mhQudUJ7J_suCZMRxD3iL655jTp2gKsstGKdZa0_W9Reu4-HY3LSc5DS1XtfjuftpuUqgg9FvPU0mK_b0wT_Rq3lbYhcHb9GZ72qiQ",
+    ...
+  }
+}
 ```
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 13175
-...
-Accept-Ranges: bytes
 
-<!DOCTYPE html>
-<html lang="cn">
-...
+### Add Consumer Custom ID to Header
+
+The following example demonstrates how you can attach a Consumer custom ID to 
authenticated request in the `Consumer-Custom-Id` header, which can be used to 
implement additional logics as needed.
+
+Create a Consumer `jack` with a custom ID label:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack",
+    "labels": {
+      "custom_id": "495aec6a"
+    }
+  }'
 ```
 
-## Delete Plugin
+Create `jwt-auth` Credential for the Consumer:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
+    }
+  }'
+```
 
-To remove the `jwt-auth` Plugin, you can delete the corresponding JSON 
configuration from the Plugin configuration. APISIX will automatically reload 
and you do not have to restart for this to take effect.
+Create a Route with `jwt-auth`:
 
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/routes/1 -H "X-API-KEY: $admin_key" -X 
PUT -d '
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-auth-route",
+    "uri": "/anything",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+To issue a JWT for `jack`, you could use [JWT.io's 
debugger](https://jwt.io/#debugger-io) or other utilities. If you are using 
[JWT.io's debugger](https://jwt.io/#debugger-io), do the following:
+
+* Select __HS256__ in the __Algorithm__ dropdown.
+* Update the secret in the __Verify Signature__ section to be 
`jack-hs256-secret`.
+* Update payload with Consumer key `jack-key`; and add `exp` or `nbf` in UNIX 
timestamp.
+
+  Your payload should look similar to the following:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+Copy the generated JWT under the __Encoded__ section and save to a variable:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
+
+To verify, send a request to the Route with the JWT in the `Authorization` 
header:
+
+```shell
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
+```
+
+You should see an `HTTP/1.1 200 OK` response similar to the following, where 
`X-Consumer-Custom-Id` is attached:
+
+```json
 {
-    "methods": ["GET"],
-    "uri": "/index.html",
-    "id": 1,
-    "plugins": {},
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjY2NDk2NDAsImtleSI6ImphY2sta2V5In0.kdhumNWrZFxjUvYzWLt4lFr546PNsr9TXuf0Az5opoM",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/8.6.0",
+    "X-Amzn-Trace-Id": "Root=1-66ea951a-4d740d724bd2a44f174d4daf",
+    "X-Consumer-Username": "jack",
+    "X-Credential-Identifier": "cred-jack-jwt-auth",
+    "X-Consumer-Custom-Id": "495aec6a",
+    "X-Forwarded-Host": "127.0.0.1"
+  }
+}
+```
+
+### Rate Limit with Anonymous Consumer
+
+The following example demonstrates how you can configure different rate 
limiting policies by regular and anonymous consumers, where the anonymous 
Consumer does not need to authenticate and has less quotas.
+
+Create a regular Consumer `jack` and configure the `limit-count` Plugin to 
allow for a quota of 3 within a 30-second window:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack",
+    "plugins": {
+      "limit-count": {
+        "count": 3,
+        "time_window": 30,
+        "rejected_code": 429
+      }
+    }
+  }'
+```
+
+Create the `jwt-auth` Credential for the Consumer `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
+    }
+  }'
+```
+
+Create an anonymous user `anonymous` and configure the `limit-count` Plugin to 
allow for a quota of 1 within a 30-second window:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "anonymous",
+    "plugins": {
+      "limit-count": {
+        "count": 1,
+        "time_window": 30,
+        "rejected_code": 429
+      }
+    }
+  }'
+```
+
+Create a Route and configure the `jwt-auth` Plugin to accept anonymous 
Consumer `anonymous` from bypassing the authentication:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-auth-route",
+    "uri": "/anything",
+    "plugins": {
+      "jwt-auth": {
+        "anonymous_consumer": "anonymous"
+      }
+    },
     "upstream": {
-        "type": "roundrobin",
-        "nodes": {
-            "127.0.0.1:1980": 1
-        }
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
     }
-}'
+  }'
+```
+
+To issue a JWT for `jack`, you could use [JWT.io's 
debugger](https://jwt.io/#debugger-io) or other utilities. If you are using 
[JWT.io's debugger](https://jwt.io/#debugger-io), do the following:
+
+* Select __HS256__ in the __Algorithm__ dropdown.
+* Update the secret in the __Verify Signature__ section to be 
`jack-hs256-secret`.
+* Update payload with role `user`, permission `read`, and Consumer key 
`jack-key`; as well as `exp` or `nbf` in UNIX timestamp.
+
+  Your payload should look similar to the following:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+Copy the generated JWT under the __Encoded__ section and save to a variable:
+
+```shell
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.hjtSsEILpko14zb8-ibyxrB2tA5biYY9JrFm3do69vs
+```
+
+To verify the rate limiting, send five consecutive requests with `jack`'s JWT:
+
+```shell
+resp=$(seq 5 | xargs -I{} curl "http://127.0.0.1:9080/anything"; -H 
"Authorization: ${jwt_token}" -o /dev/null -s -w "%{http_code}\n") && \
+  count_200=$(echo "$resp" | grep "200" | wc -l) && \
+  count_429=$(echo "$resp" | grep "429" | wc -l) && \
+  echo "200": $count_200, "429": $count_429
+```
+
+You should see the following response, showing that out of the 5 requests, 3 
requests were successful (status code 200) while the others were rejected 
(status code 429).
+
+```text
+200:    3, 429:    2
+```
+
+Send five anonymous requests:
+
+```shell
+resp=$(seq 5 | xargs -I{} curl "http://127.0.0.1:9080/anything"; -o /dev/null 
-s -w "%{http_code}\n") && \
+  count_200=$(echo "$resp" | grep "200" | wc -l) && \
+  count_429=$(echo "$resp" | grep "429" | wc -l) && \
+  echo "200": $count_200, "429": $count_429
+```
+
+You should see the following response, showing that only one request was 
successful:
+
+```text
+200:    1, 429:    4
 ```
diff --git a/docs/zh/latest/plugins/jwt-auth.md 
b/docs/zh/latest/plugins/jwt-auth.md
index 0111e9e03..8977d8283 100644
--- a/docs/zh/latest/plugins/jwt-auth.md
+++ b/docs/zh/latest/plugins/jwt-auth.md
@@ -6,7 +6,7 @@ keywords:
   - Plugin
   - JWT Auth
   - jwt-auth
-description: 本文介绍了关于 Apache APISIX `jwt-auth` 插件的基本信息及使用方法。
+description: jwt-auth 插件支持使用 JSON Web Token (JWT) 作为客户端在访问上游资源之前进行身份验证的机制。
 ---
 
 <!--
@@ -30,23 +30,26 @@ description: 本文介绍了关于 Apache APISIX `jwt-auth` 插件的基本信
 
 ## 描述
 
-`jwt-auth` 插件用于将 [JWT](https://jwt.io/) 身份验证添加到 
[Service](../terminology/service.md) 或 [Route](../terminology/route.md) 中。
+`jwt-auth` 插件支持使用 [JSON Web Token (JWT)](https://jwt.io/) 
作为客户端在访问上游资源之前进行身份验证的机制。
 
-通过 Consumer 将其密匙添加到查询字符串参数、请求头或 `cookie` 中用来验证其请求。
+启用后,该插件会公开一个端点,供 [消费者](../terminology/consumer.md) 创建 JWT 
凭据。该过程会生成一个令牌,客户端请求应携带该令牌以向 APISIX 标识自己。该令牌可以包含在请求 URL 查询字符串、请求标头或 cookie 
中。然后,APISIX 将验证该令牌以确定是否应允许或拒绝请求访问上游资源。
+
+当消费者成功通过身份验证后,APISIX 会在将请求代理到上游服务之前向请求添加其他标头,例如 
`X-Consumer-Username`、`X-Credential-Indentifier` 
和其他消费者自定义标头(如已配置)。上游服务将能够区分消费者并根据需要实施其他逻辑。如果任何一个值不可用,则不会添加相应的标题。
 
 ## 属性
 
-Consumer 端:
+Consumer/Credential 端:
 
 | 名称          | 类型     | 必选项 | 默认值  | 有效值                      | 描述            
                                                                                
              |
 | ------------- | ------- | ----- | ------- | --------------------------- | 
------------------------------------------------------------------------------------------------------------
 |
-| key           | string  | 是    |         |                             | 
Consumer 的 `access_key` 必须是唯一的。如果不同 Consumer 使用了相同的 `access_key` ,将会出现请求匹配异常。 |
-| secret        | string  | 否    |         |                             | 
加密秘钥。如果未指定,后台将会自动生成。该字段支持使用 [APISIX Secret](../terminology/secret.md) 资源,将值保存在 
Secret Manager 中。   |
+| key           | string  | 是    |         |                             | 
消费者的唯一密钥。  |
+| secret        | string  | 否    |         |                             | 
当使用对称算法时,用于对 JWT 进行签名和验证的共享密钥。使用 `HS256` 或 `HS512` 
作为算法时必填。如果未指定,后台将会自动生成。该字段支持使用 [APISIX Secret](../terminology/secret.md) 
资源,将值保存在 Secret Manager 中。   |
 | public_key    | string  | 否    |         |                             | RSA 
或 ECDSA 公钥, `algorithm` 属性选择 `RS256` 或 `ES256` 算法时必选。该字段支持使用 [APISIX 
Secret](../terminology/secret.md) 资源,将值保存在 Secret Manager 中。       |
 | algorithm     | string  | 否    | "HS256" | ["HS256", "HS512", "RS256", 
"ES256"] | 加密算法。                                                                
                                      |
 | exp           | integer | 否    | 86400   | [1,...]                     | 
token 的超时时间。                                                                    
                          |
 | base64_secret | boolean | 否    | false   |                             | 
当设置为 `true` 时,密钥为 base64 编码。                                                    
                                     |
-| lifetime_grace_period | integer | 否    | 0  | [0,...]                  | 
定义生成 JWT 的服务器和验证 JWT 的服务器之间的时钟偏移。该值应该是零(0)或一个正整数。 |
+| lifetime_grace_period | integer | 否    | 0  | [0,...]                  | 
宽限期(以秒为单位)。用于解决生成 JWT 的服务器与验证 JWT 的服务器之间的时钟偏差。 |
+| key_claim_name | string | 否                                                 
| key     |                             | JWT payload 中的声明用于标识相关的秘密,例如 `iss`。 |
 
 注意:schema 中还定义了 `encrypt_fields = {"secret"}`,这意味着该字段将会被加密存储在 etcd 中。具体参考 
[加密存储字段](../plugin-develop.md#加密存储字段)。
 
@@ -57,17 +60,16 @@ Route 端:
 | header | string | 否     | authorization | 设置我们从哪个 header 获取 token。           
              |
 | query  | string | 否     | jwt           | 设置我们从哪个 query string 获取 
token,优先级低于 header。  |
 | cookie | string | 否     | jwt           | 设置我们从哪个 cookie 获取 token,优先级低于 
query。        |
-| hide_credentials | boolean | 否     | false  | 该参数设置为 `true` 时,则不会将含有认证信息的 
header\query\cookie 传递给 Upstream。|
+| hide_credentials | boolean | 否     | false  | 如果为 true,则不要将 header、query 或带有 
JWT 的 cookie 传递给上游服务。 |
 | key_claim_name | string  | 否     | key           | 包含用户密钥(对应消费者的密钥属性)的 JWT 
声明的名称。|
+| anonymous_consumer | string | 否     | false  | 匿名消费者名称。如果已配置,则允许匿名用户绕过身份验证。  
|
 | store_in_ctx | boolean | 否     | false  | 设置为 `true` 将会将 JWT 负载存储在请求上下文 
(`ctx.jwt_auth_payload`) 中。这允许在同一请求上随后运行的低优先级插件检索和使用 JWT 令牌。 |
 
 您可以使用 [HashiCorp Vault](https://www.vaultproject.io/) 实施 `jwt-auth`,以从其[加密的 KV 
引擎](https://developer.hashicorp.com/vault/docs/secrets/kv) 使用 [APISIX 
Secret](../terminology/secret.md) 资源。
 
-## 启用插件
-
-如果想要启用插件,就必须使用 JWT token 创建一个 Consumer 对象,并将 Route 配置为使用 JWT 身份验证。
+## 示例
 
-首先,你可以通过 Admin API 创建一个 Consumer:
+以下示例演示了如何在不同场景中使用 `jwt-auth` 插件。
 
 :::note
 
@@ -79,157 +81,827 @@ admin_key=$(yq '.deployment.admin.admin_key[0].key' 
conf/config.yaml | sed 's/"/
 
 :::
 
+### 使用 JWT 进行消费者身份验证
+
+以下示例演示如何实现 JWT 进行消费者密钥身份验证。
+
+创建消费者 `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+为消费者创建 `jwt-auth` 凭证:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
+    }
+  }'
+```
+
+使用 `jwt-auth` 插件创建路由:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/headers",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+要为 `jack` 签发 JWT,您可以使用 [JWT.io 的调试器](https://jwt.io/#debugger-io) 
或其他实用程序。如果您使用的是 [JWT.io 的调试器](https://jwt.io/#debugger-io),请执行以下操作:
+
+* 在 __Algorithm__ 下拉菜单中选择 __HS256__。
+* 将 __Verify Signature__ 部分中的密钥更新为 `jack-hs256-secret`。
+* 使用消费者密钥 `jack-key` 更新有效 payload;并在 UNIX 时间戳中添加 `exp` 或 `nbf`。
+
+  您的 payload 应类似于以下内容:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+将生成的 JWT 复制到 __Encoded__ 部分并保存到变量中:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
+
+使用 `Authorization` 标头中的 JWT 向路由发送请求:
+
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/consumers \
--H "X-API-KEY: $admin_key" -X PUT -d '
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
+```
+
+您应该收到类似于以下内容的 `HTTP/1.1 200 OK` 响应:
+
+```text
 {
-    "username": "jack",
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjY2NDk2NDAsImtleSI6ImphY2sta2V5In0.kdhumNWrZFxjUvYzWLt4lFr546PNsr9TXuf0Az5opoM",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/8.6.0",
+    "X-Amzn-Trace-Id": "Root=1-66ea951a-4d740d724bd2a44f174d4daf",
+    "X-Consumer-Username": "jack",
+    "X-Credential-Identifier": "cred-jack-jwt-auth",
+    "X-Forwarded-Host": "127.0.0.1"
+  }
+}
+```
+
+30 秒后,令牌将过期。使用相同令牌发送请求以验证:
+
+```shell
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
+```
+
+您应该收到类似于以下内容的 `HTTP/1.1 401 Unauthorized` 响应:
+
+```text
+{"message":"failed to verify jwt"}
+```
+
+### 在请求标头、查询字符串或 Cookie 中携带 JWT
+
+以下示例演示如何在指定的标头、查询字符串和 Cookie 中接受 JWT。
+
+创建一个消费者 `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+为消费者创建 `jwt-auth` 凭证:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
     "plugins": {
-        "jwt-auth": {
-            "key": "user-key",
-            "secret": "my-secret-key"
-        }
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
     }
-}'
+  }'
 ```
 
-:::note
+创建一个带有 `jwt-auth` 插件的路由,并指定请求可以在标头、查询或 cookie 中携带令牌:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/get",
+    "plugins": {
+      "jwt-auth": {
+        "header": "jwt-auth-header",
+        "query": "jwt-query",
+        "cookie": "jwt-cookie"
+      }
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+要为 `jack` 签发 JWT,您可以使用 [JWT.io 的调试器](https://jwt.io/#debugger-io) 
或其他实用程序。如果您使用的是 [JWT.io 的调试器](https://jwt.io/#debugger-io),请执行以下操作:
+
+* 在 __Algorithm__ 下拉菜单中选择 __HS256__。
+* 将 __Verify Signature__ 部分中的密钥更新为 `jack-hs256-secret`。
+* 使用消费者密钥 `jack-key` 更新有效 payload;并在 UNIX 时间戳中添加 `exp` 或 `nbf`。
+
+  您的有效 payload 应类似于以下内容:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+将生成的 JWT 复制到 __Encoded__ 部分并保存到变量中:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
+
+#### 使用标头中的 JWT 进行验证
 
-`jwt-auth` 默认使用 `HS256` 算法,如果使用 `RS256` 算法,需要指定算法,并配置公钥,示例如下:
+发送标头中包含 JWT 的请求:
 
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/consumers \
--H "X-API-KEY: $admin_key" -X PUT -d '
+curl -i "http://127.0.0.1:9080/get"; -H "jwt-auth-header: ${jwt_token}"
+```
+
+您应该收到类似于以下内容的 `HTTP/1.1 200 OK` 响应:
+
+```text
 {
-    "username": "kerouac",
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Host": "127.0.0.1",
+    "Jwt-Auth-Header": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ",
+    ...
+  },
+  ...
+}
+```
+
+#### 在查询字符串中使用 JWT 进行验证
+
+在查询字符串中使用 JWT 发送请求:
+
+```shell
+curl -i "http://127.0.0.1:9080/get?jwt-query=${jwt_token}";
+```
+
+您应该收到类似于以下内容的 `HTTP/1.1 200 OK` 响应:
+
+```text
+{
+  "args": {
+    "jwt-query": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ"
+  },
+  "headers": {
+    "Accept": "*/*",
+    ...
+  },
+  "origin": "127.0.0.1, 183.17.233.107",
+  "url": 
"http://127.0.0.1/get?jwt-query=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ";
+}
+```
+
+#### 使用 Cookie 中的 JWT 进行验证
+
+使用 cookie 中的 JWT 发送请求:
+
+```shell
+curl -i "http://127.0.0.1:9080/get"; --cookie jwt-cookie=${jwt_token}
+```
+
+您应该收到类似于以下内容的 `HTTP/1.1 200 OK` 响应:
+
+```text
+{
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Cookie": 
"jwt-cookie=eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTY5NTEyOTA0NH0.EiktFX7di_tBbspbjmqDKoWAD9JG39Wo_CAQ1LZ9voQ",
+    ...
+  },
+  ...
+}
+```
+
+### 管理环境变量中的机密
+
+以下示例演示了如何将 `jwt-auth` 消费者密钥保存到环境变量并在配置中引用它。
+
+APISIX 支持引用通过 [NGINX `env` 
指令](https://nginx.org/en/docs/ngx_core_module.html#env) 配置的系统和用户环境变量。
+
+将密钥保存到环境变量中:
+
+```shell
+JACK_JWT_AUTH_KEY=jack-key
+```
+
+创建一个消费者 `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+为消费者创建 `jwt-auth` 凭证并在密钥中引用环境变量:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
     "plugins": {
-        "jwt-auth": {
-            "key": "user-key",
-            "public_key": "-----BEGIN PUBLIC KEY-----\n……\n-----END PUBLIC 
KEY-----",
-            "algorithm": "RS256"
-        }
+      "jwt-auth": {
+        "key": "$env://JACK_JWT_AUTH_KEY",
+        "secret": "jack-hs256-secret"
+      }
     }
-}'
+  }'
 ```
 
-:::
+创建路由并启用 `jwt-auth`:
 
-创建 Consumer 对象后,你可以创建 Route 进行验证:
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/get",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
+```
+
+要为 `jack` 签发 JWT,您可以使用 [JWT.io 的调试器](https://jwt.io/#debugger-io) 
或其他实用程序。如果您使用 [JWT.io 的调试器](https://jwt.io/#debugger-io),请执行以下操作:
+
+* 在 __Algorithm__ 下拉列表中选择 __HS256__。
+* 将 __Verify Signature__ 部分中的密钥更新为 `jack-hs256-secret` 。
+* 使用消费者密钥 `jack-key` 更新有效 payload;并在 UNIX 时间戳中添加 `exp` 或 `nbf`。
+
+  您的有效 payload 应类似于以下内容:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+将生成的 JWT 复制到 __Encoded__ 部分并保存到变量中:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
+
+发送标头中包含 JWT 的请求:
 
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/routes/1 \
--H "X-API-KEY: $admin_key" -X PUT -d '
+curl -i "http://127.0.0.1:9080/get"; -H "Authorization: ${jwt_token}"
+```
+
+您应该收到类似于以下内容的 `HTTP/1.1 200 OK` 响应:
+
+```text
 {
-    "methods": ["GET"],
-    "uri": "/index.html",
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE2OTUxMzMxNTUsImtleSI6Imp3dC1rZXkifQ.jiKuaAJqHNSSQCjXRomwnQXmdkC5Wp5VDPRsJlh1WAQ",
+    ...
+  },
+  ...
+}
+```
+
+### 在秘密管理器中管理秘密
+
+以下示例演示了如何管理 [HashiCorp Vault](https://www.vaultproject.io) 中的 `jwt-auth` 
消费者密钥并在插件配置中引用它。
+
+在 Docker 中启动 Vault 开发服务器:
+
+```shell
+docker run -d \
+  --name vault \
+  -p 8200:8200 \
+  --cap-add IPC_LOCK \
+  -e VAULT_DEV_ROOT_TOKEN_ID=root \
+  -e VAULT_DEV_LISTEN_ADDRESS=0.0.0.0:8200 \
+  vault:1.9.0 \
+  vault server -dev
+```
+
+APISIX 目前支持 [Vault KV 引擎版本 
1](https://developer.hashicorp.com/vault/docs/secrets/kv#kv-version-1)。在 Vault 
中启用它:
+
+```shell
+docker exec -i vault sh -c "VAULT_TOKEN='root' 
VAULT_ADDR='http://0.0.0.0:8200' vault secrets enable -path=kv -version=1 kv"
+```
+
+您应该看到类似于以下内容的响应:
+
+```text
+Success! Enabled the kv secrets engine at: kv/
+```
+
+创建一个 secret 并配置 Vault 地址和其他连接信息:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/secrets/vault/jwt"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "uri": "https://127.0.0.1:8200",
+    "prefix": "kv/apisix",
+    "token": "root"
+  }'
+```
+
+创建一个消费者 `jack`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
+```
+
+为消费者创建 `jwt-auth` 凭证并引用密钥中的秘密:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
     "plugins": {
-        "jwt-auth": {}
+      "jwt-auth": {
+        "key": "$secret://vault/jwt/jack/jwt-key",
+        "secret": "vault-hs256-secret"
+      }
+    }
+  }'
+```
+
+创建路由并启用 `jwt-auth`:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/get",
+    "plugins": {
+      "jwt-auth": {}
     },
     "upstream": {
-        "type": "roundrobin",
-        "nodes": {
-            "127.0.0.1:1980": 1
-        }
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
     }
-}'
+  }'
 ```
 
-## 测试插件
+在 Vault 中将 `jwt-auth` 键值设置为 `jwt-vault-key`:
+
+```shell
+docker exec -i vault sh -c "VAULT_TOKEN='root' 
VAULT_ADDR='http://0.0.0.0:8200' vault kv put kv/apisix/jack 
jwt-key=jwt-vault-key"
+```
 
-首先你需要使用诸如 [JWT.io's debugger](https://jwt.io/#debugger-io) 等工具或编程语言来生成一个 JWT 
token。
+您应该看到类似于以下内容的响应:
 
-:::note
+```text
+Success! Data written to: kv/apisix/jack
+```
 
-生成 JWT token 时,payload 中 `key` 字段是必要的,值为所要用到的凭证的 key; 且 `exp` 或 `nbf` 
至少填写其中一个,值为 UNIX 时间戳。
+要签发 JWT,您可以使用 [JWT.io 的调试器](https://jwt.io/#debugger-io) 或其他实用程序。如果您使用 [JWT.io 
的调试器](https://jwt.io/#debugger-io),请执行以下操作:
 
-示例:payload=`{"key": "user-key", "exp": 1727274983}`
+* 在 __Algorithm__ 下拉列表中选择 __HS256__。
+* 将 __Verify Signature__ 部分中的密钥更新为 `vault-hs256-secret` 。
+* 使用消费者密钥 `jwt-vault-key` 更新有效 payload;并在 UNIX 时间戳中添加 `exp` 或 `nbf`。
 
-:::
+  您的有效 payload 应类似于以下内容:
+
+  ```json
+  {
+    "key": "jwt-vault-key",
+    "nbf": 1729132271
+  }
+  ```
+
+将生成的 JWT 复制到 __Encoded__ 部分并保存到变量中:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqd3QtdmF1bHQta2V5IiwibmJmIjoxNzI5MTMyMjcxfQ.faiN93LNP1lGSXqAb4empNJKMRWop8-KgnU58VQn1EE
+```
+
+使用令牌作为标头发送请求:
+
+```shell
+curl -i "http://127.0.0.1:9080/get"; -H "Authorization: ${jwt_token}"
+```
 
-现在你可以使用获取到的 token 进行请求尝试
+您应该收到类似于以下内容的 `HTTP/1.1 200 OK` 响应:
 
-* token 放到请求头中:
+```text
+{
+  "args": {},
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqd3QtdmF1bHQta2V5IiwiZXhwIjoxNjk1MTM4NjM1fQ.Au2liSZ8eQXUJR3SJESwNlIfqZdNyRyxIJK03L4dk_g",
+    ...
+  },
+  ...
+}
+```
+
+### 使用 RS256 算法签署 JWT
+
+以下示例演示了在实施 JWT 进行消费者身份验证时如何使用非对称算法(例如 RS256)来签名和验证 JWT。您将使用 
[openssl](https://openssl-library.org/source/) 生成 RSA 密钥对,并使用 
[JWT.io](https://jwt.io/#debugger-io) 生成 JWT,以更好地了解 JWT 的组成。
+
+生成 2048 位的 RSA 私钥并提取对应的 PEM 格式的公钥:
 
 ```shell
-curl http://127.0.0.1:9080/index.html \-H 'Authorization: 
eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2NDA1MDgxMX0.Us8zh_4VjJXF-TmR5f8cif8mBU7SuefPlpxhH0jbPVI'
 -i
+openssl genrsa -out jwt-rsa256-private.pem 2048
+openssl rsa -in jwt-rsa256-private.pem -pubout -out jwt-rsa256-public.pem
 ```
 
+您应该会看到在当前工作目录中生成了 `jwt-rsa256-private.pem` 和 `jwt-rsa256-public.pem` 。
+
+访问 [JWT.io 的调试器](https://jwt.io/#debugger-io) 并执行以下操作:
+
+* 在 __Algorithm__ 下拉列表中选择 __RS256__。
+* 将 key 复制并粘贴到 __Verify Signature__ 部分。
+* 使用与您想要使用的消费者密钥匹配的 `key` 更新有效 payload;以及 UNIX 时间戳中的 `exp` 或 `nbf`。
+
+配置应类似于以下内容:
+
+<br />
+<div style={{textAlign: 'center'}}>
+<img
+  src="https://static.apiseven.com/uploads/2024/12/12/SRe7AXMw_jwt_token.png";
+  alt="complete configuration of JWT generation on jwt.io"
+  width="70%"
+/>
+</div>
+<br />
+
+复制左侧的 JWT 并保存到环境变量中:
+
 ```shell
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 13175
-...
-Accept-Ranges: bytes
-<!DOCTYPE html>
-<html lang="cn">
-...
+jwt_token=eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsImV4cCI6MTczNDIzMDQwMH0.XjqM0oszmCggwZs-8PUIlJv8wPJON1la2ET5v70E6TCE32Yq5ibrl-1azaK7IreAer3HtnVHeEfII2rR02v8xfR1TPIjU_oHov4qC-A4tLTbgqGVXI7fCy2WFm3PFh6MEKuRe6M3dCQtCAdkRRQrBr1gWFQZhV3TNeMmmtyIfuJpB7cp4DW5pYFsCcoE1Nw6Tz7dt8k0tPBTPI2Mv9AYfMJ30LHDscOaPNtz8YIk_TOkV9b9mhQudUJ7J_suCZMRxD3iL655jTp2gKsstGKdZa0_W9Reu4-HY3LSc5DS1XtfjuftpuUqgg9FvPU0mK_b0wT_Rq3lbYhcHb9GZ72qiQ
 ```
 
-* 缺少 token
+创建一个消费者 `jack`:
 
 ```shell
-curl http://127.0.0.1:9080/index.html -i
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack"
+  }'
 ```
 
+为消费者创建 `jwt-auth` 凭证并配置 RSA 密钥:
+
 ```shell
-HTTP/1.1 401 Unauthorized
-...
-{"message":"Missing JWT token in request"}
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "algorithm": "RS256",
+        "public_key": "-----BEGIN PUBLIC 
KEY-----\nMIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAnE0h4k/GWfEbYO/yE2MPjHtNKDLNz4mv1KNIPLxY2ccjPYOtjuug+iZ4MujLV59YfrHriTs0H8jweQfff3pRSMjyEK+4qWTY3TeKBXIEa3pVDeoedSJrgjLBVio6xH7et8ir+QScScfLaJHGB4/l3DDGyEhO782a9teY8brn5hsWX5uLmDJvxtTGAHYi847XOcx2UneW4tZ8wQ6JGBSiSg5qAHan4dFZ7CpixCNNqEcSK6EQ7lKOLeFGG8ys/dHBIEasU4oMlCuJH77+XQQ/shchy+vm9oZfP+grLZkV+nKAd8MQZsid7ZJ/fiB/BmnhGrjtIfh98jwxSx4DgdLhdwIDAQAB\n-----END
 PUBLIC KEY-----",
+        "private_key": "-----BEGIN PRIVATE 
KEY-----\nMIIEvwIBADANBgkqhkiG9w0BAQEFAASCBKkwggSlAgEAAoIBAQCcTSHiT8ZZ8Rtg7/ITYw+Me00oMs3Pia/Uo0g8vFjZxyM9g62O66D6Jngy6MtXn1h+seuJOzQfyPB5B99/elFIyPIQr7ipZNjdN4oFcgRrelUN6h51ImuCMsFWKjrEft63yKv5BJxJx8tokcYHj+XcMMbISE7vzZr215jxuufmGxZfm4uYMm/G1MYAdiLzjtc5zHZSd5bi1nzBDokYFKJKDmoAdqfh0VnsKmLEI02oRxIroRDuUo4t4UYbzKz90cEgRqxTigyUK4kfvv5dBD+yFyHL6+b2hl8/6CstmRX6coB3wxBmyJ3tkn9+IH8GaeEauO0h+H3yPDFLHgOB0uF3AgMBAAECggEARpY68Daw0Funzq5uN70r/3iLztSqx8hZpQE
 [...]
+      }
+    }
+  }'
 ```
 
-* token 放到请求参数中:
+:::tip
+
+您应该在开始行之后和结束行之前添加换行符,例如`-----BEGIN PRIVATE KEY-----\n......\n-----END PRIVATE 
KEY -----`。
+
+关键内容可以直接拼接。
+
+:::
+
+使用 `jwt-auth` 插件创建路由:
 
 ```shell
-curl 
http://127.0.0.1:9080/index.html?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2NDA1MDgxMX0.Us8zh_4VjJXF-TmR5f8cif8mBU7SuefPlpxhH0jbPVI
 -i
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-route",
+    "uri": "/headers",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
 ```
 
+使用 `Authorization` 标头中的 JWT 向路由发送请求:
+
 ```shell
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 13175
-...
-Accept-Ranges: bytes
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
+```
 
-<!DOCTYPE html>
-<html lang="cn">
-...
+您应该收到类似于以下内容的 `HTTP/1.1 200 OK` 响应:
+
+```json
+{
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsImV4cCI6MTczNDIzMDQwMH0.XjqM0oszmCggwZs-8PUIlJv8wPJON1la2ET5v70E6TCE32Yq5ibrl-1azaK7IreAer3HtnVHeEfII2rR02v8xfR1TPIjU_oHov4qC-A4tLTbgqGVXI7fCy2WFm3PFh6MEKuRe6M3dCQtCAdkRRQrBr1gWFQZhV3TNeMmmtyIfuJpB7cp4DW5pYFsCcoE1Nw6Tz7dt8k0tPBTPI2Mv9AYfMJ30LHDscOaPNtz8YIk_TOkV9b9mhQudUJ7J_suCZMRxD3iL655jTp2gKsstGKdZa0_W9Reu4-HY3LSc5DS1XtfjuftpuUqgg9FvPU0mK_b0wT_Rq3lbYhcHb9GZ72qiQ",
+    ...
+  }
+}
 ```
 
-* token 放到 cookie 中:
+### 将消费者自定义 ID 添加到标头
+
+以下示例演示了如何将消费者自定义 ID 附加到 `Consumer-Custom-Id` 标头中经过身份验证的请求,该标头可用于根据需要实现其他逻辑。
+
+创建一个带有自定义 ID 标签的消费者 `jack`:
 
 ```shell
-curl http://127.0.0.1:9080/index.html --cookie 
jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJ1c2VyLWtleSIsImV4cCI6MTU2NDA1MDgxMX0.Us8zh_4VjJXF-TmR5f8cif8mBU7SuefPlpxhH0jbPVI
 -i
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack",
+    "labels": {
+      "custom_id": "495aec6a"
+    }
+  }'
 ```
 
+为消费者创建 `jwt-auth` 凭证:
+
 ```shell
-HTTP/1.1 200 OK
-Content-Type: text/html
-Content-Length: 13175
-...
-Accept-Ranges: bytes
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
+    }
+  }'
+```
+
+使用 `jwt-auth` 创建路由:
 
-<!DOCTYPE html>
-<html lang="cn">
-...
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-auth-route",
+    "uri": "/anything",
+    "plugins": {
+      "jwt-auth": {}
+    },
+    "upstream": {
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
+    }
+  }'
 ```
 
-## 删除插件
+要为 `jack` 签发 JWT,您可以使用 [JWT.io 的调试器](https://jwt.io/#debugger-io) 
或其他实用程序。如果您使用的是 [JWT.io 的调试器](https://jwt.io/#debugger-io),请执行以下操作:
+
+* 在 __Algorithm__ 下拉菜单中选择 __HS256__。
+* 将 __Verify Signature__ 部分中的密钥更新为 `jack-hs256-secret` 。
+* 使用消费者密钥 `jack-key` 更新有效 payload;并在 UNIX 时间戳中添加 `exp` 或 `nbf` 。
 
-当你需要禁用 `jwt-auth` 插件时,可以通过以下命令删除相应的 JSON 配置,APISIX 将会自动重新加载相关配置,无需重启服务:
+  您的有效 payload 应类似于以下内容:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+将生成的 JWT 复制到 __Encoded__ 部分并保存到变量中:
+
+```text
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.0VDKUzNkSaa_H5g_rGNbNtDcKJ9fBGgcGC56AsVsV-I
+```
+
+使用 `Authorization` 标头中的 JWT 向路由发送请求:
 
 ```shell
-curl http://127.0.0.1:9180/apisix/admin/routes/1 \
--H "X-API-KEY: $admin_key" -X PUT -d '
+curl -i "http://127.0.0.1:9080/headers"; -H "Authorization: ${jwt_token}"
+```
+
+您应该看到类似于以下内容的 `HTTP/1.1 200 OK` 响应,其中附加了 `X-Consumer-Custom-Id`:
+
+```json
 {
-    "methods": ["GET"],
-    "uri": "/index.html",
-    "id": 1,
-    "plugins": {},
+  "headers": {
+    "Accept": "*/*",
+    "Authorization": 
"eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJleHAiOjE3MjY2NDk2NDAsImtleSI6ImphY2sta2V5In0.kdhumNWrZFxjUvYzWLt4lFr546PNsr9TXuf0Az5opoM",
+    "Host": "127.0.0.1",
+    "User-Agent": "curl/8.6.0",
+    "X-Amzn-Trace-Id": "Root=1-66ea951a-4d740d724bd2a44f174d4daf",
+    "X-Consumer-Username": "jack",
+    "X-Credential-Identifier": "cred-jack-jwt-auth",
+    "X-Consumer-Custom-Id": "495aec6a",
+    "X-Forwarded-Host": "127.0.0.1"
+  }
+}
+```
+
+### 匿名消费者的速率限制
+
+以下示例演示了如何为普通消费者和匿名消费者配置不同的速率限制策略,其中匿名消费者不需要进行身份验证,并且配额较少。
+
+创建一个普通消费者 `jack`,并配置 `limit-count` 插件,以允许 30 秒内的配额为 3:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "jack",
+    "plugins": {
+      "limit-count": {
+        "count": 3,
+        "time_window": 30,
+        "rejected_code": 429
+      }
+    }
+  }'
+```
+
+为消费者 `jack` 创建 `jwt-auth` 凭证:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers/jack/credentials"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "cred-jack-jwt-auth",
+    "plugins": {
+      "jwt-auth": {
+        "key": "jack-key",
+        "secret": "jack-hs256-secret"
+      }
+    }
+  }'
+```
+
+创建匿名用户 `anonymous`,并配置 `limit-count` 插件,以允许 30 秒内配额为 1:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/consumers"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "username": "anonymous",
+    "plugins": {
+      "limit-count": {
+        "count": 1,
+        "time_window": 30,
+        "rejected_code": 429
+      }
+    }
+  }'
+```
+
+创建一个路由并配置 `jwt-auth` 插件以接受匿名消费者 `anonymous` 绕过身份验证:
+
+```shell
+curl "http://127.0.0.1:9180/apisix/admin/routes"; -X PUT \
+  -H "X-API-KEY: ${admin_key}" \
+  -d '{
+    "id": "jwt-auth-route",
+    "uri": "/anything",
+    "plugins": {
+      "jwt-auth": {
+        "anonymous_consumer": "anonymous"
+      }
+    },
     "upstream": {
-        "type": "roundrobin",
-        "nodes": {
-            "127.0.0.1:1980": 1
-        }
+      "type": "roundrobin",
+      "nodes": {
+        "httpbin.org:80": 1
+      }
     }
-}'
+  }'
+```
+
+要为 `jack` 签发 JWT,您可以使用 [JWT.io 的调试器](https://jwt.io/#debugger-io) 
或其他实用程序。如果您使用的是 [JWT.io 的调试器](https://jwt.io/#debugger-io),请执行以下操作:
+
+* 在 __Algorithm__ 下拉菜单中选择 __HS256__。
+* 将 __Verify Signature__ 部分中的密钥更新为 `jack-hs256-secret`。
+* 使用角色 `user` 、权限 `read` 和消费者密钥 `jack-key` 以及 UNIX 时间戳中的 `exp` 或 `nbf` 更新有效 
payload。
+
+  您的有效 payload 应类似于以下内容:
+
+  ```json
+  {
+    "key": "jack-key",
+    "nbf": 1729132271
+  }
+  ```
+
+将生成的 JWT 复制到 __Encoded__ 部分并保存到变量中:
+
+```shell
+jwt_token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJrZXkiOiJqYWNrLWtleSIsIm5iZiI6MTcyOTEzMjI3MX0.hjtSsEILpko14zb8-ibyxrB2tA5biYY9JrFm3do69vs
+```
+
+为了验证速率限制,请使用 jack 的 JWT 连续发送五个请求:
+
+```shell
+resp=$(seq 5 | xargs -I{} curl "http://127.0.0.1:9080/anything"; -H 
"Authorization: ${jwt_token}" -o /dev/null -s -w "%{http_code}\n") && \
+  count_200=$(echo "$resp" | grep "200" | wc -l) && \
+  count_429=$(echo "$resp" | grep "429" | wc -l) && \
+  echo "200": $count_200, "429": $count_429
+```
+
+您应该看到以下响应,显示在 5 个请求中,3 个请求成功(状态代码 200),而其他请求被拒绝(状态代码 429)。
+
+```text
+200:    3, 429:    2
+```
+
+发送五个匿名请求:
+
+```shell
+resp=$(seq 5 | xargs -I{} curl "http://127.0.0.1:9080/anything"; -o /dev/null 
-s -w "%{http_code}\n") && \
+  count_200=$(echo "$resp" | grep "200" | wc -l) && \
+  count_429=$(echo "$resp" | grep "429" | wc -l) && \
+  echo "200": $count_200, "429": $count_429
+```
+
+您应该看到以下响应,表明只有一个请求成功:
+
+```text
+200:    1, 429:    4
 ```

Reply via email to