0.1.3 • Published 10 days ago

@byu-oit-sdk/fastify-jwt v0.1.3

Weekly downloads
-
License
Apache-2.0
Repository
github
Last release
10 days ago

@byu-oit-sdk/fastify-jwt

Requirements:

  • Node.js 18+
  • npm v9+

Installing

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

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.

OptionTypeDefaultDescription
prefixstring-Used to specify what route the middleware is registered with.
transformerJwtPayloadTransformer<Payload, Transformer>-The function that you will use for manipulating the JWT you are authenticating.
getJwtfunction-A function for getting the JWT from the request. By default, the JWT is pulled from the auth header.
validateboolean-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)
0.1.3

10 days ago

0.1.2-beta.0

2 months ago

0.1.2

2 months ago

0.1.1-beta.5

2 months ago

0.1.1-beta.4

3 months ago

0.1.1

3 months ago

0.1.1-beta.3

4 months ago

0.1.1-beta.2

4 months ago

0.1.1-beta.1

4 months ago

0.1.1-beta.0

8 months ago

0.1.0

8 months ago

0.1.0-beta.8

8 months ago

0.1.0-beta.7

8 months ago

0.1.0-beta.6

9 months ago

0.1.0-beta.5

9 months ago

0.1.0-beta.4

9 months ago

0.1.0-beta.3

9 months ago

0.1.0-beta.2

9 months ago

0.1.0-beta.1

9 months ago

0.1.0-beta.0

9 months ago