0.15.1 • Published 2 years ago

@brickblock/authorisation-library v0.15.1

Weekly downloads
112
License
UNLICENSED
Repository
-
Last release
2 years ago

Authorisation library

This authorisation library consists of functions that decode a JWT token and also allows permission and role checking of a decoded token.

Functions are listed below:

  1. parseTokenFromCookie(ctx.req.getHeader('cookie')) => parses a token out of a cookie header
  2. parseTokenFromAuthorisationHeader(ctx.req.getHeader('authorization')) => parses a token out of a authorization header
  3. decodeToken(token) => decodes a token
  4. getToken(ctx.req.getHeader('cookie'), ctx.req.getHeader('authorization')) => returns a token from a header
  5. hasPermission(token, permission) => checks if a permission is in a token
  6. hasRole(token, role) => checks if a role is in a token
  7. getRoles(token) => returns an array of roles from a token
  8. getPermissions(token) => returns an array of permissions from a token
  9. getGroups(token) => return an array of groups from a token
  10. getUserId(token) => returns auth0 user id of the format auth0|<id>
  11. requirePermissions(string[], token) => returns true if token contains all required permissions; otherwise throws an error.
  12. requireRoles(string[], token) => returns true if token contains all required roles; otherwise throws an error.

To add to a service

  1. yarn add @brickblock/authorisation-library

How to develop

Please us TDD, write tests then your function.

  1. yarn link
  2. yarn build
  3. yarn link @brickblock/authorisation-library => in the service you need this library in!

To use in service

Import as outlined below

const {
  getToken,
  getRoles,
  getPermission,
} = require('@brickblock/authorisation-library')

Dubugging the tests

  {
    "name": "Debug Jest Tests",
    "type": "node",
    "request": "launch",
    "runtimeArgs": [
      "--inspect-brk",
      "${workspaceRoot}/node_modules/.bin/jest",
      "--runInBand"
    ],
    "env": { "BBK_RUNTIME_ENVIRONMENT": "development" },
    "console": "integratedTerminal",
    "internalConsoleOptions": "neverOpen",
    "port": 9229
  }
0.15.1

2 years ago

0.15.0

2 years ago

0.14.0

2 years ago

0.13.3

2 years ago

0.13.1

3 years ago

0.13.2

3 years ago

0.13.0

5 years ago

0.12.1

5 years ago

0.12.0

5 years ago

0.11.2

5 years ago

0.11.1

5 years ago

0.11.0

5 years ago

0.10.1

5 years ago

0.10.0

5 years ago

0.9.1

5 years ago

0.9.0

5 years ago

0.8.0

5 years ago

0.7.1

5 years ago

0.7.0

5 years ago

0.6.1

5 years ago

0.6.0

5 years ago

0.5.1

5 years ago

0.5.0

5 years ago

0.4.0

5 years ago

0.3.0

5 years ago

0.2.0

5 years ago

0.1.0

5 years ago