1.3.0 • Published 6 months ago

@verimatrix/token-generation-middleware v1.3.0

Weekly downloads
-
License
ISC
Repository
github
Last release
6 months ago

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({ ... }));

Available middleware

The default export is tokenGenerator middleware, documented above. There are other middleware available:

  • tokenGenerator - adds generated token to response body
  • authorizeRequest - adds generated token to request Authorization header

Example using authorizeRequest:

import express from "express";
import { authorizeRequest } from "@verimatrix/token-generation-middleware";

const app = express.app();

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

6 months ago

1.2.0

2 years ago

1.1.0

2 years ago

1.2.0-beta.5

2 years ago

1.2.0-beta.4

2 years ago

1.0.12

2 years ago

1.0.11

3 years ago

1.0.10

3 years ago

1.0.9

3 years ago

1.0.8

3 years ago

1.0.7

3 years ago

1.0.6

3 years ago

1.0.5

3 years ago

1.0.4

3 years ago

1.0.2

3 years ago

1.0.1

3 years ago