Mailgun Webhook 访问

Mailgun Webhook Access

我们目前正在实施 Mailgun 的 webhook,以将电子邮件回复转换为我们应用程序中评论线程中的回复。我们设置一个路由来匹配收件人,并将动作设置为store(notify="https://example.com/example-endpoint")。 Mailgun 将数据发布到给定的端点,然后我们在其中处理消息并将其添加到应用程序评论线程。

我的问题是这样的:

如何锁定端点,使 Mailgun 成为唯一可以 post 的实体?是否有我可以列入白名单的 IP 列表?是否有他们发送的特殊密钥,我可以根据私有 API 密钥进行验证?

我在文档中找到了自己的答案。我应该更仔细地阅读文档。

https://documentation.mailgun.com/user_manual.html#webhooks 下的 "Securing Webhooks" 部分说:

To ensure the authenticity of event requests, Mailgun signs them and posts the signature along with other webhook parameters.

我必须将有效负载中的 signature 值与 timestamptoken 的 SHA256 HMAC 哈希进行比较,使用 api 密钥作为 HMAC 密钥。

例如:

$_POST['signature'] === hash_hmac('sha256', $_POST['timestamp'] . $_POST['token'], 'example-api-key);