Skip to content

Instantly share code, notes, and snippets.

@idmontie
Created June 6, 2019 18:06
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save idmontie/15eb8b56b6a246ad45e1fbd71b422847 to your computer and use it in GitHub Desktop.
Save idmontie/15eb8b56b6a246ad45e1fbd71b422847 to your computer and use it in GitHub Desktop.
Intercom webhook signature validation
const express = require('express');
const bodyParser = require('body-parser');
const crypto = require('crypto');
const serverless = require('serverless-http');
const app = express();
const KEY = 'YOUR_KEY';
app.use(bodyParser.raw({
type: '*/*',
}));
app.post('/webhooks/intercom', (req, res) => {
const signature = req.headers['x-hub-signature'];
console.log(req.body);
const hmac = crypto.createHmac('sha1', KEY);
hmac.update(req.body, 'utf-8');
const signed = `sha1=${hmac.digest('hex')}`;
console.log(signed);
console.log(signature);
if (signed === signature) {
console.log('signatures match');
res.sendStatus(200);
} else {
console.error('signatures DO NOT match');
res.sendStatus(403);
}
});
module.exports.handler = serverless(app);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment