Created
June 6, 2019 18:06
-
-
Save idmontie/15eb8b56b6a246ad45e1fbd71b422847 to your computer and use it in GitHub Desktop.
Intercom webhook signature validation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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