-
-
Save gregbarcza/b4dc27c53af5eef43144 to your computer and use it in GitHub Desktop.
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
var Crypto = require('crypto'); | |
/** | |
* validates a mandrill webhook request | |
* @param url string the url that mandrill sent the request to | |
* @param key string the web hook key from https://mandrillapp.com/settings/webhooks | |
* @param params array the request's POST parameters i.e. req.params | |
* @param compareTo string the x-mandrill-signature header value | |
*/ | |
var validate = function validate(url, key, params, compareTo) { | |
var data = url; | |
for(var postKey in params) { | |
data += postKey; | |
data += params[postKey]; | |
} | |
var signer = Crypto.createHmac('sha1', key); | |
var signature = signer.update(data).digest('base64'); | |
return compareTo && signature === compareTo; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment