我正在尝试使用 Node.js 验证来自 Patreon 的 webhook 签名。这是我的代码:
const crypto = require("crypto");
...
function validateJsonWebhook(request) {
const secret = SECRET_KEY_GIVEN_BY_PATREON;
const hash = crypto.createHmac("md5", secret)
.update(JSON.stringify(request.body))
.digest("hex");
if (request.header("x-patreon-signature") === hash) {
return true;
} else {
return false;
}
}
Patreon webhook 使用 MD5 - 请参阅https://docs.patreon.com/#webhooks。
我已经多次验证了密钥,所以我知道这不是问题。
"request.header("x-patreon-signature")" 和 "hash" 都返回正确的格式(即它们都是 32 位字母数字组合),但它们只是不匹配。
知道发生了什么吗?