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

@forgedevstack/forge-auth

v2.0.1

Published

Node auth toolkit: HMAC sessions, refresh/rotation, Harbor middleware, cookies, API keys, scrypt, OIDC helpers.

Downloads

164

Readme

@forgedevstack/forge-auth

Node.js auth toolkit with zero runtime dependencies — everything is built on node:crypto. Part of the ForgeStack ecosystem and designed to plug into @forgedevstack/harbor or any HTTP framework.

Not AuthMaster. This package is server-side only (sessions, API keys, scrypt, OIDC helpers, Harbor middleware). The React OAuth UI formerly associated with “AuthMaster” is a different product and should not be published under @forgedevstack/forge-auth. Recommended future npm name: @forgedevstack/auth-master.

  • HMAC-SHA256 signed session tokens with TTL
  • Refresh tokens + rotation (createSessionPair / rotateSessionPair)
  • Cookie serialize/parse helpers and Harbor cookie session middleware
  • Harbor middleware wrappers for bearer session and API key auth
  • scrypt password hashing with self-describing hash strings
  • API key generation and SHA-256 hash verification
  • OIDC authorization-code helpers with PKCE (S256) + refresh grant body helper
  • Framework-agnostic guards over a minimal { headers } request shape

Install

npm install @forgedevstack/forge-auth

Current version: 2.0.1

Quick Example

Session plus Harbor middleware:

import {
  createSessionPair,
  createHarborSessionMiddleware,
  setSessionCookie,
  setRefreshCookie,
} from '@forgedevstack/forge-auth';

const secret = process.env.SESSION_SECRET!;

app.post('/login', (req, res) => {
  const pair = createSessionPair({
    secret,
    accessPayload: { userId: 'user-1', role: 'admin' },
  });
  setSessionCookie(res, pair.accessToken, { httpOnly: true, sameSite: 'Lax' });
  setRefreshCookie(res, pair.refreshToken, { httpOnly: true, sameSite: 'Lax' });
  res.json({ ok: true });
});

app.use(createHarborSessionMiddleware({ secret }));

app.get('/profile', (req, res) => {
  res.json({ userId: req.forgeSession?.payload.userId });
});

Cookie-based session (no Authorization header):

import { createHarborCookieSessionMiddleware } from '@forgedevstack/forge-auth';

app.use(createHarborCookieSessionMiddleware({ secret }));

API Overview

Sessions

  • createSession(payload, secret, options?) — compact token: base64url(claims) + '.' + base64url(hmac). Default TTL 3600s.
  • verifySession(token, secret){ valid: true, claims } or { valid: false, reason }.

Refresh / rotation

  • createRefreshToken(payload, secret, options?) — long-lived refresh token (tokenType: 'refresh', random jti). Default TTL 7 days.
  • verifyRefreshToken(token, secret) — validates signature, expiry, and refresh shape.
  • createSessionPair({ secret, accessPayload, ... }) — access + refresh pair.
  • rotateSessionPair({ secret, refreshToken, accessPayload, ... }) — verifies refresh and issues a new pair (rotation).

Cookies

  • parseCookieHeader(header) / serializeCookie(name, value, options?) / clearCookie(name, options?)
  • setSessionCookie / setRefreshCookie / clearSessionCookie / clearRefreshCookie / readCookieValue for Harbor-style responses

Harbor middleware

  • createHarborSessionMiddleware({ secret }) — bearer session → req.forgeSession
  • createHarborApiKeyMiddleware({ hashes }) — API key → req.forgeApiKey
  • createHarborCookieSessionMiddleware({ secret }) — HttpOnly cookie session → req.forgeSession

Passwords

  • hashPassword(password, options?) / verifyPassword(password, stored)

API Keys

  • generateApiKey() / hashApiKey(key) / verifyApiKey(key, hash)

OIDC

  • generateState() / generatePkcePair()
  • buildAuthorizationUrl(config, params)
  • buildTokenRequestBody(config, params) — authorization_code grant
  • buildRefreshTokenRequestBody(config, params) — refresh_token grant

Full Harbor + OIDC walkthrough: docs/oidc-flow.md

Guards

  • extractBearerToken(request, headerName?)
  • createSessionGuard(options) / createApiKeyGuard(options)

Guards are plain functions of { headers } returning { authorized: true, context } or { authorized: false, reason }.

Security Notes

  • Session tokens are signed with HMAC-SHA256; payloads are encoded, not encrypted — do not put secrets in the payload.
  • Refresh tokens include a jti; rotate on use and invalidate previous jti values in your store when you need server-side revocation.
  • Password hashing uses scrypt; comparisons use crypto.timingSafeEqual.
  • Prefer HttpOnly + Secure + SameSite=Lax (or Strict) for session cookies.

Related packages

| Package | Role | |---|---| | @forgedevstack/forge-auth (this) | Node auth toolkit | | @forgedevstack/auth-master (recommended name) | React OAuth UI (AuthMaster) — separate product, not this package | | @forgedevstack/harbor | Backend framework these middleware helpers target |

License

MIT — part of the ForgeStack family of libraries.