Assuming express, we can throw a little bodyParser
middleware at it
var express = require('express');
var bodyParser = require('body-parser');
var app = express();
app.use(bodyParser.json({
verify: function(req, res, buf, encoding) {
// is there a hub to verify against
req.twitch_hub = false;
if (req.headers && req.headers['x-hub-signature']) {
req.twitch_hub = true;
var xHub = req.headers['x-hub-signature'].split('=');
req.twitch_hex = crypto.createHmac(xHub[0], mysecret)
.update(buf)
.digest('hex');
req.twitch_signature = xHub[1];
}
}
}));
app.route('/webhook/').post(function(req, res) {
res.send('OK');
if (req.twitch_hub && req.twitch_hex == req.twitch_signature) {
// it's good
} else {
// it's bad
}
})
Additional example/previous forum post on the same subject: