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

@notoofly/auth-server

v1.0.1

Published

Notoofly Auth Server - JWT verification and authorization middleware

Readme

@notoofly/auth-server

Production-ready JWT verification and authorization middleware for Node.js applications.

🚀 Features

  • JWT Verification: Secure token validation with JWKS caching
  • Framework Adapters: Native support for Express.js and Elysia
  • Authorization: Role-based and permission-based access control
  • Security: Race-safe fetching, input validation, error sanitization
  • Performance: In-memory caching with configurable TTL
  • TypeScript: Full type safety with strict typing

📦 Installation

npm install @notoofly/auth-server

🔧 Quick Start

Express.js Integration

import express from 'express';
import { createAuthMiddleware, createRoleGuard } from '@notoofly/auth-server/express';

const app = express();

// Configure authentication middleware
const authMiddleware = createAuthMiddleware({
  jwksUri: 'https://your-auth-domain.com/.well-known/jwks.json',
  issuer: 'https://your-auth-domain.com',
  audience: 'your-api',
  cacheTtl: 300000, // 5 minutes
});

// Apply authentication to routes
app.use('/api', authMiddleware);

// Protected route with role guard
app.get('/api/admin', createRoleGuard('admin'), (req, res) => {
  res.json({ message: 'Admin access granted' });
});

app.listen(3000);

Elysia Integration

import { Elysia } from 'elysia';
import { createAuthPlugin, createRoleGuard } from '@notoofly/auth-server/elysia';

const app = new Elysia()
  .use(createAuthPlugin({
    jwksUri: 'https://your-auth-domain.com/.well-known/jwks.json',
    issuer: 'https://your-auth-domain.com',
    audience: 'your-api',
  }))
  .guard(
    { role: 'admin' },
    ({ user }) => ({ message: `Hello admin ${user.email}` })
  )
  .listen(3000);

⚙️ Configuration

Environment Variables

Create a .env file based on .env.example:

# JWT Configuration
JWT_ISSUER=https://your-auth-domain.com
JWT_AUDIENCE=your-api-audience
JWKS_URI=https://your-auth-domain.com/.well-known/jwks.json
JWKS_CACHE_TTL=300000

# Security
NODE_ENV=production
LOG_LEVEL=info
ALLOWED_ORIGINS=https://yourdomain.com,https://app.yourdomain.com

# Rate Limiting
RATE_LIMIT_WINDOW_MS=60000
RATE_LIMIT_MAX_REQUESTS=100

Configuration Options

interface JwtVerificationConfig {
  jwksUri: string;           // JWKS endpoint URL
  issuer: string;            // Expected token issuer
  audience: string;          // Expected token audience
  cacheTtl?: number;        // Cache TTL in milliseconds (default: 300000)
}

🛡️ Security Features

Token Validation

  • Algorithm Support: RS256 and ES256
  • Claims Verification: iss, aud, exp, nbf
  • Key Validation: Kid matching and key rotation support

Caching Strategy

  • Race-Safe: Deduplicated concurrent requests
  • Memory Efficient: Automatic cleanup of expired keys
  • Configurable TTL: Default 5 minutes

Error Handling

  • Sanitized Messages: Production-safe error responses
  • Structured Logging: Consistent error format
  • Graceful Degradation: Fallback for JWKS unavailability

📚 API Reference

Core Classes

JwtVerifier

Main JWT verification class.

import { JwtVerifier } from '@notoofly/auth-server';

const verifier = new JwtVerifier({
  jwksUri: 'https://your-auth-domain.com/.well-known/jwks.json',
  issuer: 'https://your-auth-domain.com',
  audience: 'your-api',
});

// Verify access token
const user = await verifier.verifyAccessToken(token);

Methods

  • verifyAccessToken(token: string): Promise<AuthUser>
  • getUserFromToken(token: string): Promise<AuthUser>

Authorization Utilities

import {
  hasRole,
  hasPermission,
  hasAllRoles,
  hasAnyPermission,
  checkGuard
} from '@notoofly/auth-server';

Express Middleware

import {
  createAuthMiddleware,
  createRoleGuard,
  createPermissionGuard,
  createGuard
} from '@notoofly/auth-server/express';

Elysia Plugin

import {
  createAuthPlugin,
  createRoleGuard,
  createPermissionGuard,
  createGuard
} from '@notoofly/auth-server/elysia';

🔒 Best Practices

Production Deployment

  1. Environment Configuration

    NODE_ENV=production
    LOG_LEVEL=error
  2. Security Headers

    // Middleware automatically adds security headers
    app.use(helmet());
  3. Rate Limiting

    // Configure rate limiting
    const rateLimit = rateLimit({
      windowMs: 60000,
      max: 100
    });
  4. Monitoring

    // Add request logging
    app.use((req, res, next) => {
      console.log(`${req.method} ${req.path}`, { 
        ip: req.ip, 
        userAgent: req.get('User-Agent') 
      });
      next();
    });

Security Considerations

  • HTTPS Only: Always use HTTPS in production
  • CORS Configuration: Configure allowed origins properly
  • Key Rotation: Regularly rotate JWT signing keys
  • Token Expiration: Use short-lived access tokens
  • Error Messages: Don't expose sensitive information

🧪 Testing

# Run tests
npm test

# Run tests with coverage
npm run test:ci

# Type checking
npm run type-check

# Linting
npm run lint
npm run lint:fix

📈 Performance

Benchmarks

  • JWT Verification: <1ms average
  • JWKS Caching: 99% hit rate
  • Memory Usage: <10MB for 1000 cached keys
  • Concurrent Requests: No race conditions

Optimization Tips

  1. Cache TTL: Balance between freshness and performance
  2. Connection Pooling: Reuse HTTP connections
  3. Memory Monitoring: Monitor cache size
  4. Load Balancing: Distribute across multiple instances

🔄 Migration

From v0.x to v1.0

Breaking changes:

  • Package renamed to @notoofly/auth-server
  • TypeScript exports now use .js extensions
  • Configuration options updated

Migration Steps

  1. Update package.json:

    {
      "dependencies": {
        "@notoofly/auth-server": "^1.0.0"
      }
    }
  2. Update imports:

    // Before
    import { JwtVerifier } from 'auth-server';
       
    // After
    import { JwtVerifier } from '@notoofly/auth-server';
  3. Update configuration:

    // Review configuration options for changes

🤝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests
  5. Run npm run test:ci
  6. Submit a pull request

📄 License

MIT License – see LICENSE file for details.

🆘 Support