@verimatrix/token-generation-middleware
TypeScript icon, indicating that this package has built-in type declarations

1.2.0 • Public • Published

token-generation-middleware

An express middleware that generates and includes a JWT token in the response.

Usage

Install the middleware plugin in your NPM project with npm or yarn:

  • npm install --save @verimatrix/token-generation-middleware
  • yarn add @verimatrix/token-generation-middleware

Import and use in your express app:

import express from "express";
import tokenGenerator from "@verimatrix/token-generation-middleware";

const app = express.app();

app.use(
  tokenGenerator({
    privateKey: "***",
    operator: {
      audience: "myAudience",
      issuer: "myIssuer",
      keyId: "myKeyId",
    },
    expiresIn: 30,
  })
);

Then, send a request to your express app:

curl "http://localhost:8080/token?subject=foo"

POST Request Support

The middleware supports generating tokens with GET or POST requests, but to allow the middleware to access data in the POST request bodies, you must enable JSON body parsing in the express app first.

import express from "express";
import tokenGenerator from "@verimatrix/token-generation-middleware";

const app = express.app();

// enable JSON body parsing
app.use(express.json());

app.use(tokenGenerator({ ... }));

Readme

Keywords

none

Package Sidebar

Install

npm i @verimatrix/token-generation-middleware

Weekly Downloads

0

Version

1.2.0

License

ISC

Unpacked Size

30.4 kB

Total Files

12

Last publish

Collaborators

  • vmx-service-account
  • danielcarrami