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

@phila/sso-core

v0.0.9

Published

Framework-agnostic SSO client for Azure AD B2C / Entra External ID

Readme

@phila/sso-core

Framework-agnostic SSO client for Azure AD B2C / Entra External ID, built on top of @azure/msal-browser.

Installation

pnpm add @phila/sso-core @azure/msal-browser

Quick Start

import { SSOClient, B2CProvider } from "@phila/sso-core";

const client = new SSOClient({
  provider: new B2CProvider({
    clientId: "your-client-id",
    b2cEnvironment: "YourTenant",
    authorityDomain: "YourTenant.b2clogin.com",
    redirectUri: "http://localhost:3000",
  }),
  debug: true,
});

await client.initialize();

if (!client.state.isAuthenticated) {
  await client.signIn();
}

Providers

B2CProvider

Azure AD B2C authentication provider.

import { B2CProvider } from "@phila/sso-core";

const provider = new B2CProvider({
  clientId: "your-client-id",
  b2cEnvironment: "YourTenant",
  authorityDomain: "YourTenant.b2clogin.com",
  redirectUri: "http://localhost:3000",
  postLogoutRedirectUri: "http://localhost:3000", // optional, defaults to redirectUri
  apiScopes: ["https://YourTenant.onmicrosoft.com/api/read"], // optional
  policies: {
    signUpSignIn: "B2C_1A_SIGNUP_SIGNIN", // optional, shown values are defaults
    signInOnly: "B2C_1A_AD_SIGNIN_ONLY",
    resetPassword: "B2C_1A_PASSWORDRESET",
  },
  cacheLocation: "sessionStorage", // optional, "sessionStorage" | "localStorage"
});

CIAMProvider

Entra External ID (CIAM) provider.

import { CIAMProvider } from "@phila/sso-core";

const provider = new CIAMProvider({
  clientId: "your-client-id",
  tenantSubdomain: "yoursubdomain",
  redirectUri: "http://localhost:3000",
  scopes: ["api://your-api/scope"], // optional
});

EntraProvider

Entra workforce (Azure AD) provider.

import { EntraProvider } from "@phila/sso-core";

const provider = new EntraProvider({
  clientId: "your-client-id",
  tenantId: "your-tenant-guid",
  redirectUri: "http://localhost:3000",
  scopes: ["User.Read"], // optional
});

SSOClient API

Constructor

const client = new SSOClient({
  provider: B2CProvider | CIAMProvider | EntraProvider,
  debug?: boolean,
  state?: Record<string, unknown>, // custom state preserved across redirects
});

Lifecycle

| Method | Returns | Description | | -------------- | ------------------------------- | ---------------------------------------------------------- | | initialize() | Promise<AuthResponse \| null> | Initialize MSAL, process redirect, check existing sessions | | destroy() | void | Clean up resources and reset state |

Authentication

| Method | Returns | Description | | ------------------------------ | ------------------------- | ----------------------------------------------------- | | signIn(options?) | Promise<void> | Start sign-in redirect flow | | signInCityEmployee(options?) | Promise<void> | Sign in with the sign-in-only policy (B2C) | | signOut(options?) | Promise<void> | Sign out and redirect | | forgotPassword() | Promise<void> | Start password reset flow (B2C) | | acquireToken(options?) | Promise<string \| null> | Get access token (silent first, interactive fallback) |

Options

interface SignInOptions {
  scopes?: string[];
  loginHint?: string;
  domainHint?: string;
  state?: Record<string, unknown>;
  prompt?: string;
}

interface SignOutOptions {
  postLogoutRedirectUri?: string;
}

interface TokenOptions {
  scopes?: string[];
  forceRefresh?: boolean;
}

State

Access the current auth state via client.state:

interface SSOClientState {
  isAuthenticated: boolean;
  isLoading: boolean;
  user: AccountInfo | null;
  token: string | null;
  error: Error | null;
  activePolicy: string | null;
  authReady: boolean;
}

Events

Subscribe to auth lifecycle events:

const unsubscribe = client.events.on("auth:signedIn", response => {
  console.log("User signed in:", response.account);
});

// Clean up
unsubscribe();

| Event | Payload | Description | | --------------------- | ---------------- | ------------------------ | | auth:stateChanged | SSOClientState | Any state change | | auth:signedIn | AuthResponse | Sign-in completed | | auth:signedOut | void | Sign-out initiated | | auth:tokenAcquired | string | Token acquired silently | | auth:error | Error | Authentication error | | auth:forgotPassword | void | Password reset completed | | auth:loading | boolean | Loading state changed |

Custom State

Preserve arbitrary data across auth redirects:

const client = new SSOClient({
  provider,
  state: { returnUrl: "/dashboard" },
});

const response = await client.initialize();
if (response?.customPostbackObject) {
  console.log(response.customPostbackObject.returnUrl); // "/dashboard"
}

License

MIT