How to verify your webhooks?

How to verify your webhooks?

Verifying webhooks is crucial for ensuring the authenticity, integrity, and security of data exchanged between applications. In this guide, I will explain how to verify your webhooks.

Initialize webhook configuration

On the top right hand corner of your screen, click on the Profile menu. Go into the Workspace > Integrations > Webhook

Paste your webhook URL and select events you want to connect to Doran webhooks.

Copy your webhook secret key

After initializing your webhook configuration, Doran will show you a secret key. Copy it.

Verify your webhook

NodeJS

Now, you can verify your webhook. In this example, we use Express.

const express = require( 'express' );
const bodyParser = require("body-parser");

const WEBHOOK_SECRET_KEY = '' // TODO: Paste your secret key;

function ksort(obj){
  const keys = Object.keys(obj).sort();
  let sortedObj = {};
  for (let i in keys) {
    sortedObj[keys[i]] = obj[keys[i]];
  }
  return sortedObj;
}

function validateWebhook(body, dSignature) {
  const sortedBody = ksort(body);
  const signature = crypto
    .createHmac('sha256', WEBHOOK_SECRET_KEY)
    .update(JSON.stringify(sortedBody))
    .digest('base64');

  return dSignature === signature;
}

const app = express();
app.use(bodyParser.urlencoded({ extended: true }));

app.post('/', (req, res) => {
  if (validateWebhook(req.body, req.get('d-signature'))) {
    console.log('WEBHOOK_VERIFIED');
    res.status(200).end();
  } else {
    res.sendStatus(403);
    console.log('WEBHOOK_NOT_VERIFIED')
  }
})
Linda Bui
Linda Bui
Updated a week ago 1 min read