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

@unidev-hub/azure-auth

v1.0.1

Published

Azure AD authentication and authorization module for Node.js applications

Readme

@unidev-hub/azure-auth

Azure AD Authentication Module

A reusable npm module for authentication and authorization using Azure AD in Node.js applications.

Features

  • Azure AD authentication using MSAL
  • Token validation and decoding
  • Role-based and group-based authorization
  • Express middleware for protecting routes
  • Token caching and refresh capabilities
  • Client credentials flow for server-to-server auth

Installation

npm install azure-auth

Prerequisites

This module has peer dependencies on:

  • express
  • logger
  • cache

Ensure these are installed in your project.

Usage

Basic Setup

import { createAzureAuth, AzureAdOptions } from 'azure-auth';
import { logger } from 'logger';
import { cache } from 'cache';

const azureOptions: AzureAdOptions = {
  tenantId: 'your-tenant-id',
  clientId: 'your-client-id',
  clientSecret: 'your-client-secret',
  redirectUri: 'http://localhost:3000/auth/callback',
  allowedGroups: ['admin-group-id']
};

const { service, middleware } = createAzureAuth(azureOptions, logger, cache);

// Use in Express application
import express from 'express';
const app = express();

// Protected route with authentication
app.get('/protected', 
  middleware.authenticate, 
  (req, res) => {
    res.json({ message: 'Authenticated', user: req.user });
  }
);

// Route protected with role-based authorization
app.get('/admin', 
  middleware.authenticate,
  middleware.requireRole('Admin'),
  (req, res) => {
    res.json({ message: 'Admin route' });
  }
);

// Route protected with group-based authorization
app.get('/group-members', 
  middleware.authenticate,
  middleware.requireGroup('group-id'),
  (req, res) => {
    res.json({ message: 'Group members only' });
  }
);

Login Process

// Generate login URL
app.get('/login', (req, res) => {
  const state = req.query.returnUrl || '/';
  service.getLoginUrl(state)
    .then(url => {
      res.redirect(url);
    })
    .catch(err => {
      res.status(500).json({ error: err.message });
    });
});

// Handle callback
app.post('/auth/callback', async (req, res) => {
  try {
    const { code, state } = req.body;
    const { user, tokenResponse } = await service.authenticateWithCode(code);
    
    // Store tokens in session or send to client
    req.session.accessToken = tokenResponse.accessToken;
    req.session.refreshToken = tokenResponse.refreshToken;
    
    // Redirect to original URL
    res.redirect(state || '/');
  } catch (error) {
    res.status(401).json({ error: 'Authentication failed' });
  }
});

Client Credentials Flow

// Service-to-service authentication
async function callProtectedAPI() {
  const tokenResponse = await service.getClientCredentialsToken();
  
  // Use token to call another API
  const apiResponse = await fetch('https://api.example.com/data', {
    headers: {
      Authorization: `Bearer ${tokenResponse.accessToken}`
    }
  });
  
  return apiResponse.json();
}

API Documentation

[Link to detailed API documentation]

License

MIT