0.0.1 • Published 2 years ago

symblight-node-oauth2-jwt-bearer v0.0.1

Weekly downloads
-
License
ISC
Repository
github
Last release
2 years ago

Getting started

Requirements

This package supports the following tooling versions:

  • Node.js: ^12.19.0 || ^14.15.0 || ^16.13.0 || ^18.12.0

Installation

Using npm in your project directory run the following command:

npm install symblight-fastify-oauth2-jwt

Getting started

Environment Variables

ISSUER_BASE_URL=https://YOUR_ISSUER_DOMAIN
AUDIENCE=https://my-api.com
const { fastifyOauth2 } = require("symblight-fastify-oauth2-jwt");
app.register(fastifyOauth2, {
  audience: "",
  issuerBaseURL: ``,
  jwksUri: "",
  algorithms: ["RS256"],
});
const checkJwt = async (req, reply) => {
  const jwt = app.Oauth2.getToken(
    req.headers,
    req.query,
    req.body,
    !!reply.header("Content-type", "urlencoded")
  );
  return await app.Oauth2.verifyJwt(jwt);
};

app.get("/", async function (request, reply) {
  request.auth = await checkJwt(request, reply);
  return reply
    .status(200)
    .header("Content-Type", "application/json; charset=utf-8")
    .send(request.auth?.payload);
});
0.0.1

2 years ago