@verimatrix/token-generation-middleware
v1.2.0
Published
Token Generation Middleware
Downloads
31
Readme
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({ ... }));