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

@opuscapita/useridentity-middleware

v4.1.1

Published

Express middleware to access identity token (jwt) data of a logged-in user

Downloads

1,410

Readme

OpusCapita UserIdentity Middlware

This module defines an express middleware providing read access to the encrypted identity token (jwt) of a user as used in OpusCapita Business Network.

Using UserIdentity Middlware

  • In order to use UserIdentity Middlware in your project, you can either use it directly as an express middleware or through @opuscapita/web-init.
  • For using UserIdentity Middlware directly via API, please have a look at the API documentation wiki.

For using it with express, simply do the following:

const UserIdentity = require('@opuscapita/useridentity-middleware');

const userIdentity = new UserIdentity();
const app = express();

app.use(userIdentity.middleware());

Access the data

As this middleware is intended to be used with web-init, it extends the req.opuscapita namespace adding several methods and properties.

Methods:

  • req.opuscapita.userData(key = null) : object
  • req.opuscapita.getTenantId() : string
  • req.opuscapita.isSupplier(tenantId) : bool
  • req.opuscapita.isCustomer(tenantId) : bool
  • req.opuscapita.getSupplierId(tenantId) : string
  • req.opuscapita.getCustomerId(tenantId) : string
  • req.opuscapita.splitTenant(tenantId) : object
  • req.opuscapita.customerIdToTenantId(supplierId = null) : string
  • req.opuscapita.supplierIdToTenantId(customerId = null) : string

Properties:

  • req.opuscapita.isAuthenticated

The method req.opuscapita.userData(key) can either be called with or without a key. If no key is passed, the whole user-data object is returned. If a key is present (can also be camel case e.g. supplierId) only the value of the key is returned. If the key was not found, the result will be null.

The special req.opuscapita.splitTenant(tenantId) tries to find out whenever the passed tenantId is a supplier or a customer ID and returns an object containing the properties supplierId and customerId. If the passed tenantId is valid, one of the properties will be filled and the other will be null. If the passed tenantId is invalid or empty, both properties will be null.

If the no identity token was present, could not be decrypted or an error occurred, the requesting client will get an HTTP 403 response.

Example user-data

{
    "sub": "[email protected]",
    "id": "[email protected]",
    "email": "[email protected]",
    "phoneno": "+4912345678",
    "supplierid": "mySupplier",
    "customerid": "",
    "status": "firstLogin",
    "maychangesupplier": false,
    "maychangecustomer": false,
    "languageid": "en",
    "firstname": "John",
    "lastname": "Doe",
    "mustbechanged": "",
    "roles": ["supplier-admin", "user"],
    "nonce": "b946536ab2313b11489c6c1d1f78b5da",
    "at_hash": "Yh_Rdj-erYaD0N0zhP1PBA",
    "rt_hash": "uQLs-2iM0zcxeMIcMKbXRA",
    "sid": "162fc78b-ea7e-4816-ae12-dfcef38ee9c6",
    "iat": 1515160784,
    "exp": 1515167984,
    "aud": "oidcCLIENT",
    "iss": "https://some-address.com"
}

Default configuration

{
    noLogEndpoints : [ '^/api/list/apis$', '^/api/health/check$' ],
    cache : new Cache({ defaultExpire : 3600 }),
    serviceClient : new ServiceClient()
}

Migration notes

v3 to v4

  • Due to changes in jsonwebtoken library
    • Removed support for Node versions 11 and below.
    • The verify() function no longer accepts unsigned tokens by default.
    • RSA key size must be 2048 bits or greater.
    • Asymmetric keys cannot be used to sign & verify HMAC tokens.
    • Key types must be valid for the signing / verification algorithm
    • see https://github.com/auth0/node-jsonwebtoken/wiki/Migration-Notes:-v8-to-v9