@storyous/identity
v1.2.0
Published
## Usage of PermissionHelper
Downloads
14
Keywords
Readme
identity
Usage of PermissionHelper
import { permissionHelper } from '@storyous/identity';
// encode
const rawPermission = [true, true, true, false, false, true];
const response = permissionHelper.encodeData(rawPermission);
...
// decode
const encodedPermission = 'e4';
const response = permissionHelper.decodeData(encodedPermission);
Usage of JwtPermissions
import { jwtPermissions } from '@storyous/identity';
import Router from 'koa-router';
// Validate JWT and permissions for specific route
router = new Router();
router.get(
'/',
jwtPermissions.validateJwtTokenMiddleware('https://example.com/getPublicKey'),
jwtPermissions.checkPermissionsMiddleWare([8, 9]),
(ctx: any) => {
ctx.body = {status: 'ok'};
ctx.status = 200;
},
);
// Authorize User
const jwtFromUser = 'someToken';
await jwtPermissions.authorizeUser(
jwtFromUser,
{
merchantId: '123,
publicKeyUrl: 'https://example.com/getPublicKey',
placeId: '1',
deviceId: '2'
permissions: [8, 9],
}
);