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

@idirdev/auth-fortress

v1.0.0

Published

Authentication and authorization library with JWT, API keys, rate limiting, and RBAC

Readme

auth-fortress

[EN] All-in-one authentication middleware for Node.js — JWT, API keys, rate limiting, RBAC and session management in a single composable class. [FR] Middleware d'authentification tout-en-un pour Node.js — JWT, clés API, limitation de débit, RBAC et gestion de sessions dans une seule classe composable.


Features / Fonctionnalités

[EN]

  • JWT token generation, verification and auto-expiry (HS256/RS256)
  • API key validation with key store lookup
  • Built-in rate limiter: per-IP sliding window, configurable limits
  • Role-Based Access Control (RBAC) — attach roles to users, guard routes
  • Session manager with configurable TTL and store backends
  • Single middleware() call handles auth + rate-limit + RBAC in one pass
  • Returns structured JSON errors (401 / 403 / 429) with machine-readable codes
  • Zero production dependencies beyond your existing runtime

[FR]

  • Génération, vérification et expiration automatique des tokens JWT (HS256/RS256)
  • Validation des clés API avec consultation du magasin de clés
  • Limiteur de débit intégré : fenêtre glissante par IP, limites configurables
  • Contrôle d'accès basé sur les rôles (RBAC) — attachez des rôles aux utilisateurs, protégez les routes
  • Gestionnaire de sessions avec TTL configurable et backends de stockage
  • Un seul appel middleware() gère auth + rate-limit + RBAC en une passe
  • Renvoie des erreurs JSON structurées (401 / 403 / 429) avec codes lisibles par machine
  • Aucune dépendance de production au-delà de votre runtime existant

Installation

npm install @idirdev/auth-fortress

API (Programmatic) / API (Programmation)

const { AuthFortress, JwtAuth, ApiKeyAuth, RateLimiter, RBAC, SessionManager } = require('@idirdev/auth-fortress');

// Full setup
const auth = new AuthFortress({
  jwt: { secret: process.env.JWT_SECRET, expiresIn: '15m' },
  apiKeys: { keys: ['key-abc123', 'key-xyz789'] },
  rateLimit: { max: 100, windowMs: 60000 },  // 100 req/min per IP
  roles: {
    admin:  ['read', 'write', 'delete'],
    editor: ['read', 'write'],
    viewer: ['read'],
  },
  sessions: { ttl: 3600, store: 'memory' },
});

// Attach as Express/Node middleware
app.use(auth.middleware({ required: true }));

// Protect a route — only admins and editors
app.delete('/articles/:id', auth.middleware({ roles: ['admin', 'editor'] }), handler);

// JWT only — generate a token
const jwt = new JwtAuth({ secret: 'mysecret', expiresIn: '1h' });
const token = jwt.sign({ userId: 42, role: 'editor' });
const payload = jwt.verify(token); // { userId: 42, role: 'editor', iat, exp }

// API key only
const apiKey = new ApiKeyAuth({ keys: ['k1', 'k2'] });
const user = apiKey.validate('k1'); // returns associated user object or null

// Standalone rate limiter
const limiter = new RateLimiter({ max: 60, windowMs: 60000 });
if (!limiter.check('192.168.1.1')) {
  // too many requests
}

// RBAC check
const rbac = new RBAC({ admin: ['read','write'], viewer: ['read'] });
rbac.hasAnyRole('admin', ['admin', 'editor']); // true

Error responses / Réponses d'erreur

// 401 — no token / invalid token
{ "error": "Authentication required" }
{ "error": "Token expired", "code": "TOKEN_EXPIRED" }

// 403 — insufficient role
{ "error": "Insufficient permissions" }

// 429 — rate limit exceeded
{ "error": "Too many requests" }

License

MIT — idirdev