rnsync_key_generator
v1.0.4
Published
Secure way to create database and credentials for devices using RNSync
Downloads
2
Readme
rnsync_key_generator
About
rnsync_key_generator handles the creation of database and generation of credentials as recommended in the Cloudant Sync doc. This package was made to be used with RNSync, but can of course be used however you wish.
Installation
Install with npm
npm install --save rnsync_key_generator
Usage
The database name must start with a character and only lowercase characters (a-z), digits (0-9), and any of the characters _, $, (, ), +, -, and / are allowed.
Router
let express = require('express');
let rnsync_key_generator = require('rnsync_key_generator');
// You can retrieve your cloudant_url by accessing the Cloudant Service Credentials from your Bluemix.net dashboard
rnsync_key_generator.init("https://user:[email protected]");
let app = express();
app.use('/genkey', rnsync_key_generator.router);
The router accepts a GET request and expects there to be a query parameter 'dbname'.
http://server.com/genkey?dbname=mydbname
response looks like:
{
"password": "YPNCaIX1sJRX5upaL3eqvTfi",
"ok": true,
"key": "blentfortedsionstrindigl"
}
Genkey
Simply call rnsync_key_generator.genkey('dbname') to get the db credentials
rnsync_key_generator.init("https://user:[email protected]");
router.get( '/genkey', function ( req, res, next )
{
let userId = req.user.sub;
rnsync_key_generator.genkey('u' + userId)
.then( (dbCredentials) =>
{
res.status( 200 ).json( { dbCredentials } )
})
.catch( (error) => {
res.status( 500 ).json( { error } )
})
}