Created
April 3, 2016 12:37
-
-
Save GabiGrin/f90150a42da0563b8126cbb23c01f610 to your computer and use it in GitHub Desktop.
Answers Webhook Signed request
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 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