Securing Your Webhook Handler
Ensure events processed by your application is from Magic Hour’s system.
Headers
Events includes two headers to help verify the authenticity of the payload.
magic-hour-event-signature
A signatured created with the webhook secret key and a signed_payload, using HMAC with SHA-256
magic-hour-event-timestamp
Time in seconds since the epoch. Use this value to check whether the request is within a reasonable window of the current time. Usually less than 5 minutes.
Using the header to verify the request ensures that the request is authentic. However, the header verification is not required to receive webhook events.
Compute the signature
To verify the request, generate the signature in your application and confirm that it matches the request.
Create signed payload
Create a signed_payload
by concatenating:
- the timestamp as a string
- the character .
- the payload JSON (stringified)
For example,
Compute the signature
Compute an HMAC with the SHA256 Hash function. Using the webhook secret as the key, and use the signed_payload as the message.
Compare against request header
Compare the computed signature value against the header value and ensure they are identical. And verify that the timestamp is within a reasonable window.
Integrate with handler
Was this page helpful?