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

@cepseudo/auth

v1.0.1

Published

Authentication providers, user management, and middleware for Digital Twin framework

Readme

@cepseudo/auth

npm version License: MIT

Pluggable authentication and user management for the Digital Twin framework.

Installation

pnpm add @cepseudo/auth

Peer dependency: @cepseudo/shared (workspace)

Auth Modes

| Mode | AUTH_MODE | Use case | How it works | |------|------------|----------|--------------| | Gateway | gateway (default) | Production behind Apache APISIX or similar | Parses x-user-id and x-user-roles headers set by the API gateway | | JWT | jwt | Standalone deployment without a gateway | Validates Bearer tokens from the Authorization header using HMAC or RSA/EC | | None | none | Development and testing | Returns an anonymous user for every request, no credentials required |

Usage

Creating a provider with AuthProviderFactory

The factory reads environment variables to create the right provider:

import { AuthProviderFactory } from '@cepseudo/auth'

// Auto-detect mode from AUTH_MODE env var (defaults to 'gateway')
const provider = AuthProviderFactory.fromEnv()

// Or configure explicitly
const provider = AuthProviderFactory.create({
    mode: 'jwt',
    adminRoleName: 'admin',
    jwt: {
        secret: 'your-hmac-secret',
        algorithm: 'HS256',
        userIdClaim: 'sub',
        rolesClaim: 'roles',
    },
})

Using the AuthProvider interface

All providers implement the same AuthProvider interface:

const user = provider.parseRequest(req) // AuthenticatedUser | null
const valid = provider.hasValidAuth(req) // boolean
const admin = provider.isAdmin(req)      // boolean
const userId = provider.getUserId(req)   // string | null
const roles = provider.getUserRoles(req) // string[]

Setting up AuthMiddleware

AuthMiddleware is the single source of truth for authenticating HTTP requests across all components. It combines header/token parsing with user record management:

import { AuthMiddleware, UserService } from '@cepseudo/auth'
import type { UserRepository } from '@cepseudo/shared'

// UserRepository is injected (typically KnexUserRepository from @cepseudo/database)
const userService = new UserService(userRepository)
const authMiddleware = new AuthMiddleware(userService)

Authenticating a request in a component

const result = await authMiddleware.authenticate(req)

if (!result.success) {
    // result.response contains the appropriate error (401/500)
    return result.response
}

// result.userRecord is the full UserRecord with id, keycloak_id, roles
const { userRecord } = result

Environment Variables

General

| Variable | Description | Default | |----------|-------------|---------| | AUTH_MODE | Authentication mode: gateway, jwt, or none | gateway | | AUTH_ADMIN_ROLE | Name of the admin role | admin | | DIGITALTWIN_DISABLE_AUTH | Set to true to disable auth (legacy, equivalent to none) | - | | DIGITALTWIN_ANONYMOUS_USER_ID | User ID for anonymous access in none mode | anonymous |

JWT Mode

| Variable | Description | Default | |----------|-------------|---------| | JWT_SECRET | HMAC secret key (required if no public key) | - | | JWT_PUBLIC_KEY | RSA/EC public key content | - | | JWT_PUBLIC_KEY_FILE | Path to public key file | - | | JWT_ALGORITHM | Signing algorithm | HS256 | | JWT_ISSUER | Expected token issuer | - | | JWT_AUDIENCE | Expected token audience | - | | JWT_USER_ID_CLAIM | JWT claim containing the user ID | sub | | JWT_ROLES_CLAIM | JWT claim containing roles (supports dot-paths like realm_access.roles) | roles |

License

MIT