业务介绍
在上一节中,我们学习了如何将插件添加到Kong,在本节中,我们将学习如何将使用者添加到Kong。 使用者与服务相关联,可用于跟踪,访问管理等。
添加使用者
$ curl -i -X POST \
--url http://localhost:8001/consumers/ \
--data "username=Jason"
应答
HTTP/1.1 201 Created
Date: Mon, 20 Apr 2020 03:55:54 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/2.0.3
Content-Length: 117
X-Kong-Admin-Latency: 201
{
"custom_id":null,
"created_at":1587354954,
"id":"b61bfac7-34ca-4156-8327-6d41b967a88f",
"tags":null,
"username":"Jason"
}
给使用者提供一个票据
$ curl -i -X POST \
--url http://localhost:8001/consumers/Jason/key-auth/ \
--data 'key=ENTER_KEY_HERE'
应答
HTTP/1.1 201 Created
Date: Mon, 20 Apr 2020 03:56:16 GMT
Content-Type: application/json; charset=utf-8
Connection: keep-alive
Access-Control-Allow-Origin: *
Server: kong/2.0.3
Content-Length: 172
X-Kong-Admin-Latency: 185
{
"created_at":1587354976,
"consumer":{"id":"b61bfac7-34ca-4156-8327-6d41b967a88f"},
"id":"9b91cba1-fe0c-480a-9376-89277657bf25",
"tags":null,
"ttl":null,
"key":"ENTER_KEY_HERE"
}
测试使用者票据有效性
$ curl -i -X GET \
--url http://localhost:8000 \
--header "Host: example.com" \
--header "apikey: ENTER_KEY_HERE"
有正确的返回,表示consumer配置正确。