AppCenter Webhook请求的“签名无效”消息

问题描述 投票:1回答:1

我正在尝试在GitHub API和AppCenter API之间编写代理服务,当我尝试重新路由标准GitHub API消息时,我收到“签名无效”响应。这是我试图发送的内容:

{
"ref": "refs/heads/xxxx",
"before": "xxxxxxxxxxxxx",
"after": "xxxxxxxxxxxxx",
"created": false,
"deleted": false,
"forced": false,
"base_ref": null,
"compare": "https://github.com/xxxxx",
"commits": [{
    "content": "xxxx"
}],
"head_commit": {
    "content": "xxxx"
},
"repository": {
    "content": "xxxx"
},
"pusher": {
    "content": "xxxx"
},
"organization": {
    "content": "xxxx"
},
"sender": {
    "content": "xxxx"
}

}

AppCenter的终点是:

https://api.appcenter.ms/v0.1/public/apps/xxxxxxxxxxx/hooks

请求的标题是:

{
    "content-type": "application/json",
    "User-Agent": "GitHub-Hookshot/xxxxxxxx",
    "X-GitHub-Delivery": "xxxxxxxxxxxxxx",
    "X-GitHub-Event": "push",
    "X-Hub-Signature": "sha1=xxxxxxxxxxx"
}

这是我得到的回应:

{
    "id": "xxxxxxxxxxxxxxxx",
    "message": "Signature is invalid"
}

我还没有从AppCenter收到合理的答案,希望有人已经有类似的经历并且可以回答。谢谢

github-api visual-studio-app-center
1个回答
1
投票

我认为这个问题是X-Hub-Signature的价值。从Validating payloads from Github,Github在有效负载数据和您放入存储库的webhook部分的秘密字符串之间使用HMAC SHA1:

enter image description here

签名格式(不带括号):

sha1={HMAC-SHA1(secret, payload)}

计算签名的几个示例:

  • 使用ruby(来自here): signature = 'sha1=' + OpenSSL::HMAC.hexdigest(OpenSSL::Digest.new('sha1'), ENV['SECRET_TOKEN'], payload_body)
  • 使用javascript(来自here): var signature = 'sha1=' + CryptoJS.HmacSHA1(payload, environment.secret).toString(CryptoJS.enc.Hex)
© www.soinside.com 2019 - 2024. All rights reserved.