add/adjust event parsing helpers - #1855
Open
xavdid wants to merge 4 commits into
Open
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why?
Historically, our webhook parsing logic has been closely tied to signature validation (because the expectation is that users verify webhooks' authenticity before use). But, as the webhook handling experience has grown in complexity over time, our helper methods haven't kept up.
In addition to the classic parse+verify & handle, we also support / encourage :
This gives us 4 use cases that each need a subset of helper methods:
verifyparseparseAndVerifysignTestPayloadTo support these workflows, we need all of these methods publicly available in every SDK:
constructEvent(payload, signature, ...)(parse + verify)parseEventNotification(payload, signature, ...)(parse + verify)constructEventWithoutVerification(payload)(parse, supports both direct webhooks and cloud provider envelopes)parseEventNotificationWithoutVerification(payload)(parse, supports both direct webhooks and cloud provider envelopes)verify(payload, signature, secret, ...)signTestPayload(payload, secret)The exact naming & arguments vary by language, but each SDK should provide roughly the same capabilities.
Important
For reviewers: the exact error messages are a little inconsistent between SDKs right now. Everything throws in the right place, but we're still iterating on some of the naming. We're trying out "thin event notification" as a descriptor on some of these surfaces. We're planning to have this all cleaned up by the GA launch of interop events; ignore exact messages for now.
What?
Note
these notes generic across all the SDKs; see
Changelogbelow for the SDK-specific list of changesStripeClient&Webhookclasses, where relevant.maybe_extract_from_cloud_provider_envelopefor handling wrapped events without the user having to think about itSee Also
Changelog
Event/EventNotificationclass instances without verifying authenticity. Use them when you've previously verified an event (e.g. you verified, put the event in a queue, and are now processing). Supports events from AWS EventBridge and Azure Event Grid natively.Webhook.construct_event_without_verification(payload)StripeClient.construct_event_without_verification(payload)StripeClient.parse_event_notification_without_verification(payload)WebhookSignature.generate_signature_header(payload, secret, timestamp=None), which computes a fullStripe-Signatureheader for the given payload. Useful for unit tests!