All Projects → Canner → graphql-rbac

Canner / graphql-rbac

Licence: Apache-2.0 license
GraphQL Role-based access control (RBAC) middleware

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language

Projects that are alternatives of or similar to graphql-rbac

express-objection-starter
an opinionated, production-ready, isomorphic express/knex/objection starter with centralized configuration
Stars: ✭ 19 (-47.22%)
Mutual labels:  rbac
WendzelNNTPd
A usable and IPv6-ready Usenet-server (NNTP daemon). It is portable (Linux/*BSD/*nix), supports AUTHINFO authentication, contains ACL as well as role based ACL and provides "invisible" newsgroups. It can run on MySQL and SQLite backends.
Stars: ✭ 43 (+19.44%)
Mutual labels:  rbac
laravel-casbin-admin
Vue-Element-Admin + Laravel开发前后端分离的Rbac管理后台
Stars: ✭ 109 (+202.78%)
Mutual labels:  rbac
egg-rbac
Role Based Access Control for eggjs
Stars: ✭ 32 (-11.11%)
Mutual labels:  rbac
linkifier
Database reverse engineering
Stars: ✭ 32 (-11.11%)
Mutual labels:  schema
nt-casbin
nest.js with casbin auth Nest.js RBAC ABAC 权限管理
Stars: ✭ 27 (-25%)
Mutual labels:  rbac
examples
Apache Pulsar examples and demos
Stars: ✭ 41 (+13.89%)
Mutual labels:  schema
openapi-types.ts
Generated TypeScript definitions based on GitHub's OpenAPI spec
Stars: ✭ 30 (-16.67%)
Mutual labels:  schema
k8s-security-demos
Demos for several kubernetes security features
Stars: ✭ 60 (+66.67%)
Mutual labels:  rbac
performify
Service object which makes you better.
Stars: ✭ 14 (-61.11%)
Mutual labels:  schema
classicpress-seo
Classic SEO is the first SEO plugin built specifically to work with ClassicPress. A fork of Rank Math, the plugin contains many essential SEO tools to help optimize your website.
Stars: ✭ 18 (-50%)
Mutual labels:  schema
Workshop-GraphQL
A GraphQL Server made for the workshop
Stars: ✭ 22 (-38.89%)
Mutual labels:  schema
srclient
Golang Client for Schema Registry
Stars: ✭ 188 (+422.22%)
Mutual labels:  schema
gke-anthos-holistic-demo
This repository guides you through deploying a private GKE cluster and provides a base platform for hands-on exploration of several GKE related topics which leverage or integrate with that infrastructure. After completing the exercises in all topic areas, you will have a deeper understanding of several core components of GKE and GCP as configure…
Stars: ✭ 55 (+52.78%)
Mutual labels:  rbac
csv-schema
Parse a CSV file into PHP objects based on a schema.
Stars: ✭ 23 (-36.11%)
Mutual labels:  schema
popoto-examples
Contains a list of Popoto.js examples
Stars: ✭ 121 (+236.11%)
Mutual labels:  schema
openapi4j
OpenAPI 3 parser, JSON schema and request validator.
Stars: ✭ 92 (+155.56%)
Mutual labels:  schema
lua-casbin
An authorization library that supports access control models like ACL, RBAC, ABAC in Lua (OpenResty)
Stars: ✭ 43 (+19.44%)
Mutual labels:  rbac
citrus
🌈 低代码快速开发脚手架,灵活、高效,降低开发成本
Stars: ✭ 368 (+922.22%)
Mutual labels:  rbac
scheriff
Schema Sheriff: yet another Kubernetes manifests validation tool
Stars: ✭ 15 (-58.33%)
Mutual labels:  schema

GraphQL Role-based access control (RBAC) middleware

CircleCI npm version

graphql-rbac provides you a simple way to use Role-based access control in GraphQL. This package integrates with graphql-shield which helps you create a permission layer for your application. Using a schema with array of role, graphql-rbac can help you generate rule functions in graphql-shield. So you can easily use RBAC in your application by providing a schema.

Why graphql-rbac?

  • Easy to specify rule permissions for each field in GraphQL.
  • Don't need to write rule function by yourself.

Installation

yarn add graphql-rbac

How to use

import { RBAC } from 'graphql-rbac'

const roles = ['ADMIN', 'DEVELOPER']

const schema = {
  Query: {
    users: ['ADMIN', 'DEVELOPER']
  },
  Mutation: {
    createUser: ['ADMIN', 'DEVELOPER'],
    updateUser: ['ADMIN', 'DEVELOPER'],
    deleteUser: ['ADMIN']
  },
  User: {
    password: ['ADMIN']
  }
}

const typeDefs = `
  type Query {
    users: [User!]!
  }

  type Mutation {
    createUser: User!
    updateUser: User!
    deleteUser: User
  }

  type User {
    username: String!
    password: String!
  }
`

const resolvers = {
  Query: {
    users: () => [
      { username: 'Tom', password: '****' },
      { username: 'John', password: '****' },
    ]
  },
  Mutation: {
    createUser: () => { username: 'Tom', password: '****' },
    updateUser: () => { username: 'John', password: '****' },
    deleteUser: () => null
  }
}

const users = {
  admin: { role: 'ADMIN' },
  developer: { role: 'DEVELOPER' }
}

const getUser = async (req) => {
  const auth = req.request.headers.authorization
  let user = {}
  if (users[auth]) {
    user = users[auth]
  }

  return user
}

const rbac = new RBAC({roles, schema, getUser})

const server = new GraphQLServer({
  typeDefs,
  resolvers,
  middlewares: [rbac.middleware()],
  context: req => ({
    user: rbac.context(req)
  }),
})

Run test

npm run test

License

Apache-2.0

footer banner

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].