Skip to content

Instantly share code, notes, and snippets.

@sehmbimanvir
Created April 18, 2021 12:14
Show Gist options
  • Save sehmbimanvir/9ff0fb7efa430d70577cf580908da633 to your computer and use it in GitHub Desktop.
Save sehmbimanvir/9ff0fb7efa430d70577cf580908da633 to your computer and use it in GitHub Desktop.
const express = require('express');
const crypto = require('crypto');
require('dotenv/config');
const app = express();
app.use(express.json());
app.post('/mentor', function (req, res) {
const { SECRET_KEY } = process.env
const { body, headers } = req
// Create Signature from Request Body
const expectedSignature = `sha1=${crypto.createHmac('sha1', SECRET_KEY).update(JSON.stringify(body).digest('hex'))}`
// Compare the signature against the one in the request
const signature = headers["x-hub-signature"];
if (signature !== expectedSignature) {
throw new Error("Invalid signature.");
}
res.send('API Works');
})
app.listen(8081, function () {
console.log('Listening on Port 8081');
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment