Back to All

How to verify webhook

Hello, we are having issues trying to verify webhook comparing the generated signature and that returned in one of the ones sent in the svix-signature header.

This is the code below.

const getWebhookSignature = (svixId, svixTimestamp, body) => {
  
    const signedContent = `${svixId}.${svixTimestamp}.${body}`
    const secret = process.env.MAPRALAD_WEBHOOK_SECKEY; // your webhook secret 

    // Need to base64 decode the secret
    const secretBytes = new Buffer(secret.split('_')[1], "base64");
    const signature = crypto
        .createHmac('sha256', secretBytes)
        .update(signedContent)
        .digest('base64');
  
    console.log(signature);
    return signature
}

exports.webhookResponse = async(req, res) =>{

    res.status(200).send()
    console.log(req.body)
      const body = req.body
          
          const svixId = req.headers["svix-id"]
          const svixTimestamp = req.headers["svix-timestamp"]
          const svixSignature = req.headers["svix-signature"]
          
          const signature = getWebhookSignature(svixId, svixTimestamp, body)
          console.log(signature)
          console.log(svixSignature.substring(3))
  //to check
  if(svixSignature === signature){
  //rest code
  }
  
  
}

The issue is that the svixSignature and signature are never the same. Please what mistake is been made here?

Hi there, can I see an example of the signature you get in the webhook?

This is an example

Psj7Z4kfq4k1l3Ex661N74Ccs3uINqv3kNIBw7+VvQI=

When comparing it with the svixSignature after removing version prefix and delimiter with substring the svixSignature becomes below

hhY6bKPlsRR7byeVNrzXYCXKu+j2TvNwwMaiC6z8dls=

The two strings are never the same

It's possible to get multiple strings in the svixSignature header, please confirm if it doesn't match either.

Just one string is returned when console logging the svixSignature

Please try integrating without verifying, while we investigate this.

Please try integrating without verifying, while we investigate this.

Please try integrating without verifying, while we investigate this.

Please try integrating without verifying, while we investigate this.

ok

Had this been fixed please

*has

ο»Ώ