Azure 事件 Webhook 验证失败

时间:2021-04-13 19:26:13

标签: express azure-eventgrid

我正在尝试使用 Azure 事件验证 webhook。根据他们的文档,请求具有以下正文:

[
  {
    "id": "2d1781af-3a4c-4d7c-bd0c-e34b19da4e66",
    "topic": "/subscriptions/xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
    "subject": "",
    "data": {
      "validationCode": "512d38b6-c7b8-40c8-89fe-f46f9e9622b6",
      "validationUrl": "https://rp-eastus2.eventgrid.azure.net:553/eventsubscriptions/estest/validate?id=512d38b6-c7b8-40c8-89fe-f46f9e9622b6&t=2018-04-26T20:30:54.4538837Z&apiVersion=2018-05-01-preview&token=1A1A1A1A"
    },
    "eventType": "Microsoft.EventGrid.SubscriptionValidationEvent",
    "eventTime": "2018-01-25T22:12:19.4556811Z",
    "metadataVersion": "1",
    "dataVersion": "1"
  }
]

应该返回:

{
  "validationResponse": "512d38b6-c7b8-40c8-89fe-f46f9e9622b6"
}

我已与邮递员确认我的应用程序正是这样做的。这是一个片段:

const validationEventType = 'Microsoft.EventGrid.SubscriptionValidationEvent';
for (var events in req.body) {
const body = req.body[events];
// Validate the event-hook when the eventhook is created
if (body.data && body.eventType === validationEventType) {
    const code = body.data.validationCode;
    const resBody = { validationResponse: code };
    return res.status(200).json(resBody);
}

当我尝试使用 Azure 进行验证时,我仍然收到以下错误消息:

https://.ngrok.io/v*./api//media-job 的 Webhook 验证握手失败。 Http POST 请求使用响应正文重新调整了 2XX 响应 {“验证响应”:“301549B7-E5A7-4D5B-9D35-8A4CAD6D9494”。 当在响应正文中没有验证代码的情况下接受验证请求时,在验证事件中包含的验证 url 上需要 Http GET(在 10 分钟内)。用于故障排除*

任何想法可能导致此问题?

1 个答案:

答案 0 :(得分:0)

我找到了一个修复程序,但是,我不完全确定错误是什么。我在我的请求中看到我有很多标头,例如 set-cookieX-... 移动路由器以不使用 cookie-parser、passport cors、helm 删除了很多 cookie 并使握手正常工作正如预期的那样。