The Signature Header
When Blink sends a webhook to your server, it includes the following headers:Blink-Signature: The cryptographic signature of the payload (e.g.,v1=a1b2c3d4...)Blink-Timestamp: The unix timestamp (in seconds) when the event was dispatched.Blink-Event: The name of the event (e.g.,order.paid).
How to Verify the Signature
Blink uses HMAC with SHA-256 to sign webhook payloads. To verify the signature, you need the Signing Secret for your webhook endpoint (which you can find in the Blink dashboard or via the API). Follow these steps to verify the signature:- Extract the timestamp and signature from the headers.
- Prepare the signed payload string by concatenating the timestamp, a dot (
.), and the raw JSON request body:${timestamp}.${rawBody}. - Compute the expected HMAC signature using SHA-256, your signing secret, and the signed payload string.
- Compare the signatures. If your computed signature matches the one in the
Blink-Signatureheader (stripping thev1=prefix), the webhook is valid!
Example: Node.js (Express)
Here is a complete example of how to verify a webhook signature in a Node.js Express application:Example: Next.js (App Router)
If you are using Next.js App Router, you can verify webhooks like this:Replay Attacks
As a best practice to prevent replay attacks, you should check that theBlink-Timestamp is within a reasonable tolerance (e.g., 5 minutes) of your server’s current time.