From 15ca930c84044234a5eac8429d1b3781224bd4f6 Mon Sep 17 00:00:00 2001 From: Shwetha Radhakrishna Date: Tue, 5 Oct 2021 21:49:25 -0500 Subject: [PATCH] docs: improve signed webhook event validation docs --- TROUBLESHOOTING.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/TROUBLESHOOTING.md b/TROUBLESHOOTING.md index 657b7469..7f8d249a 100644 --- a/TROUBLESHOOTING.md +++ b/TROUBLESHOOTING.md @@ -17,6 +17,7 @@ If you can't find a solution below, please open an [issue](https://github.com/se * [Rails Specifics](#rails-specifics) * [Ruby Versions](#ruby-versions) * [Viewing the Request Body](#viewing-the-request-body) +* [Verifying Event Webhooks](#signed-webhooks) ## Migrating from v2 to v3 @@ -137,3 +138,14 @@ You can do this before `response = sg.client.mail._('send').post(request_body: m ```ruby puts mail.to_json ``` + + +## Signed Webhook Verification + +Twilio SendGrid's Event Webhook will notify a URL via HTTP POST with information about events that occur as your mail is processed. [This](https://docs.sendgrid.com/for-developers/tracking-events/getting-started-event-webhook-security-features) article covers all you need to know to secure the Event Webhook, allowing you to verify that incoming requests originate from Twilio SendGrid. The sendgrid-ruby library can help you verify these Signed Event Webhooks. + +You can find the usage example [here](examples/helpers/eventwebhook/example.rb) and the tests [here](spec/sendgrid/helpers/eventwebhook/eventwebhook_spec.rb). +If you are still having trouble getting the validation to work, follow the following instructions: +- Be sure to use the *raw* payload for validation +- Be sure to include a trailing carriage return and newline in your payload +- In case of multi-event webhooks, make sure you include the trailing newline and carriage return after *each* event