Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including @nearform/udaru-hapi-16-plugin with all npm packages installed. Try it out:

var udaruHapi16Plugin = require("@nearform/udaru-hapi-16-plugin")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

@nearform/udaru-hapi-16-plugin v5.3.2

Hapi plugin that allows using udaru for policy based authorization

Udaru Hapi Plugin

npm travis coveralls snyk

Udaru is a Policy Based Access Control (PBAC) authorization module. It supports Organizations, Teams and User entities that are used to build the access model. The policies attached to these entities define the 'Actions' that can be performed by an entity on various 'Resources'.

See the Udaru website for complete documentation on Udaru.

Install

To install via npm:

npm install @nearform/udaru-hapi-16-plugin

Usage

const Hapi = require('hapi')
const UdaruPlugin = require('@nearform/udaru-hapi-16-plugin')

...

const server = new Hapi.server()
server.register({register: UdaruPlugin})

Hooks

In order to register udaru hooks, just provide a hooks key in the plugin options where keys are the names and values are handler functions (or array of functions).

const Hapi = require('hapi')
const UdaruPlugin = require('@nearform/udaru-hapi-16-plugin')

...

const server = new Hapi.server()
server.register({
  register: UdaruPlugin,
  options: {
    // Other options here
    hooks: {
      'authorize:isUserAuthorized': [
        function (error, args, result, done) {
          if (error) {
            console.error(`Authorization errored: ${error}`)
          } else {
            console.log(`Access to ${args[0]} got access: ${result[0].access}`)
          }

          done()
        }
      ]
    }
  }
})

License

Copyright nearForm Ltd 2017. Licensed under MIT.

RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free