问题
I have setup an endpoint for sendgrid to send event notifications. However, the server is setup with basic authentication and the events don't come through because they are not authenticated. How can I authenticate these event webhooks by SendGrid or whitelist SendGrid?
回答1:
You can use basic authentication when setting up the HTTP POST URL by setting it to a value like https://user:password@this.is.my.test/listening/endpoint
Where "user" is the basic authentication user name and "password" is the basic authentication password for the user.
Or
Turn off basic authentication to your listening endpoint and use a simple check to prevent random people/bots from executing all the code at your listening endpoint, when setting the HTTP POST URL include a querystring value:
Then the first thing your listening code should do is extract the querystring and check that "key" = "some_random_value" if is doesn't then just return bad/invalid request. If the querystring contains "key" = "some_random_value" then your code should parse the body. It's not bulletproof but should stop most random requests.
Or
Combine the techniques and do them both!
来源:https://stackoverflow.com/questions/55727577/sendgrid-event-notification-authentication