Verifying Webhooks
Verify the events that Caption.Ed sends to your webhook endpoints.
Captioned-Timestamp: "1893456000"
Captioned-Signature: <SHA256_SIGNATURE>import crypto from 'crypto';
const signingSecret = process.env["CAPTIONED_WEBHOOK_SIGNING_SECRET"]
const verifySignature(request) {
// Get headers
const timestamp = request.headers['Captioned-Timestamp']
const requestSignature = request.headers['Captioned-Signature']
// Check the headers are present
if (!timestamp || !requestSignature) return false
// Optionally: Check the timestamp is in your allowable range (e.g. within 1 min)
// Get the raw request body
const payload = request.body
// Combine the timestamp with the payload to build the signature data
const signatureData = [timestamp, ".", payload].join("")
// Create a SHA256 HMAC instance with your signingSecret
const hmac = crypto.createHmac('sha256', signingSecret)
// Create the verification hex
const verification = hmac.update(signatureData).digest('hex')
// Check if it matches the header value
return verification === requestSignature
}Last updated