doorknob

add Mozilla Persona user login and LevelDB based session storage to node web apps

Usage no npm install needed!

<script type="module">
  import doorknob from 'https://cdn.skypack.dev/doorknob';
</script>

README

doorknob

convenience module for adding Mozilla Persona user login + LevelDB based session storage to node web apps

Uses levelup for storing sessions and Mozilla Persona (via the persona-id module) for user sign-on.

get it on npm

npm install doorknob

test it out locally

  1. clone this repo
  2. npm install
  3. npm test
  4. open localhost:8080

API

require + make an instance

var doorknob = require('doorknob')(audience || options)

returns a function that you can use to authenticate requests and responses, e.g. function(req, res) {}

arguments:

  • if you just pass a string it has to be the persona audience URL (default is http://localhost:8080)
  • options gets passed to the levelup constructor internally
  • by default valueEncoding is set to json but you can override that
  • you can also pass in your own levelup instance (or technically anything with the same API) via options.db
  • after initializing, doorknob.db is the levelup instance (or the db object you passed in)

handle a request/response

require('http').createServer(function(req, res) {
  doorknob(req, res, function(err, profile) {
    if (profile.loggingIn) // the request has been handled by persona
    if (profile.email) // the user is logged in
    else // the user is not logged in
  })
}).listen(8080)

license

BSD