Verifying a webhook subscription
Last updated
Last updated
If you have created your webhook subscription using a signingKey you can validate the authenticity of the webhook by validating the request signature sent in the request header.
From the incoming webhook, parse the following request headers:
messagebird-signature
messagebird-request-timestamp
In addition, parse the request URL
and the request Body
.
To calculate the request signature:
Base64 decode the messagebird-signature
header;
Create a SHA256 hash checksum of the request body
as a binary result;
Join the request timestamp (messagebird-request-timestamp
header) with the request URL and request body
checksum computed in step 2, separated by a new line (\n
);
Calculate HMACSHA256 using the signing key as the secret and the joined payload from step 3 to calculate the signature;
Compare the output of Step 4 with the signature from Step 1. The code snippets below illustrate the intended process. We recommend tailoring these examples to fit your preferred programming language, codebase, or framework.
Examples
The following code snippets are provided to illustrate the intended process. We recommend adapting them to your preferred programming language, codebase, or framework to ensure compatibility.