AuthorizedResource extends Resource
rest-io
supports Authorized Resources. The UserResource is mandatory to enable authorized resources.
To create an Authorized Resource:
import { AuthorizedResource, ROLES } from 'rest-io';
export default class BananaResource extends AuthorizedResource {
...
}
Now you can overwrite the standard calls and authorizations:
export default class BananaResource extends AuthorizedResource {
constructor() {
this.permissions = {
getAll: [ROLES.USER, ROLES.SUPER_USER, ROLES.MODERATOR, ROLES.ADMIN],
getById: [ROLES.USER, ROLES.SUPER_USER, ROLES.MODERATOR, ROLES.ADMIN],
create: [ROLES.MODERATOR, ROLES.ADMIN],
update: [ROLES.MODERATOR, ROLES.ADMIN],
del: [ROLES.ADMIN]
};
}
});
const banana = new BananaResource({
name: 'banana',
model: {
name: String
}
});
The Authorized Resource allows you to easily configure per method what roles have access to them.
A set of string constants that you are free to adjust to your needs.
Object defining the allowed roles. When an empty array of roles is provided, no authorization will be performed. This allows users who are not logged in to access this resource.
Array of role names allowed to access.
Array of role names allowed to access.
Array of role names allowed to access.
Array of role names allowed to access.
Array of role names allowed to access.