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 🙏

© 2025 – Pkg Stats / Ryan Hefner

@saminwankwo/auth-sdk

v1.0.1

Published

A scalable, plugin-driven Authentication & Authorization SDK for Express.js with JWT, API-Keys, OTP, RBAC and more

Readme

🔐 Auth SDK for Express.js

A plug-and-play authentication & authorization SDK built for Express applications. Supports JWT access/refresh tokens, OTP via email/SMS, API key management, rate limiting, and pluggable providers like OAuth.


🚀 Quickstart

📦 Installation

npm install @saminwankwo/auth-sdk
# or
yarn add @saminwankwo/auth-sdk

⚙️ Environment Configuration

Create a .env file at your project root:

# Server
PORT=3000
BASE_PATH=/api/auth

# JWT
JWT_ACCESS_SECRET=your-access-secret
JWT_REFRESH_SECRET=your-refresh-secret
JWT_ACCESS_EXPIRES_IN=15m
JWT_REFRESH_EXPIRES_IN=7d

# Rate Limiting
RATE_WINDOW_MS=60000
RATE_MAX=100
RATE_MESSAGE=Too many requests

# Logging
LOG_LEVEL=info
LOG_FORMAT=dev

# Email (Nodemailer)
EMAIL_HOST=smtp.example.com
EMAIL_PORT=587
EMAIL_SECURE=false
[email protected]
EMAIL_PASS=your-email-password

# SMS (Twilio)
TWILIO_ACCOUNT_SID=your-twilio-sid
TWILIO_AUTH_TOKEN=your-twilio-token
TWILIO_PHONE_NUMBER=+1234567890

# Blacklist Storage
BLACKLIST_STORE=memory
# Optional Redis: REDIS_URL or REDIS_HOST=localhost

# Plugins
PLUGINS=oauth

🔧 Basic Usage

// server.js
require('dotenv').config();
const AuthSDK = require('auth-sdk-express');

(async () => {
  const sdk = new AuthSDK(); // Uses process.env by default
  sdk.setupMiddlewares()
     .mountRoutes()
     .start();
})();

By default, routes are available under /api/auth:

| Method | Route | Description | | ------ | ------------------------- | ------------------------- | | POST | /register | Register and send OTP | | POST | /verify | Verify OTP and get tokens | | POST | /login | Email/password login | | POST | /refresh | Refresh JWT tokens | | POST | /change-password (auth) | Change user password |


🛠 Custom Configuration

You can override environment settings:

const sdk = new AuthSDK({
  env: {
    ...process.env,
    PORT: 4000,
  },
});

🔌 Adding Plugins

Enable OAuth or any custom plugin:

sdk.registerPlugin(require('auth-sdk-express/src/plugins/oauthPlugin'));

🔁 Using the OTP Service

Generate and send OTP programmatically:

const { OtpService } = require('auth-sdk-express').services;
const otp = new OtpService(sdk.config);

await otp.generateAndSend(userId, userEmail, 'email');

🔑 API Key Management

1. Generate a New Key

const { ApiKeyService } = require('auth-sdk-express/src/services/ApiKeyService');
const keySvc = new ApiKeyService();

const { key, id } = await keySvc.generate('my-service', ['read:users', 'write:orders']);
console.log('API Key:', key);

2. Rotate an Existing Key

const { key: newKey } = await keySvc.rotate(oldRawKey);
console.log('New API Key:', newKey);

3. Revoke a Key

await keySvc.revoke({ key: rawKey });

4. Secure Routes with API Key Middleware

const apiKey = require('auth-sdk-express/src/middleware/apiKey.middleware');

app.get('/protected', apiKey('read:users'), (req, res) => {
  res.json({ message: 'Secure content' });
});

💡 Contributing

Got an idea or found a bug? PRs and issues are welcome on GitHub!


📄 License

MIT © Nwankwo Samuel