# @byu-oit-sdk/jwt

> JSON Web Token validation for the BYU OIT SDK

Latest version **0.4.0** (published 2026-04-29) · Apache-2.0 license · 0 weekly downloads

## Install

```sh
npm install @byu-oit-sdk/jwt
pnpm add @byu-oit-sdk/jwt
yarn add @byu-oit-sdk/jwt
bun add @byu-oit-sdk/jwt
```

## Health

**Score 60/100 (C)** — status: active.

Positive: has types; esm support; no vulnerabilities; high quality score.

Warnings: low downloads; pre 1.0.

## Facts

| | |
|---|---|
| Version | 0.4.0 |
| Published | 2026-04-29 |
| First published | 2023-08-23 |
| Weekly downloads | 0 |
| License | Apache-2.0 |
| TypeScript types | bundled |
| Module format | ESM + CommonJS |
| Node | >=22 |
| Dependencies | 3 |
| Unpacked size | 73.7 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| Author | Spencer Tuft |
| Maintainers | stuft2, byu-oit-bot |

## Links

- npm: https://www.npmjs.com/package/@byu-oit-sdk/jwt
- Repository: https://github.com/byu-oit-sdk/javascript
- Homepage: https://github.com/byu-oit-sdk/javascript#readme
- Issues: https://github.com/byu-oit-sdk/javascript/issues
- npm.io page: https://npm.io/package/@byu-oit-sdk/jwt

## Dependencies (3)

- [jose](https://npm.io/package/jose.md) ^6.1.0
- [tslib](https://npm.io/package/tslib.md) ^2.5.0
- [@byu-oit-sdk/credential-provider](https://npm.io/package/@byu-oit-sdk/credential-provider.md) ^0.20.0

## Recent versions

- 0.4.0 (latest) — 2026-04-29
- 0.3.1 — 2026-04-07
- 0.3.0 — 2026-04-06
- 0.2.0 — 2025-07-22
- 0.1.22 — 2025-05-01
- 0.1.21 — 2025-04-01
- 0.1.20 — 2025-03-18
- 0.1.19 — 2025-03-12
- 0.1.18 — 2025-02-20
- 0.1.17 — 2025-02-19
- 0.1.16 — 2025-01-22
- 0.1.15 — 2025-01-21
- 0.1.14 — 2024-11-14
- 0.1.13 — 2024-10-29
- 0.1.12 — 2024-10-11
- … 27 more at https://npm.io/package/@byu-oit-sdk/jwt/versions

## README

# @byu-oit-sdk/jwt

**Requirements**:

- Node.js 18+
- npm v9+

## Installing

In addition to installing this module, you can install either the Jwt plugin for Fastify or for Express
depending on what you're using.

```shell
npm install @byu-oit-sdk/jwt
```

## Introduction

Use this module for verification and decoding of JWTs. Can be used in conjunction with the express and fastify plugins.

The current implementation uses `jose` internally for JWT verification and JWK handling.

This package exports the following:

- `Jwk` - A class for verifying Jwks.
- `RsaJwk` - A class for verifying RSA JWKs. Extension of the `Jwk` class.
- `JwkSet` - A class which handles construction, validation, and loading of Jwk Sets.
- `createJwt()` - A function that returns a class with methods for verifying and decoding JWTs.

## Options

> The following options can be passed in to the CreateJwt() function.

| Option                | Type               | Default         | Description                                                                                                        |
|-----------------------|--------------------|-----------------|--------------------------------------------------------------------------------------------------------------------|
| Schema                | Object             | REQUIRED OPTION | The schema of the payload of the JWT that you are creating.                                                        |
| transformer           | function           | -               | The function that you will use for manipulating the JWT you are authenticating.                                    |
| additionalValidations | array of functions | -               | An optional array of functions that will also be used to validate the JWT.                                         |
| key                   | string             | REQUIRED OPTION | This is required but can be an empty string.                                                                       |
| discoveryEndpoint     | string             | -               | The redirection endpoint that the authorization server should redirect to after authenticating the resource owner. |
| issuer                | string             | -               | Used to configure where the user will be sent to sign in.                                                          |

## Usage

<details>
<summary>TypeScript Coding Example</summary>


```typescript
import { createJwt, Jwt, type JwtData } from '../src/Jwt.js'
import { type Static, Type } from '@sinclair/typebox'

const sampleJwtData = {
  header: {
    alg: 'HS256',
    typ: 'JWT'
  },
  payload: {
    id: 'some id',
    name: 'some Name'
  },
  signature: 'some signature'
}

const UserSchema = Type.Object({
  id: Type.String(),
  name: Type.String()
})

const TransformedJwtPayload = Type.Object({
  userId: Type.String(),
  userName: Type.String()
})

const jwtData: JwtData<Static<typeof UserSchema>> = {
  header: { alg: 'HS256', typ: 'JWT', kid: 'testKid' },
  payload: { id: '1', name: 'Alice' },
  signature: 'sample_signature'
}

const payloadTransformer = (payload: typeof UserSchema): Static<typeof TransformedJwtPayload> => {
  const userId = payload.id
  const userName = payload.name
  return {
    userId,
    userName
  }
}

const instance = new Jwt(jwtData, { transformer: payloadTransformer })

const CustomJwt = createJwt({
  schema: UserSchema,
  key: ''
})


```

</details>

---
_Source: https://npm.io/package/@byu-oit-sdk/jwt · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
