Skip to content

Add a verify_sendgrid_webhook_signature decorator to make Sendgrid Events webhook development easier#138

Merged
sklarsa merged 3 commits intosklarsa:masterfrom
blag:add-webhook-helper-decorator
May 14, 2025
Merged

Add a verify_sendgrid_webhook_signature decorator to make Sendgrid Events webhook development easier#138
sklarsa merged 3 commits intosklarsa:masterfrom
blag:add-webhook-helper-decorator

Conversation

@blag
Copy link
Copy Markdown
Contributor

@blag blag commented May 11, 2025

Add a decorator that verifies the webhook signature for Sendgrid Events.

See: https://www.twilio.com/docs/sendgrid/for-developers/tracking-events/getting-started-event-webhook-security-features#sample-verification-libraries for more information.

Added tests and documentation.

@blag blag force-pushed the add-webhook-helper-decorator branch 2 times, most recently from d711cd2 to c9998c0 Compare May 11, 2025 17:29
@sklarsa
Copy link
Copy Markdown
Owner

sklarsa commented May 12, 2025

This looks like a cool effort, thanks! Just please make sure that we support the Sendrid API versions that implement the webhook signature before spending more time on this. All supported sendgrid/django/python versions can be found in our test matrix

@blag blag force-pushed the add-webhook-helper-decorator branch 6 times, most recently from 5772fac to b0a25e2 Compare May 13, 2025 11:35
@blag
Copy link
Copy Markdown
Contributor Author

blag commented May 13, 2025

Sendgrid v5 doesn't have any support for webhooks. I'm not sure how to skip tests (and imports, etc.) when the sendgrid package version < 6.

But the tests with sendgrid v6 all pass when I run tox locally.

Any advice or ideas?

@sklarsa
Copy link
Copy Markdown
Owner

sklarsa commented May 13, 2025

Sendgrid v5 doesn't have any support for webhooks. I'm not sure how to skip tests (and imports, etc.) when the sendgrid package version < 6.

But the tests with sendgrid v6 all pass when I run tox locally.

Any advice or ideas?

I have some utils for that. You can see the usage here:

from sendgrid_backend.util import SENDGRID_5, SENDGRID_6, dict_to_personalization
if SENDGRID_6:
from sendgrid.helpers.mail import Bcc, Cc, To

@blag blag force-pushed the add-webhook-helper-decorator branch from b0a25e2 to c79eec1 Compare May 13, 2025 20:44
@blag blag force-pushed the add-webhook-helper-decorator branch from c79eec1 to 9958045 Compare May 13, 2025 21:11
@blag blag force-pushed the add-webhook-helper-decorator branch from 9958045 to 44d1f03 Compare May 13, 2025 21:17
@blag blag marked this pull request as ready for review May 14, 2025 05:10
@blag
Copy link
Copy Markdown
Contributor Author

blag commented May 14, 2025

Thanks for the pointers, got all the tests passing. This should be good to merge.

Copy link
Copy Markdown
Owner

@sklarsa sklarsa left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, thank you! I'll cut a release shortly

@sklarsa sklarsa merged commit 76cc12d into sklarsa:master May 14, 2025
6 checks passed
@blag blag deleted the add-webhook-helper-decorator branch May 14, 2025 21:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants