1.0.3 • Published 8 years ago

hawkify-pouchdb v1.0.3

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

Hawkify PouchDB

Make PouchDB HTTP requests use hawk authentication.

Sign your PouchDB requests with a hawk Authorization header. This plugin works in conjunction with MRN-Code/nodeapi and MRN-Code/coinstac-storage-proxy to ensure clients using PouchDB are authenticated.

Installation

Make sure you have Node.js (4.2.x or greater) and NPM installed. To use hawkify-pouchdb in your project, run:

npm install hawkify-pouchdb --save

Use

This plugin works by altering PouchDB’s internal request system. hawkify-pouchdb exports a single function which expects two arguments:

  1. PouchDB: The PouchDB constructor.
  2. credentials: A valid hawk credentials object with algorithm, id and key properties. Example:

    {
      algorithm: 'sha256',
      id: 'abcdef',
      key: '1234567890',
    }

    See hawk’s source code for further documentation.

Example

const PouchDB = require('pouchdb');
const hawkifyPouchDB = require('hawkify-pouchdb');
const myCredentials = {
  algorithm: 'sha256',
  id: 'abcdef',
  key: '1234567890',
};

hawkifyPouchDB(PouchDB, myCredentials);

const myDb = new PouchDB('http://localhost:5984/my-database/');

myDb.get('my-doc-id')
  .then(response => {
    // Request was valid
  })
  .catch(error => {
    // Error, potentially due to invalid credentials
  });

Development

To work on hawkify-pouchdb, clone this repository and run npm install in the directory to install its dependencies.

License

MIT. See LICENSE.