New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

@brickblock/authorisation-library

Package Overview
Dependencies
Maintainers
3
Versions
27
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@brickblock/authorisation-library

This is a simple library for decoding a JWT token and checking permissions and roles

latest
npmnpm
Version
0.15.1
Version published
Weekly downloads
38
Maintainers
3
Weekly downloads
 
Created
Source

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:

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

To add to a service

  • yarn add @brickblock/authorisation-library

How to develop

Please us TDD, write tests then your function.

  • yarn link
  • yarn build
  • 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
  }

FAQs

Package last updated on 14 Oct 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts