gpt4 book ai didi

node.js - 如何验证 node.js/express 中的 Shopify webhook 签名?

转载 作者:搜寻专家 更新时间:2023-10-31 22:59:36 25 4
gpt4 key购买 nike

Shopify 提供 examples in Ruby and PHP来完成这个。在我的 Node/快速应用程序中,我尝试:

var data = querystring.stringify(req.body);
var calculatedSha256 = crypto.createHmac("SHA256", APP_SECRET).update(new Buffer(data, 'utf8')).digest('base64');

还有

var data = req.body;
var calculatedSha256 = crypto.createHmac("SHA256", APP_SECRET).update(new Buffer(data, 'utf8')).digest('base64');

但它们都没有提供与 Shopify 作为签名发送的字符串相同的字符串。

最佳答案

有点旧,但我想我会发布我的解决方案:

var express      = require('express')
, bodyParser = require('body-parser')
, crypto = require('crypto');

var app = express();

app.use(bodyParser.json({ verify: function(req, res, buf, encoding) {
req.headers['x-generated-signature'] = crypto.createHmac('sha256', 'SHARED_SECRET')
.update(buf)
.digest('base64');
} }));

app.post('/webhook', function(req, res) {
if (req.headers['x-generated-signature'] != req.headers['x-shopify-hmac-sha256']) {
return res.status(401).send('Invalid Signature');
}
});

关于node.js - 如何验证 node.js/express 中的 Shopify webhook 签名?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22118751/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com