【问题标题】:unable to verify webhook无法验证 webhook
【发布时间】:2018-09-28 21:57:44
【问题描述】:

我有一个 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') 与 webhook 中的密钥匹配。然而,这段代码计算的 sha 并不等于 GitHub 发送的 sha。此代码逐字取自https://cloud.google.com/community/tutorials/github-auto-assign-reviewers-cloud-functions。 GitHub 使用的哈希方法有变化吗?

【问题讨论】:

    标签: github google-cloud-build


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 2020-05-25
      • 1970-01-01
      • 1970-01-01
      • 2021-06-30
      • 2020-01-30
      • 1970-01-01
      • 1970-01-01
      • 2017-11-24
      • 1970-01-01
      相关资源
      最近更新 更多