Skip to content

A simple feathers' hook to provide permissions per provider, service and method.

Notifications You must be signed in to change notification settings

SetaSouto/feathers-hook-provider-permissions

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Feathers hook ProviderPermissions

A simple hook for your feathers app to provide permissions to execute methods on services based on the provider, the service and the method.

Quick start

Install the package:

npm i feathers-hook-provider-permissions

Use it in your app:

// app.hooks.js
const providerPermissions = require('feathers-hook-provider-permissions');

module.exports = {
  before: {
    all: [
      providerPermissions({
        rest: {
          // Only users/find method can accessible through rest provider
          users: ['find']
          // Services omitted won't be accessible by that provider
        },
        socketio: {
          // Users get and find only available methods
          users: ['get', 'find'],
          // All the methods of the posts service without 'update'
          posts: ['get', 'find', 'create', 'patch', 'remove'],
          comments: [], // All the methods of the comments service
        },
        // Providers omitted won't be allowed
      }),
    ],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  after: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  },

  error: {
    all: [],
    find: [],
    get: [],
    create: [],
    update: [],
    patch: [],
    remove: []
  }
};

And the expected behavior will be:

const app = require('./app.js')

// throws Forbidden('Provider "custom" not allowed.')
app.service('users').find({ provider: 'custom' })
// works ok
app.service('users').create(data, { provider: 'socketio' })
app.service('users').find({ query: {}, provider: 'socketio' })
app.service('users').find({ query: {}, provider: 'rest' })
// throws Forbidden('Provider "rest" not allowed to access method "find" of service "posts")
app.service('posts').find({ query: {}, provider: 'rest' })

Author

About

A simple feathers' hook to provide permissions per provider, service and method.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published