Created
April 18, 2021 12:14
-
-
Save sehmbimanvir/9ff0fb7efa430d70577cf580908da633 to your computer and use it in GitHub Desktop.
This file contains 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 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