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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@saurbit/oauth2-jwt

v0.1.1

Published

JWT utilities for @saurbit/oauth2 (jose-based)

Downloads

217

Readme

@saurbit/oauth2-jwt

JWT utilities and JWKS authority for @saurbit/oauth2. Wraps jose to provide ready-made implementations of the JWT-related interfaces required by @saurbit/oauth2.

📖 Documentation

Installation

Node.js / Bun

npm install @saurbit/oauth2-jwt
# or
yarn add @saurbit/oauth2-jwt
# or
pnpm add @saurbit/oauth2-jwt
# or
bun add @saurbit/oauth2-jwt

Deno / JSR

deno add jsr:@saurbit/oauth2-jwt

JWT Utilities

@saurbit/oauth2-jwt provides three ready-made functions that satisfy the JwtVerify, JwtDecode, and JwkVerify interfaces expected by @saurbit/oauth2.

verifyJwt and decodeJwt

Used by the ClientSecretJwt and PrivateKeyJwt client authentication methods.

ClientSecretJwt

import { ClientSecretJwt } from "@saurbit/oauth2";
import { decodeJwt, verifyJwt } from "@saurbit/oauth2-jwt";

const clientSecretJwt = new ClientSecretJwt(decodeJwt, verifyJwt);

PrivateKeyJwt

import { PrivateKeyJwt } from "@saurbit/oauth2";
import { decodeJwt, verifyJwt } from "@saurbit/oauth2-jwt";

const privateKeyJwt = new PrivateKeyJwt(decodeJwt, verifyJwt);

verifyJwk

Used by DPoPTokenType for Demonstration of Proof-of-Possession token validation.

import { createInMemoryReplayStore, DPoPTokenType } from "@saurbit/oauth2";
import { verifyJwk } from "@saurbit/oauth2-jwt";

const dpop = new DPoPTokenType(verifyJwk, createInMemoryReplayStore());

JWKS Authority

JoseJwksAuthority manages RS256 signing key pairs, signs and verifies JWTs, and returns the JWKS endpoint payload. Keys are stored in a JwksKeyStore and generated automatically on first use.

Setup

import { createInMemoryKeyStore, JoseJwksAuthority } from "@saurbit/oauth2-jwt";

const store = createInMemoryKeyStore();
const authority = new JoseJwksAuthority(store, 8.64e+6); // public keys valid for 100 days

Sign a JWT

const { token } = await authority.sign({
  sub: "user-123",
  iss: "https://auth.example.com",
  aud: "my-client",
  iat: Math.floor(Date.now() / 1000),
  exp: Math.floor(Date.now() / 1000) + 3600,
  jti: crypto.randomUUID(),
});

Verify a JWT

const payload = await authority.verify(token);
console.log(payload.sub); // "user-123"

JWKS endpoint

getJwksEndpointResponse() returns the set of current public keys in JWKS format, ready to be served at a well-known endpoint (e.g. /.well-known/jwks.json).

// Example with Hono
app.get("/jwks", async (c) => {
  return c.json(await authority.getJwksEndpointResponse());
});

The response has the shape { keys: RawKey[] } and is safe to return directly as JSON.

Key Rotation

JwksRotator manages scheduled key rotation. It compares the current time against the last rotation timestamp and generates a new key pair only when the configured interval has elapsed.

Call checkAndRotateKeys() at service startup and/or on a recurring schedule (e.g. every hour). If a rotation is due a new key pair is generated; otherwise the call is a no-op. During rotation the previous public key remains available in the JWKS until its TTL expires, so in-flight tokens continue to verify correctly.

Setup

import { createInMemoryKeyStore, JoseJwksAuthority, JwksRotator } from "@saurbit/oauth2-jwt";

const store = createInMemoryKeyStore();
const authority = new JoseJwksAuthority(store, 8.64e+6); // 100 days key TTL

const rotator = new JwksRotator({
  keyGenerator: authority,
  rotatorKeyStore: store,
  rotationIntervalMs: 7.884e9, // 91 days
});

Usage

// At startup
await rotator.checkAndRotateKeys();

// Or on a recurring schedule
setInterval(async () => {
  await rotator.checkAndRotateKeys();
}, 60 * 60 * 1000); // every hour

License

MIT