保护webhook免受未经授权的请求?

2024-05-28 11:16:42 发布

您现在位置:Python中文网/ 问答频道 /正文

我想制作一个webhook,以便更改集合中文档的状态。这将触发其他事件。你知道吗

Router.route('/mandrill/invitation_sent', { where: 'server' })
  .post(function () {
    var response = EJSON.parse(this.request.body.mandrill_events);
    Players.update({
      "email": {
        "$in": _.map(_.where(response, {
          event: 'send'
        }), function (obj) {
          return obj.msg.email;
        })
      }
    }, {
      "feed": {
        "$push": {
          title: "Player invited",
          icon: "ios-player-invited"
        }
      }
    })
  });
});

然而。。。我不能直接手动发布到这个webhook吗?你知道吗

>>> import requests
>>> webhook_url = '<url>.com/mandrill/invitation_sent'
>>> payload = { 'mandrill_events': [{ 'event': 'send', 'msg': { 'email': 'foo@bar.com'}}]}
>>> requests.post(webhook_url, data=payload)
<Response [200]>

我如何知道请求来自可信来源?是否有一些规范的方法来确保webhook从可信的源接收数据?你知道吗


Tags: eventsendobjurlemailresponsefunctionmsg