HMAC for kong API

时间:2017-03-27 14:01:01

标签: api curl hmac kong

请...

我需要一些帮助来配置和使用HMAC for KONG API。

我正在关注使用演示凭证bob / secret456

https://getkong.org/plugins/hmac-authentication/发布的手册

问题在于使用HMAC身份验证。我仍然得到403错误 - 禁止。

这是我的命令行输出:

root@test.com# curl -v http://X:8000/public4/ -H 'Authorization: hmac username="bob", algorithm="hmac-sha1", headers="Date content-md5", signature="Base64(HMAC-SHA1(secret456))"'
> GET /public4/ HTTP/1.1
> User-Agent: curl/7.35.0
> Host: XXX:8000
> Accept: */*
> Authorization: hmac username="bob", algorithm="hmac-sha1", headers="X-Date content-md5", signature="Base64(HMAC-SHA1(secret456))" <<- IS THIS CORRECT?
>
< HTTP/1.1 403 Forbidden
< Date: Mon, 27 Mar 2017 13:15:07 GMT
< Content-Type: application/json; charset=utf-8
< Transfer-Encoding: chunked
< Connection: keep-alive
* Server kong/0.9.7 is not blacklisted
< Server: kong/0.9.7
<
{"message":"HMAC signature cannot be verified, a valid date or x-date header is required for HMAC Authentication"}
* Connection #0 to host XXX left intact

香港消费者:

{
  "total": 1,
  "data": [
    {
      "consumer_id": "e98e1ca2-2f13-4430-a658-cabdd4e6cd26",
      "created_at": 1490616124000,
      "username": "bob",
      "id": "037db653-8b38-4a7e-b139-1040856b7cfb",
      "secret": "secret456"
    }
  ]
}

任何提示或指南都将不胜感激。 Github问题已经结束,评论没有帮助。我仍然得到同样的错误。

非常感谢你。

1 个答案:

答案 0 :(得分:2)

您包括字符串文字&#34; Base64(HMAC-SHA1(secret456))&#34;在您的授权标题中。您应该计算密码的HMAC,对其进行base64编码,并包含该值。