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

haechi-auth-jwt

v0.2.1

Published

Headless JWKS bearer (JWT) authProvider satellite for Haechi — node: builtins only, PII-safe identity.

Readme

haechi-auth-jwt

A headless JWKS bearer (JWT) authProvider for Haechi. It verifies an Authorization: Bearer <jwt> against an issuer's JWKS and resolves a PII-safe identity — using node: builtins only (no jose). Published independently as haechi-auth-jwt; it adds no runtime dependency to core.

Usage

import { createRuntime } from "haechi/runtime";
import { createJwtAuthProvider } from "haechi-auth-jwt";

const runtime = createRuntime(
  { auth: { provider: "external" }, /* ... */ },
  {
    cryptoProvider, // required (also satisfies the PII-safe identity hmac)
    authProvider: createJwtAuthProvider({
      issuer: "https://idp.example.com",
      audience: "haechi-gateway",
      jwksUri: "https://idp.example.com/.well-known/jwks.json",
      cryptoProvider,
      algorithms: ["RS256", "ES256"],     // server-side allowlist (default)
      clockSkewSeconds: 60,                // max 300
      claimMappings: { scope: "scp", labels: { team: "groups" } }
    })
  }
);

Wired via injection (auth.provider: "external"); dynamic loading stays banned until the 1.0 plugin sandbox.

Security (these are guarantees, not options)

  • The token never picks the algorithm. The verifier uses the configured algorithms allowlist and the JWK type. alg: "none" is rejected; HMAC (HS*) is not allowed (alg-confusion defence); a JWKS public key is only ever used with its matching asymmetric algorithm. ES256 uses dsaEncoding: "ieee-p1363" (a JWS ES256 signature is raw R‖S, which node:crypto otherwise mis-verifies).
  • kid required, key selected by kid. RSA ≥ 2048 bits. JWK use must be sig; key_ops must not include encrypt/decrypt. Only JWS is accepted (typ: "JWE" rejected).
  • Claims fully validated: iss exact match; aud (string or array) must contain the configured audience; sub required non-empty; exp/nbf required and checked with a bounded clockSkewSeconds (default 60, max 300).
  • JWKS fetching is SSRF-hardened: issuer and jwksUri must be HTTPS and share a host (single-origin issuers only in 0.8); requests to private/loopback/link-local/metadata addresses are refused (literal host + resolved IPs); fetch has a timeout and a 1 MiB response cap; JSON parsing is depth-bounded; JWT segments are strict base64url.
  • JWKS cache is bounded: TTL-cached; an unknown kid triggers at most one refetch per cooldown (no fetch-storm against the IdP).
  • Identity is PII-safe (fail-closed): a cryptoProvider with hmac() is required; subjectHash/issuerHash are keyed HMAC-SHA-256 (haechi:identity:hash:v1, built by core's buildExternalIdentity) — raw sub/iss are never stored or logged. scopes from the configured scope claim; labels from an allowlisted claim mapping.
  • Fail-closed everywhere: any verification error → authenticate returns null (deny), never throws into the request path, and echoes no token detail.

createJwtVerifier (the reusable primitive)

createJwtVerifier(options) is the standalone, audited JWS/JWKS verification path that createJwtAuthProvider is built on. It takes the verification-only options (issuer, audience, jwksUri, algorithms, clockSkewSeconds, JWKS cache/fetch knobs, now) — no cryptoProvider, claimMappings, or allowedLabelKeys (those stay in the provider) — and returns { verify }:

const verifier = createJwtVerifier({ issuer, audience, jwksUri /* ... */ });
const claims = await verifier.verify(jwt);            // validated claims object, or null
const claims2 = await verifier.verify(jwt, { expectedNonce }); // + OIDC nonce check

verify(jwt) does exactly the 0.8 bearer work — signature + alg/kid/RSA-bits + iss/aud/exp/nbf — and returns the validated claims object (not an identity) or null on any failure (fully fail-closed). nonce is not part of the bearer surface: it is checked only when expectedNonce is passed, and is a no-op when omitted. This is the single verification path reused by the haechi-auth-oidc broker (0.9).

Scope (0.8)

Single-origin issuers only (issuer host == JWKS host). Multi-origin/CDN-fronted JWKS and full interactive OIDC (haechi-auth-oidc) are 0.9.