validationFacebook X-Hub-Signature

在parsing云代码我试图validation从Facebook webhook收到的头部x-hub-signature

secret是Facebook应用程序的正确密钥。

 var hmac, expectedSignature, payload = JSON.stringify(req.body), secret = 'xyzxyzxyz'; hmac = crypto.createHmac('sha1', secret); hmac.update(payload, 'utf-8'); expectedSignature = 'sha1=' + hmac.digest('hex'); console.log(expectedSignature); console.log(req.headers['x-hub-signature']); 

但签名永远不会匹配。 哪里不对?

如果你正在使用中间件将对象parsing为对象,请检查Node.js – 使用Express获取原始请求体

如果您已经使用原始parsing模块,那么它应该可以工作,如果您不使用JSON.stringify req.body:

 payload = req.body,