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

@bliv/authentication

v0.0.8

Published

Authentication middleware for Express applications

Downloads

97

Readme

@bliv/authentication

A TypeScript-based authentication middleware library for Express applications, providing JWT verification and authentication functionality.

Features

  • Full TypeScript support with built-in type definitions
  • JWT verification with JWKS (JSON Web Key Set) support
  • Express middleware for authentication
  • Configurable path exclusions
  • Rate limiting for JWKS requests
  • Customizable audience and issuer validation
  • Error handling middleware

Installation

npm install @bliv/authentication

Usage with TypeScript

Basic Setup

import express from 'express';
import { middleware, JwtVerifyConfig, AuthRequest } from '@bliv/authentication';

const app = express();

// Configure the authentication middleware
const config: JwtVerifyConfig = {
  JWKSURL: 'https://your-jwks-url.com/.well-known/jwks.json',
  AUDIENCE: 'your-audience',
  ISSUER: 'your-issuer',
  IGNORE_PATHS: ['/public', '/health'],
  CREDENTIALS_REQUIRED: true
};

// Use the middleware
app.use(middleware(config));

// Type-safe request handling
app.get('/protected', (req: AuthRequest, res) => {
  // TypeScript knows about req.auth
  const userId = req.auth?.userId;
  
  if (!userId) {
    return res.status(401).json({ error: 'User not authenticated' });
  }
  
  res.json({ userId, message: 'Protected resource accessed successfully' });
});

Configuration Options

interface JwtVerifyConfig {
  // Required: URL to fetch JWKS (JSON Web Key Set)
  JWKSURL: string;
  
  // Optional: Expected audience for the JWT (default: "platform")
  AUDIENCE?: string;
  
  // Optional: Expected issuer for the JWT
  ISSUER?: string;
  
  // Optional: Whether to require authentication (default: true)
  CREDENTIALS_REQUIRED?: boolean;
  
  // Optional: Array of paths to exclude from authentication
  IGNORE_PATHS?: string[];
}

Type Definitions

The package includes TypeScript definitions for enhanced type safety:

// Request with authentication data
interface AuthRequest extends Request {
  auth?: AuthPayload;
  headers: {
    "x-coreplatform-correlationid"?: string;
    [key: string]: string | string[] | undefined;
  };
}

// Authentication payload
interface AuthPayload {
  userId?: string;
  [key: string]: any;
}

Error Handling

import { ErrorRequestHandler } from 'express';
import { AuthRequest } from '@bliv/authentication';

const errorHandler: ErrorRequestHandler = (err, req: AuthRequest, res, next) => {
  if (err.name === 'UnauthorizedError') {
    return res.status(401).json({
      error: 'Authentication failed',
      details: err.message
    });
  }
  next(err);
};

app.use(errorHandler);

Advanced Usage

Custom Claims Validation

import { middleware, JwtVerifyConfig } from '@bliv/authentication';

const config: JwtVerifyConfig = {
  JWKSURL: 'https://your-jwks-url.com/.well-known/jwks.json',
  AUDIENCE: ['web', 'mobile'],  // Support multiple audiences
  ISSUER: 'https://your-issuer.com',
  IGNORE_PATHS: [
    '/public',
    '/health',
    /^\/api\/v1\/public\/.*/  // Support regex patterns
  ]
};

app.use(middleware(config));

Role-Based Access Control

import { AuthRequest } from '@bliv/authentication';

const checkRole = (role: string) => {
  return (req: AuthRequest, res, next) => {
    const userRoles = req.auth?.roles || [];
    
    if (!userRoles.includes(role)) {
      return res.status(403).json({ 
        error: 'Access denied',
        message: `Required role: ${role}`
      });
    }
    
    next();
  };
};

app.get('/admin', checkRole('admin'), (req, res) => {
  res.json({ message: 'Admin access granted' });
});

Development

Prerequisites

  • Node.js v16 or higher
  • npm v7 or higher

Setup

# Clone the repository
git clone https://github.com/bliv-club/bliv-authentication.git

# Install dependencies
npm install

# Build the library
npm run build

# Run tests
npm test

Available Scripts

  • npm run build: Compiles TypeScript code to JavaScript
  • npm test: Runs the test suite
  • npm run lint: Runs ESLint for code quality
  • npm run format: Formats code using Prettier

Version History

  • 0.0.6: Current version

    • Full TypeScript support with built-in type definitions
    • Improved error handling
    • Rate limiting for JWKS requests
    • Express middleware integration
    • Type-safe request handling
    • Customizable audience and issuer validation
    • Configurable path exclusions
    • Documentation updates
  • 0.0.5:

    • Added TypeScript support
    • Improved error handling
    • Updated dependencies
  • 0.0.4:

    • Initial TypeScript conversion
    • Added JWKS support
    • Basic middleware functionality
  • 0.0.3:

    • Initial release

Contributing

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add some amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

License

Apache-2.0

Support

For support:

  1. Check the documentation
  2. Open an issue in the GitHub repository
  3. Contact [email protected]

Acknowledgments

  • express-jwt - JWT middleware for Express
  • jwks-rsa - Retrieve RSA signing keys from a JWKS endpoint