Skip to content

Instantly share code, notes, and snippets.

@dariye
Last active August 21, 2018 01:05
Show Gist options
  • Save dariye/461744e4f1ad0c8852fa95d6f8284684 to your computer and use it in GitHub Desktop.
Save dariye/461744e4f1ad0c8852fa95d6f8284684 to your computer and use it in GitHub Desktop.
Validate github webhook event
const crypto = require('crypto')
/**
* Sign request body using secret and HTTP request body
* @param {string} key Secret key
* @param {body} body HTTP request body
* @returns {string} Generate hash code
*/
function signRequestBody (key, body) {
return `sha1=${crypto.createHmac('sha1', key).update(body, 'utf-8').digest('hex')}`
}
module.exports = { signRequestBody }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment