node package manager



A Node.js server that integrated Mozilla Persona logins with Apache CouchDB, once a user has successfully authenticated with persona we create a user and a database for their use only, on a successful login this script will return the url to a couchdb database and a token used to authenticate against that instance.


couch-persona requires a CouchDB host running, preferably with CORS support enabled.

Install and start your server

$ npm install -g couch-persona
$ couch-persona --host= --username=john --password=doe

Follow the Quick Setup instructions on the MDN wiki to install the persona client on your site, ensure you use the correct urls to sign in and out (/persona/sign-in + /persona/sign-out). Here is some example working code:

// Host that the couch-persona server is running on 
var authHost = '';
var loggedIn = function(result) { 
  console.log('logged in:', result);
  // result.dbUrl is the location of your CouchDB Instance 
  // result.authToken is the token you need to be able to write to it,  
  // use xhr.setRequestHeader("Cookie", result.authToken); 
var loggedOut = function() { 
  console.log('logged out!');
function simpleXhrSentinel(xhr) {
  return function() {
    if (xhr.readyState == 4) {
      if (xhr.status == 200) {
        var result = {};
        try { 
          result = JSON.parse(xhr.responseText);
        } catch(e) {}
      } else {
function verifyAssertion(assertion) {
  var xhr = new XMLHttpRequest();
  var param = 'assert=' + assertion;'POST', authHost + '/persona/sign-in', true);
  xhr.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
  xhr.setRequestHeader("Content-length", param.length);
  xhr.setRequestHeader("Connection", "close");
  xhr.onreadystatechange = simpleXhrSentinel(xhr); 
function signoutUser() {
  var xhr = new XMLHttpRequest();"POST", authHost + '/persona/sign-out', true);
  xhr.onreadystatechange = simpleXhrSentinel(xhr); 
  onlogin: verifyAssertion,
  onlogout: signoutUser 
var signinLink = document.getElementById('signin');
var signoutLink = document.getElementById('signout');
signinLink.onclick = function() {; };
signoutLink.onclick = function() {; };