5.7.1 • Published 3 years ago

@infomaker/service-authorization-lib v5.7.1

Weekly downloads
16
License
UNLICENSED
Repository
github
Last release
3 years ago

Infomaker service-authorization-lib

Develop the project

Run the unit tests

docker-compose up

Rebuild after updates to package.json

docker-compose down
docker-compose build
docker-compose up

tokenUtils

Usage

  const tokenUtils = require('@infomaker/service-authorization-lib').tokenUtils

  const expressMiddlewareFunctionThing = (req, res, next) => {
    tokenUtils.extractServiceTokenFromRequest(req) // -> {...} serviceToken
    tokenUtils.extractImidTokenFromRequest(req) // -> 'eyJhbGciOiJSUzUxMiIsIn...' | null
    tokenUtils.getSubject(req) // -> '07b9d9e6-5be1-4eb2-9675-9ee702f955ce'
    tokenUtils.getOrganization(req) // -> 'infomaker'
    tokenUtils.getUnits(req) // -> ['unit-a', 'unit-b']
    tokenUtils.getSelectedUnit(req) // -> 'unit-a'
    tokenUtils.getOrgPermissions(req) // -> ['writer:access']
    tokenUtils.getUnitPermissions(req, 'infomaker-dev') // -> ['writer:access']
    tokenUtils.isServiceAdmin(req) // -> false
    tokenUtils.getUserinfo(req) // -> { given_name: ... }
  }

extractServiceTokenFromRequest(request) ⇒ Object

Extracts and decodes a service token from request

Returns: Object - serviceToken - The service token

ParamTypeDescription
requesthttp.IncomingMessage

extractImidTokenFromRequest(request) ⇒ String | null

Extracts IMID token from a raw request if present

Returns: String | null - imidToken - The IMID token if present

ParamType
requesthttp.IncomingMessage

getSubject(request) ⇒ String

Get the subject from the service token

Returns: String - organization - The subject identifier set on the service token

ParamTypeDescription
requesthttp.IncomingMessage

getOrganization(request) ⇒ String

Get the subject's organization

Returns: String - organization - The organization the subject belongs to

ParamTypeDescription
requesthttp.IncomingMessage

getUnits(request) ⇒ Array.<String>

Get the subject's mapped units

Returns: Array.<String> - units - An array of all units the subject belongs to

ParamTypeDescription
requesthttp.IncomingMessage

getSelectedUnit(request) ⇒ null | String

Get the subject's selected unit

Returns: null | String - unit - The subject's selected unit, null if no unit selected

ParamTypeDescription
requesthttp.IncomingMessage

getOrgPermissions(request) ⇒ Array.<String>

Get the subject's organization permissions

Organization permissions are located under permissions.org

Returns: Array.<String> - } permissions - The subject's org permissions

ParamTypeDescription
requesthttp.IncomingMessage

getUnitPermissions(request, unit) ⇒ Array.<String>

Get the subject's permissions for the specified unit

Organization permissions are located under permissions.unitsunit

Returns: Array.<String> - } permissions - The subject's permissions for the specified unit

ParamTypeDescription
requesthttp.IncomingMessage
unitStringThe unit permissions should be checked in

isServiceAdmin(request) ⇒ Boolean

Checks if a token belogs to an admin for the service

Organization permissions are located under permissions.unitsunit

Returns: Boolean - isServiceAdmin - True if the token belongs to an admin for the service

ParamTypeDescription
requesthttp.IncomingMessage

getUserinfo(request) ⇒ Object

Get the subject's userinfo

Organization permissions are located under permissions.unitsunit

Returns: Object - userinfo - The userinfo object set on the subject

ParamTypeDescription
requesthttp.IncomingMessage
5.7.1

3 years ago

5.7.0

3 years ago

5.6.3

3 years ago

5.6.2

3 years ago

5.6.1

4 years ago

5.6.0

4 years ago

5.5.1

5 years ago

5.5.0

5 years ago

5.4.1

5 years ago

5.4.0

5 years ago

5.3.7

5 years ago

5.3.6

5 years ago

5.3.5

5 years ago

5.3.4

5 years ago

5.3.3

5 years ago

5.3.2

5 years ago

5.3.1

5 years ago

5.3.0

5 years ago

5.2.0

5 years ago

5.1.1

5 years ago

5.1.0

5 years ago

5.0.0

5 years ago

4.1.0

6 years ago

4.0.1

6 years ago

4.0.0

6 years ago

3.1.6

6 years ago

3.1.5

6 years ago

3.1.4

6 years ago

3.1.3

6 years ago

3.1.1

6 years ago

3.1.0

6 years ago

3.0.1

6 years ago

3.0.0

6 years ago

2.1.0

6 years ago

2.0.0

6 years ago

1.1.6

6 years ago

1.1.5

6 years ago

1.1.3

6 years ago

1.1.1

6 years ago

1.1.0

6 years ago

1.0.0

6 years ago

0.1.0

6 years ago

0.0.11

6 years ago

0.0.10

6 years ago

0.0.9

6 years ago

0.0.1

6 years ago