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

@riao/authn-sso-entra

v1.0.0

Published

authn-sso-entra

Readme

@riao/authn-sso-entra

Microsoft Entra ID (Azure AD) authentication driver for riao-iam.

Installation

npm install @riao/authn-sso-entra @riao/iam @riao/dbal
npm install --save-dev @riao/cli
npx riao migration:create import-sso-entra-tables

database/main/migrations/123456789-import-sso-tables.ts:

import { AuthenticationSSOMigrations } from '@riao/authn-sso/authentication-sso-migrations';

export default AuthenticationSSOMigrations;

Setup

1. Register Application in Entra

  1. Go to Azure Portal
  2. Navigate to Azure Active Directory → App registrations
  3. Click "New registration"
  4. Configure:
    • Name: Your application name
    • Supported principal types: Choose based on your needs
    • Redirect URI: https://yourdomain.com/auth/entra/callback

2. Create Client Secret

  1. In your app registration, go to Certificates & secrets
  2. Click "New client secret"
  3. Copy the value (you won't be able to see it again)

3. Get Configuration Values

From your app registration Overview page, note:

  • Application (client) IDENTRA_CLIENT_ID
  • Directory (tenant) IDENTRA_TENANT_ID

Configuration

import { EntraAuthentication } from '@riao/authn-sso-entra';

const entraAuth = new EntraAuthentication({
	db: database,
	clientId: process.env.ENTRA_CLIENT_ID!,
	clientSecret: process.env.ENTRA_CLIENT_SECRET!,
	tenantId: process.env.ENTRA_TENANT_ID!,
	redirectUri: process.env.ENTRA_REDIRECT_URI!,
});

Required API Permissions

IMPORTANT: You must configure the following permission in your app registration:

  1. Go to App RegistrationAPI permissions
  2. Click + Add a permission
  3. Select Microsoft GraphDelegated permissions
  4. Search for and grant: User.Read
  5. Click Grant admin consent for [Organization]

Without the User.Read permission, user info retrieval will fail with a 403 Forbidden error.

Custom Scopes

By default, the driver requests: openid, profile, email, https://graph.microsoft.com/.default.

To customize scopes:

const entraAuth = new EntraAuthentication({
	// ... other options
	scopes: ['openid', 'profile', 'email', 'offline_access'],
});

Environment Variables

ENTRA_CLIENT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ENTRA_CLIENT_SECRET=your-secret-here
ENTRA_TENANT_ID=xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx
ENTRA_REDIRECT_URI=https://yourdomain.com/auth/entra/callback

Usage

Get Authorization URL

const state = crypto.randomUUID();
const authUrl = entraAuth.getAuthorizationUrl(state);
// Redirect user to authUrl

Handle Callback

const principal = await entraAuth.authenticate({ code });
if (principal) {
	// User authenticated successfully
	// Create session, JWT token, etc.
}

Refresh Access Token

const newAccessToken = await entraAuth.refreshAccessToken(principalId);

Get Stored Token

const tokenRecord = await entraAuth.getStoredToken(principalId);

Revoke Session

await entraAuth.revokeSession(principalId);

API Scopes

Default Scopes

The implementation requests these scopes by default:

  • openid - Required for OpenID Connect identity verification
  • profile - User's profile information (displayName, etc.)
  • email - User's email address
  • https://graph.microsoft.com/.default - Microsoft Graph API access (required for fetching user info)

Note: To make these work, you must grant the User.Read permission in your app registration's API permissions.

Optional Scopes

  • offline_access - Enables refresh tokens for persistent access without user interaction

Scope Descriptions

| Scope | Purpose | Required | Notes | |-------|---------|----------|-------| | openid | Identity verification | Yes | Always required | | profile | User profile data | Yes | Needed for displayName | | email | Email address | Yes | Needed for user email | | https://graph.microsoft.com/.default | Graph API access | Yes | Required for getUserInfo() | | offline_access | Refresh tokens | No | Optional, for persistent access |

Example: Adding Offline Access

const entraAuth = new EntraAuthentication({
	// ... other options
	scopes: [
		'openid',
		'profile',
		'email',
		'https://graph.microsoft.com/.default',
		'offline_access', // Enables refresh tokens
	],
});

For a complete list of available scopes, see Microsoft Entra permissions and consent.

Error Handling

All methods throw on network/API errors. Wrap calls in try-catch:

try {
	const principal = await entraAuth.authenticate({ code });
}
catch (error) {
	console.error('Authentication failed:', error);
}

Contributing & Development

See contributing.md for information on how to develop or contribute to this project!