npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@infomaker/service-authorization-lib

v5.7.1

Published

IMID Service Authorization Library

Downloads

31

Readme

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

| Param | Type | Description | | --- | --- | --- | | request | http.IncomingMessage | |

extractImidTokenFromRequest(request) ⇒ String | null

Extracts IMID token from a raw request if present

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

| Param | Type | | --- | --- | | request | http.IncomingMessage |

getSubject(request) ⇒ String

Get the subject from the service token

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

| Param | Type | Description | | --- | --- | --- | | request | http.IncomingMessage | |

getOrganization(request) ⇒ String

Get the subject's organization

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

| Param | Type | Description | | --- | --- | --- | | request | http.IncomingMessage | |

getUnits(request) ⇒ Array.<String>

Get the subject's mapped units

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

| Param | Type | Description | | --- | --- | --- | | request | http.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

| Param | Type | Description | | --- | --- | --- | | request | http.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

| Param | Type | Description | | --- | --- | --- | | request | http.IncomingMessage | |

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

Get the subject's permissions for the specified unit

Organization permissions are located under permissions.units[unit]

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

| Param | Type | Description | | --- | --- | --- | | request | http.IncomingMessage | | | unit | String | The 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.units[unit]

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

| Param | Type | Description | | --- | --- | --- | | request | http.IncomingMessage | |

getUserinfo(request) ⇒ Object

Get the subject's userinfo

Organization permissions are located under permissions.units[unit]

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

| Param | Type | Description | | --- | --- | --- | | request | http.IncomingMessage | |