hawkify-pouchdb
v1.0.3
Published
Make PouchDB HTTP requests use Hawk authentication.
Downloads
8
Keywords
Readme
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:
PouchDB
: The PouchDB constructor.credentials
: A valid hawk credentials object withalgorithm
,id
andkey
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.
- Style: This plugin adheres to the Airbnb JavaScript style guide via ESLint. Run
npm run lint
to lint the files. - Tests: This plugin uses tape for testing. Run
npm test
to run the tests.
License
MIT. See LICENSE.