无法验证webhook

时间:2018-09-28 21:57:44

标签: github google-cloud-build

我有一个Webhook,可将Push事件的有效负载传递给Google Cloud Function。我的nodejs代码如下所示:

function validateRequest (req) {
  return Promise.resolve()
    .then(() => {
      const digest = crypto
        .createHmac('sha1', '12345')
        .update(JSON.stringify(req.body))
        .digest('hex');

      if (req.headers['x-hub-signature'] !== `sha1=${digest}`) {
        const error = new Error('Unauthorized');
        error.statusCode = 403;
        throw error;
      } else {
        console.log('Request validated.');
      }
    });
}

我已经两次和三次检查了秘密令牌( 代码中的12345')与网络挂钩中的机密匹配。但是,此代码计算出的sha不等于GitHub发送的sha。该代码是从https://cloud.google.com/community/tutorials/github-auto-assign-reviewers-cloud-functions逐字获取的。 GitHub使用的哈希方法是否已更改?

1 个答案:

答案 0 :(得分:0)

问题是webhook需要发送内容类型application/json而不是application/x-www-form-urlencoded

相关问题