Skip to content

Instantly share code, notes, and snippets.

@GabiGrin
Created April 3, 2016 12:37
Show Gist options
  • Select an option

  • Save GabiGrin/f90150a42da0563b8126cbb23c01f610 to your computer and use it in GitHub Desktop.

Select an option

Save GabiGrin/f90150a42da0563b8126cbb23c01f610 to your computer and use it in GitHub Desktop.
Answers Webhook Signed request
var apiKey = 'YOUR KEY HERE';
var secret = 'YOUR SECRET HERE';
var crypto = require('crypto');
var requestify = require('requestify');
function signedPost (url, data) {
var signer = cryto.createHmac('sha256', new Buffer(secret, 'utf8'));
var jsonData = unescape(encodeURIComponent(JSON.stringify(data)));
var signature = signer.update(jsonData).digest('hex');
return requestify.post(url, data, { //I used requestify, but any other method for doing cross-server requests is valid, the only thing that matters are the headers..
headers: {
'X-Auth-Api-Key': apiKey,
'X-Auth-Data-Signature': signature
}
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment