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.
There are two main goals for this project:
- Don't be tied to any specific web framework
- Make it as easy as possible to spin up new web apps that users can log in to
Get it on npm
npm install doorknob
Rest it out locally
- clone this repo
- npm install
- npm test
- open localhost:8080
API
Require + make an instance
var doorknob = audience || options
Returns a function that you can use to authenticate requests and responses, e.g. function(req, res) {}
Default options:
valueEncoding: 'json' location: path db: audience: 'http://localhost:8080' devMode: false // used to develop offline, returns a fake session
- If you just pass a string as the only argument it has to be the persona audience URL (default is http://localhost:8080)
- Options gets passed to the levelup constructor internally
- 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
using the built in server
There is a default server that uses http
from node core to handle the basic functionality. It will create a doorknob instance for you and mount it in front of a static file server. You'll want to specify in your own front-end assets (via the staticPath
option), but you can check out the working (but unstyled) www/
folder in this repo for an example.
var createServer =
Then create a server with some optional options, here are the defaults:
var server =
server
is an http.Server
instance with the doorknob
instance available as server.doorknob
.
onRequest
is a function that gets passed (req, res, profile, callback)
. You must call the callback with either true
if you handled the request and nothing else should happen or false
if you want the server to try to serve a static file for the request.
var server =
Additionally you can GET /_profile
to retrieve the current user profile.
license
BSD