This is an example application which shows how to integrate CASL.
Application uses jwt
tokens for authentication.
Used packRules and unpackRules
Rules are stored in database,while user login fetch the rules based on the roles and help of packRules decreases serialized rules and storing the ability to JWT
Permission logic are define in src/hooks/authorize.js.
please refer the folder seed/db-dump.json
"permissions": [{
"actions": [
"manage"
],
"fields": [],
"inverted": false,
"subject": "all",
"roleId": "5bffd7bb66e5320cf0e3dcd6",
},
{
"actions": [
"read"
],
"fields": [],
"inverted": false,
"subject": "shop",
"roleId": "5bffdaebc06a620d0f7572eb",
"conditions": {
"organizationId": "${user.organizationId}",
"createdBy": "${user.createdBy}"
},
},
{
"actions": [
"create",
"update",
"read"
],
"fields": [],
"inverted": false,
"subject": "products",
"roleId": "5bffdaebc06a620d0f7572eb",
"conditions": {
"organizationId": "${user.organizationId}",
"createdBy": "${user.createdBy}"
},
"createdAt": "2018-11-29T13:29:26.483Z",
"updatedAt": "2018-11-29T13:29:26.483Z"
},
{
"actions": [
"delete"
],
"fields": [],
"inverted": true,
"subject": "products",
"roleId": "5bffdaebc06a620d0f7572ed",
"conditions": {
"organizationId": "${user.organizationId}",
"createdBy": "${user.createdBy}"
},
}
]
-
Clone the application repository
$ git clone git@github.com:gowthaman-i2i/casl-featherjs-plus-example.git
-
Install your dependencies
$ npm install
-
Start your application
$ npm start
-
Seed default set-up
$ npm run start:seed
or
Register default user, roles and permissions
$ npm run seed
-
Documentation
$ npm run docs
API base URL - http://localhost:3030/
Swagger API document URL - http://localhost:3030/docs
Note: You can also use postman,I have attached the postman collection json file(CASL-FEATHERSJS-PLUS-EXAMPLE.postman_collection.json) import your postman and use.
- Create new session
POST http://localhost:3030/authentication
{
"strategy": "local",
"email": "test@test.com",
"password": "test1234"
}
201 Created
{ "accessToken": "...." }
- Put access token in
Authorization
header for all future requests
- /shops
- /products
- /permissions
- /users
- /roles
- /authentication
For more information on all the things you can do, visit
- the generator,
- feathersJS
- extensions.
- authorization-with-casl-in-feathersjs
- casl-feathers-example
- casl-ability
- casl-mongoose
0.1.0
- Initial release
Copyright (c) 2018
Licensed under the MIT license.