@flexfactory/policy
v4.1.3
Published
A policy library for use within Hotelflex services
Downloads
37
Readme
policy
Install
npm i --save @flexfactory/policy
Usage
Securing an endpoint
const { Session } = require('@flexfactory/policy');
if(!ctx.session) {
throw Boom.unauthorized();
}
const session = new Session(ctx.session);
const hasAccess = session.hasAccess({
actions: ['read'],
resources: ['svc:auth:accounts']
});
if(!hasAccess) {
throw Boom.forbidden();
}
Checking token permissions
const { Token } = require('@flexfactory/policy');
if(!tokenData) {
throw Boom.unauthorized();
}
const token = new Token(tokenData);
const hasAccess = token.hasAccess({
actions: ['read'],
resources: ['svc:auth:accounts']
});
if(!hasAccess) {
throw Boom.forbidden();
}