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

@accountsystem/auth-node-sdk

v1.0.0

Published

Node.js SDK for AccountSystem authentication microservice. This SDK provides Express middleware and utilities to integrate with the AccountSystem authentication service, supporting both local authentication and OAuth (Google, Microsoft, Facebook) with adv

Readme

Auth Node SDK

Node.js SDK for AccountSystem authentication microservice. This SDK provides Express middleware and utilities to integrate with the AccountSystem authentication service, supporting both local authentication and OAuth (Google, Microsoft, Facebook) with advanced features like 2FA, session management, and real-time notifications.

Features

  • 🔐 Session Validation: Middleware for validating user sessions
  • 🎯 Account Type Enforcement: Require specific account types (Local/OAuth)
  • 🔑 Google API Integration: Validate Google OAuth scopes and permissions
  • 🔄 Automatic Token Refresh: Handle token expiration gracefully
  • 📡 Real-time Notifications: WebSocket client for live updates
  • 🛡️ Secure Communication: mTLS authentication with the auth service
  • 📝 TypeScript Support: Full type definitions included
  • Express Middleware: Easy integration with Express.js applications

Installation

npm install @accountsystem/auth-node-sdk

Quick Start

1. Configure the SDK

import { AuthSDK } from '@accountsystem/auth-node-sdk';

// Configure the SDK with your service credentials
AuthSDK.configure({
  authServiceUrl: 'https://your-auth-service.com',
  serviceName: 'your-service-name',
  serviceSecret: 'your-service-secret',
  certificates: {
    key: '/path/to/your/client.key',
    cert: '/path/to/your/client.crt',
    ca: '/path/to/ca.crt'
  },
  requestTimeout: 10000 // optional, defaults to 10 seconds
});

2. Use Authentication Middleware

import express from 'express';
import { AuthSDK } from '@accountsystem/auth-node-sdk';

const app = express();

// Validate session for protected routes
app.use('/:accountId/protected', AuthSDK.validateSession());

// Require specific account type
app.use('/:accountId/oauth-only', 
  AuthSDK.validateSession(),
  AuthSDK.requireAccountType('oauth')
);

// Require Google API scopes
app.use('/:accountId/gmail', 
  AuthSDK.validateSession(),
  AuthSDK.requireGoogleScope('gmail.readonly')
);

// Multiple scopes
app.use('/:accountId/calendar-gmail', 
  AuthSDK.validateSession(),
  AuthSDK.requireGoogleScopes(['gmail.readonly', 'calendar.events'])
);

// Your protected route
app.get('/:accountId/protected/data', (req, res) => {
  // req.account contains the authenticated user's account information
  res.json({
    message: 'Hello authenticated user!',
    account: req.account
  });
});

3. Use the Client Directly

import { AuthSDK } from '@accountsystem/auth-node-sdk';

const authClient = AuthSDK.getInstance().getAuthClient;

// Get user information
try {
  const userInfo = await authClient.getUserInfo('account-id-123');
  console.log('User:', userInfo.account.userDetails.name);
} catch (error) {
  console.error('Failed to get user info:', error.message);
}

// Search user by email
const user = await authClient.searchUserByEmail('[email protected]');

// Validate session
const session = await authClient.validateSession('account-id', 'access-token');

// Get user's Google scopes
const scopes = await authClient.getUserScopes('account-id');

4. Real-time Notifications

import { AuthSDK } from '@accountsystem/auth-node-sdk';

const socketClient = AuthSDK.getInstance().getSocketClient;

// Connect to notification service
await socketClient.connect();

// Subscribe to account notifications
await socketClient.subscribeToAccount('account-id-123');

// Listen for notifications
socketClient.onNotification('notification:new', (data) => {
  console.log('New notification:', data);
});

socketClient.onNotification('notification:updated', (data) => {
  console.log('Notification updated:', data);
});

Configuration Options

Required Configuration

{
  authServiceUrl: 'https://your-auth-service.com',  // Your AccountSystem service URL
  serviceName: 'your-service-name',                 // Internal service identifier
  serviceSecret: 'your-service-secret',             // Service authentication secret
  certificates: {
    key: '/path/to/client.key',                     // Client private key for mTLS
    cert: '/path/to/client.crt',                    // Client certificate for mTLS  
    ca: '/path/to/ca.crt'                          // CA certificate for verification
  }
}

Optional Configuration

{
  requestTimeout: 10000  // Request timeout in milliseconds (default: 10000)
}

Security

This SDK uses mutual TLS (mTLS) for secure communication with the AccountSystem service. The authentication flow includes:

  1. Client Certificate Validation - Your service must present a valid client certificate signed by the same CA as the auth service
  2. Service Header Authentication - The SDK automatically sends service identification headers
  3. Request Signing - All requests are authenticated using your service credentials

Ensure your certificates are properly configured and secured. No additional configuration is needed on the auth service side.

Error Handling

The SDK throws errors with descriptive messages. Wrap your calls in try-catch blocks:

try {
  const user = await authClient.getUserInfo(accountId);
} catch (error) {
  console.error('Auth error:', error.message);
  // Handle the error appropriately
}

TypeScript Support

This SDK is written in TypeScript and provides full type definitions. All types are exported:

import { SafeAccount, AccountType, AuthSDKConfig } from '@accountsystem/auth-node-sdk';

License

MIT License - see LICENSE file for details.