Last active
August 29, 2015 14:25
-
-
Save avnersorek/44b7d8135f2e15a11a79 to your computer and use it in GitHub Desktop.
Doorbell.io Node.js server side integration
This file contains 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'); | |
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 | |
} |
This file contains 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
script. | |
window.doorbellOptions = #{JSON.stringify(doorbellOptions)}; | |
// rest of the doorbell snippet - make sure not to over-run the doorbellOptions object |
This file contains 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 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