Verifying Webhooks
To prevent undesired requests to your webhooks, you can verify the webhook signature with a unique secret for your team. This secret can always be used to verify that the webhook sender is valid.
Why verify webhooks?
A webhook is an HTTP POST request from an API service to a URL you control. You might want to verify these requests to ensure they’re from pyannoteAI and not from a malicious actor.
How to verify webhooks
Each webhook request includes 2 HTTP headers that you can use to verify the request:
X-Signature
: The base64 encoded signature of the webhook request.X-Request-Timestamp
: The timestamp of the webhook request in seconds since the Unix epoch.
1. Creating the signed content
As the webhook receiver, you need to create the signed content by concatenating the timestamp
and the raw body
of the request with a colon (:
) and prefixing the result with v0:
.
In code, this looks like:
Make sure to use the raw body of the request (without headers or other metadata) before serializing to JSON or any other format.
2. Retrieving your webhook secret
You can find your webhook secret in the pyannoteAI dashboard.
- Sign in to your dashboard at https://dashboard.pyannote.ai
- Click on the “Webhooks” page in the sidebar.
- Click on the button with the eye icon to reveal your webhook secret.
- Copy the secret to your clipboard.
On the webhook page, you can also rotate your webhook secret. This is useful if you think your secret has been compromised.
3. Determining the expected signature
pyannoteAI uses the HMAC-SHA256 algorithm to sign webhook requests. To determine the expected signature, you need to:
- Create the signed content by concatenating the
timestamp
from the HTTP header and the rawbody
with a colon (:
), then prefix the result withv0:
. - Compute the HMAC-SHA256 hash of the result using your webhook secret as the key.
- Base64 encode the result.
In code, this looks like:
4. Verifying the signature
Then, simply compare the computed signature with the signature you received in the X-Signature
header.
Example FastAPI server
Here’s an example of how you can verify a webhook request in a FastAPI server: