004-API网关KONG添加consumer

业务介绍

在上一节中,我们学习了如何将插件添加到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配置正确。

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容