Skip to content

Instantly share code, notes, and snippets.

@avnersorek
Last active August 29, 2015 14:25
Show Gist options
  • Save avnersorek/44b7d8135f2e15a11a79 to your computer and use it in GitHub Desktop.
Save avnersorek/44b7d8135f2e15a11a79 to your computer and use it in GitHub Desktop.
Doorbell.io Node.js server side integration
var crypto = require('crypto');
var DOORBELL_SECRET = '--your secret--';
var DOORBELL_KEY = '--your app key--';
function getOptions() {
var options = {
appKey: DOORBELL_KEY,
timestamp: Math.floor(new Date() / 1000),
token: crypto.randomBytes(16).toString('hex')
};
options.signature = crypto
.createHmac("sha256", DOORBELL_SECRET)
.update('' + options.timestamp + options.token)
.digest("hex");
return options;
}
module.exports = {
getOptions: getOptions
}
script.
window.doorbellOptions = #{JSON.stringify(doorbellOptions)};
// rest of the doorbell snippet - make sure not to over-run the doorbellOptions object
var express = require('express');
var doorbell = require('./doorbell');
var app = express();
app.use(function(req, res, next){
res.locals.doorbellOptions = getDoorbellOptions();
return next();
});
app.listen();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment