Giter VIP home page Giter VIP logo

salti-admin's Introduction

SALTI-Admin

Build Status Coverage Status

Simple Authentication/Authentication Library for Thali IoT

Provides a simple Express Middleware implementation that checks a simple Authorization header.

A supporting sample that utilizes PouchDB and express-pouchdb

Using the library..

npm install --save salti-admin

Server side setup.

You should have an Express site available.

var adminAcl = require('salti-admin');

Determine a secret.

You can use any secret - but, there is a utility method to generate one.

The example below - this generates a secret - then sets the secret for the salti-admin library, then also sets the Express app property (optional).

Then this inserts the middleware, and the final call here sets up express-pouchdb app.

adminAcl.generateSecret(function (err, secret) {

  adminAcl.setSecret(secret);
  
  //also setting this in the App - see above for the API route
  app.set('secret', secret);
  
  //inject our middleware.. - needs to be BEFORE the express-pouchdb app setup.
  app.use(adminAcl.isAdminOk);

  app.use('/', require('express-pouchdb')(PouchDB, pouchOptions));
 
});

Client setup

This just requires that the same secret is shared on the client.

For example, here we're setting the PouchDB client options.

The secret is the same from above with the word CLEAR as a prefix

  pouchDbOptions.ajax.headers = {
    'User-Agent': 'request',
    'Authorization' : 'CLEAR ' + secret
  }
  
  var remoteDB = new PouchDB('https://localhost:3001/_validate', pouchDbOptions)

Setting up..

  • First - clone - then run npm install on both the root and the sample
  • Then move to the directory
  • run npm install
  • run the tests with mocha
  • move to the sample directory
  • run npm install
  • run the sample app
git clone https://github.com/cicorias/salti-admin
cd salti-admin
npm install
mocha
cd sample
npm install
node ./server.js


Running Tests

You first should have mocha installed.

npm install -g mocha

Then from the root, just run mocha

Running solution

There is a sample solution that sets up 3 Express sites.

cd sample
npm install
node ./server

At this point, you have 3 sites running.

Go to the main site at https://localhost:3000

From there other links are visible: PouchDB / Fauxton site: http://localhost:3002

Validation Page.

Validation page demonstrates the creation of a document - check the code for the calling pattern.

The field that shows the current secret it set automatcially at startup.

Try a few "create docs" and you should see the response in the green box.

Then, change the key to something else - then again try to create docs - at this point you should see messages on each failure in the red box.

Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact [email protected] with any additional questions or comments.

salti-admin's People

Contributors

cicorias avatar yaronyg avatar

Watchers

James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.