【发布时间】:2018-07-06 14:41:25
【问题描述】:
我正在尝试匹配此处记录的 X-Square-Signature 标头:https://docs.connect.squareup.com/api/connect/v1/#validating-notifications
我目前正在使用 OpenSSL::HMAC 来生成摘要,但事情似乎不正确。
string_to_sign = "#{request.url}#{param_hash.to_json}"
header_signature = request.headers["X-Square-Signature"]
# split into multiple lines for clarity
digest = OpenSSL::Digest.new('sha1')
hmac = OpenSSL::HMAC.digest(digest, ENV["SIGNATURE_KEY"], string_to_sign)
# stripping the newline off the end
hmac_64 = Base64.encode64(hmac).strip
出于某种原因,尽管遵循了上面 API 文档中提供的说明,但我得到的摘要却截然不同。我对摘要的计算似乎也与他们的 python 示例一致 (https://github.com/square/connect-api-examples/blob/master/connect-examples/v1/webhooks.py#L75-L87)。
我已经验证 string_to_sign 值与我应该遵循的模式相同,当我手动制作帖子时它可以工作,但我是通过同样的方法生成我的签名,所以它当然会排列。
我可能忽略的摘要/签名计算过程有什么细节吗?
【问题讨论】:
标签: ruby-on-rails ruby webhooks hmac square-connect