Skip to content

trendscenter/hawkify-pouchdb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

19 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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.

About

Make PouchDB HTTP requests use Hawk authentication.

Resources

License

Stars

Watchers

Forks

Packages

No packages published