Verifying a webhook
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 andrequest 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 to the signature from step 1; Examples The code examples below are pseudo code to help explain what needs to happen. We advise you to amend the example of your preferred language to what suits your codebase or framework.
Examples
The code examples below are pseudo code to help explain what needs to happen. We recommend you amend the example of your preferred language to what suits your codebase or framework.// Some code
Last updated