Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/meteor/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Meteor 流星:验证ShopifyWebhook_Meteor_Shopify_Webhooks_Hmac - Fatal编程技术网

Meteor 流星:验证ShopifyWebhook

Meteor 流星:验证ShopifyWebhook,meteor,shopify,webhooks,hmac,Meteor,Shopify,Webhooks,Hmac,我正在尝试验证来自shopify的webhook请求。为此,我提到: . 我已经创建了一个shopify应用程序,因为我正在自动注册(创建)关联商店的web挂钩,所以使用app secret来验证这一点 代码是: import { Picker } from 'meteor/meteorhacks:picker'; var bodyParser = require( 'body-parser' ), crypto = require('crypto'); Picker.mid

我正在尝试验证来自shopify的webhook请求。为此,我提到: . 我已经创建了一个shopify应用程序,因为我正在自动注册(创建)关联商店的web挂钩,所以使用app secret来验证这一点

代码是:

import { Picker } from 'meteor/meteorhacks:picker';

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

Picker.middleware( bodyParser.json() );
Picker.middleware( bodyParser.urlencoded( { extended: true } ) );

var post = Picker.filter(function(req, res) {
  // Bypass, if the url doesn't start with webhook 
  if (req.url.search('webhook') < 0) {
   return true;
  }

  let isValid = isValidWebhook(req);
  console.log( (isValid ? 'Verified' : 'Unverified') + ' webhook');

  return (isValid && req.method == "POST");
});

isValidWebhook = function (req) {
  const data       = JSON.stringify(req.body);  
  const header     = req.headers;
  const hmac       = header['x-shopify-hmac-sha256'];
  const appSecret  = Meteor.settings.shopify.secret;

  const calHmac  = crypto.createHmac("sha256", appSecret).update(data).digest("base64");

  return (hmac == calHmac);
}
从“meteor/meteorhacks:Picker”导入{Picker};
var bodyParser=require('body parser'),
加密=需要(“加密”);
中间件(bodyParser.json());
中间件(bodyParser.urlencoded({extended:true}));
var post=选择器过滤器(功能(请求、恢复){
//绕过,如果url不是以webhook开头
if(请求url.search('webhook')<0){
返回true;
}
设isValid=isValidWebhook(req);
log((isValid?'Verified':'Unverified')+'webhook');
返回(isValid&&req.method==“POST”);
});
isValidWebhook=函数(req){
const data=JSON.stringify(req.body);
const header=req.headers;
const hmac=标题['x-shopify-hmac-sha256'];
const appSecret=Meteor.settings.shopify.secret;
const calHmac=crypto.createHmac(“sha256”,appSecret).update(data).digest(“base64”);
返回值(hmac==calHmac);
}
服务器端路由正在被捕获。
到目前为止,我无法验证它,因此非常感谢您的帮助。

尝试使用
const data=req.body
而不是
const data=JSON.stringify(req.body)并让我们知道。@HymnZ已经尝试过了,所以一旦运行calHmac的代码,它就会抛出一个错误“TypeError:不是字符串或缓冲区”。在这种情况下,请尝试
const data=JSON.stringify(req.body)
const calHmac=crypto.createHmac(“sha256”,appSecret).update(data,'utf8').digest(“base64”)已尝试,但仍未验证。请确保使用正确的密码;有两个。看见