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

@byu-oit-sdk/fastify-jwt

v0.1.2

Published

Fastify plugin for verifying JWTs in fastify server requests

Downloads

574

Readme

@byu-oit-sdk/jwt-fastify

Requirements:

  • Node.js 18+
  • npm v9+

Installing

npm install @byu-oit-sdk/jwt-fastify

Introduction

This fastify middleware allows for verification and decoding of JWTs.

Options

Along with the options for the CreateJwt() function (see docs for jwt package), the following options can be passed in when registering the middleware with fastify.

| Option | Type | Default | Description | |-------------------|---------------------------------------------|---------|--------------------------------------------------------------------------------------------------------------------| | prefix | string | - | Used to specify what route the middleware is registered with. | | transformer | JwtPayloadTransformer<Payload, Transformer> | - | The function that you will use for manipulating the JWT you are authenticating. | | getJwt | function | - | A function for getting the JWT from the request. By default, the JWT is pulled from the auth header. | | validate | boolean | - | Boolean used to signify if we want to validate the jwt if true, or just decode it if false. |

Usage

import Fastify from 'fastify'
import { FastifyJwtProvider } from '@byu-oit-sdk/jwt-fastify'
import { Type } from '@sinclair/typebox'

// set up fastify server
const app = Fastify({
  logger: true
})

// declare transformer
const transformer = (payload: { 'http://byu.edu/claims/client_preferred_first_name': string }): { preferred_first_name: string } => ({ preferred_first_name: payload['http://byu.edu/claims/client_preferred_first_name'] })

// register the middleware with Fastify
await app.register(FastifyJwtProvider, { schema: Type.Object({ }, { additionalProperties: true }), key: '', validate: false, transformer })

// declare endpoint
app.get('/', async (request, reply) => {
  return request.caller
})

// send a request
const response = await app.inject({
  method: 'GET',
  url: '/',
  headers: {
    Authorization: /* A valid token */
  }
})

console.log(response)