Skip to content

Ingests permission statements and checks against the required values.

Notifications You must be signed in to change notification settings

PaperElectron/matrix-authorization

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Matrix authorization

Node based permission checks in Node.

Build Status Coverage Status

API

/*
 * Create some permissions to check against.
 */

var permissions = {
  user: ['create', 'read', 'update', 'delete'],
  post: ['create', 'read', 'update', 'delete'],
  tag: [{list: [{limit: [10, 20, 30, 40, 50]}]}]
}

/*
 * Instantiate the module, passing in your permissions object.
 */
var matrix = require('matrix-auth')(permissions)

/*
 * Create a function to call with the values you want to check.
 * Pass in an array of the required nodes.
 */

var checkFn1 = matrix.createCheck(['user.create', 'tag.list.limit.50'])

/*
 * Call the created function with the values you want to check.
 */

// matches everything downstream of the *
checkFn1({user: ['*'], tag: [{list: ['*']}]}) // true

// matches everything downstream of the *
checkFn1({user: ['*'], tag: ['*']}) // true

//missing tag node.
checkFn1({user: ['*']}) // false

Todo

  • More robust argument handling. Accept comma delimited strings, in addition to arrays.
  • Accept an array of pure node values into the function returned by createCheck
  • fuzzy matching where possible, ie node.50 matches node.[0-50]

About

Ingests permission statements and checks against the required values.

Resources

Stars

Watchers

Forks

Packages

No packages published