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

@bigscoots/wpo-v2-authentication-lib

v1.0.31

Published

WPO V2 Authentication Library

Readme

WPO V2 Authentication Library

NestJS authentication/authorization library with a global guard chain:

  1. JwtAuthGuard
  2. PermissionsGuard
  3. RoleValidationGuard

It supports both:

  • Standard JWT traffic.
  • Gateway-forwarded enterprise API-key traffic (x-auth-type=api_key).

Installation

npm install @bigscoots/wpo-v2-authentication-lib

Configuration

PermissionModule.forRoot({
  namespace: process.env.AUTH_NAMESPACE,
  domain: process.env.AUTH_DOMAIN,
  audience: process.env.AUTH_AUDIENCE,
  gatewaySharedToken: process.env.GATEWAY_SHARED_TOKEN,
  // default is true when omitted
  // set false only if you want selective @AllowApiKeyAuth() opt-in
  allowApiKeyAuthGlobally: true,
  redis: {
    host: process.env.REDIS_HOST,
    port: Number(process.env.REDIS_PORT),
    password: process.env.REDIS_PASSWORD,
  },
});

gatewaySharedToken can also be provided via GATEWAY_SHARED_TOKEN env var.

JWT Flow (Unchanged)

  • Request includes Authorization: Bearer <jwt>.
  • JwtAuthGuard verifies JWT against configured JWKS/domain/audience.
  • request.user is built from JWT claims.
  • PermissionsGuard and RoleValidationGuard execute as before.

Gateway API-Key Flow

Use this for gateway-authenticated enterprise routes.

Required forwarded headers:

  • x-auth-type: api_key
  • x-client-id: <keyId>
  • x-org-id: <orgId/userUuid>
  • x-gateway-token: <sharedGatewayToken>

Security behavior:

  • Header mode is accepted globally by default.
  • You can disable global mode (allowApiKeyAuthGlobally=false) and then selectively opt-in routes with @AllowApiKeyAuth().
  • x-gateway-token must match configured shared token using constant-time compare.
  • No KV/DB API-key validation is performed in this library.

Principal mapping for API-key mode:

  • request.user.uuid = x-org-id
  • request.user.role = customer
  • request.user.permissions = []
  • request.authContext = { authType: 'api_key', clientId, orgId }

Route Example (Global Dual-Auth)

import { Controller, Get } from '@nestjs/common';
import {
  ApiKeyGatewayHeadersDecorator,
  Roles,
} from '@bigscoots/wpo-v2-authentication-lib';

@Controller('enterprise')
export class EnterpriseController {
  @Get('usage')
  @Roles('customer')
  @ApiKeyGatewayHeadersDecorator()
  getUsage() {
    return { ok: true };
  }
}

Optional strict mode:

  • Set allowApiKeyAuthGlobally=false.
  • Then add @AllowApiKeyAuth() only where API-key traffic should be accepted.

Request Examples

JWT request:

curl -X GET "https://service.example.com/v1/sites" \
  -H "Authorization: Bearer <jwt>"

Gateway-forwarded API-key request:

curl -X GET "https://service.example.com/enterprise/usage" \
  -H "x-auth-type: api_key" \
  -H "x-client-id: key_123" \
  -H "x-org-id: org_456" \
  -H "x-gateway-token: $GATEWAY_SHARED_TOKEN"

Migration Guide

See notes/gateway-api-key-migration-guide.md.