Access controlling is one of the most important parts of every application, there are many kinds of models for access controlling like MAC (Mandatory Access Control), DAC (Discretionary Access Control), RBAC (Role Based Access Control) and etc (for more information about access models see this link)
loopback-component-authorization is a powerful and generic implementation of HRBAC (Hierarchical Role Based Access Control) access model
npm i --save loopback-component-authorizationFollow these steps to add authorization extension to your loopback4 application
- Optional: Define
User,Role,Permissionmodels - Optional: Define
User,Role,Permissionrepositories - Optional: Define
Permissionsclass - Define your
dataSource - Add
AuthorizationMixinto your application - Add
AuthorizationActionProviderto your custom http sequence handler - Use
GetUserPermissionsProviderto find user permissions whensigninandsavethe permissions in user's session
Now, let's try these
Use the command lb4 model for simplifing your Entity model creation, then just replace Entity class with User, Role or Permission as the parent class
See this example: