@azure/msal-browser

Client-side authentication library for browser SPAs, implementing OAuth 2.0 Authorization Code Flow with PKCE against Microsoft Entra ID.

SDK
npm
v5.21.0
4,118stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum.How we score it →
96/100Excellent
Development Activity96
Maintenance96
Community92
Maturity60
Momentum40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation.How we score it →
89/100Excellent
Architecture88
Code Quality92
Innovation85
Learning Curve90

@azure/msal-browser is Microsoft’s official client library for adding sign-in and token acquisition to browser-based single-page applications. It implements the OAuth 2.0 Authorization Code Flow with PKCE against Microsoft Entra ID (Azure AD), Microsoft personal accounts, and Azure AD B2C identity providers, handling redirect and popup login flows, silent token renewal via hidden iframes, and secure token caching in the browser without a backend server.

Built as one package in the msal.js monorepo alongside @azure/msal-common, @azure/msal-node, and framework wrappers for Angular and React, msal-browser exposes a single PublicClientApplication entry point backed by pluggable interaction clients for popup, redirect, silent-iframe, and silent-refresh flows, plus dedicated support for nested app authentication (Office Add-ins, Teams tabs) and native broker scenarios on Windows.

What You Get

  • A PublicClientApplication class exposing loginPopup, loginRedirect, acquireTokenSilent, and ssoSilent methods for the full authentication lifecycle
  • Automatic silent token renewal via hidden iframes with fallback to interactive popup or redirect when silent renewal fails
  • Pluggable browser token cache with support for localStorage, sessionStorage, memory, and cookie storage backends
  • Built-in account management for multi-account scenarios, including getAllAccounts and account filtering by tenant or home account
  • Nested app authentication support for Office Add-ins and Teams tabs via the @azure/msal-browser controllers for non-standard operating contexts
  • A dedicated custom-auth entry point for native, redirect-free sign-up/sign-in UI flows against Entra External ID

Common Use Cases

  • Signing users into a React, Angular, or vanilla JS single-page app against a company’s Microsoft Entra tenant
  • Acquiring access tokens to call Microsoft Graph or a protected backend API from client-side code
  • Supporting Azure AD B2C consumer sign-up/sign-in flows for public-facing web apps
  • Adding single sign-on so a signed-in user is silently recognized across multiple first-party apps
  • Embedding authenticated Microsoft identity flows inside an Office Add-in or Microsoft Teams tab

Under The Hood

Architecture The library separates concerns into app (the public PublicClientApplication facade), controllers (StandardController for normal browser contexts, NestedAppAuthController for Office/Teams host scenarios, UnknownOperatingContextController as a fallback), and interaction_client (BaseInteractionClient specialized into PopupClient, RedirectClient, SilentIframeClient, SilentRefreshClient, SilentCacheClient, and HybridSpaAuthorizationCodeClient). This controller-per-operating-context design lets the same public API route to entirely different token-acquisition strategies depending on whether the app is running in a normal browser tab or hosted inside another application, while cache/BrowserCacheManager and its storage adapters (LocalStorage, SessionStorage, CookieStorage, MemoryStorage, DatabaseStorage) isolate persistence from protocol logic. Changing the core @azure/msal-common request/response contracts that this package depends on would ripple through every interaction client.

Tech Stack Written entirely in TypeScript and built with Rollup into dual ESM/CJS output plus generated .d.ts/.d.cts type declarations, using conditional exports map entries for the main bundle and separate custom-auth, redirect-bridge, and popup-relay sub-entry points. The only runtime dependency is the sibling @azure/msal-common package from the same monorepo; tests run on Jest with jest-environment-jsdom and fake-indexeddb for browser-API simulation, and packaging is coordinated across the monorepo via npm workspaces and the beachball semantic-versioning tool.

Code Quality The package ships roughly 100 Jest spec files covering interaction clients, cache managers, crypto helpers, and controllers, with coverage tracked through Codecov and enforced in Azure Pipelines CI (.pipelines) rather than GitHub Actions. ESLint (via a shared eslint-config-msal workspace package) and Prettier enforce consistent style, TypeScript’s strict settings catch type errors at build time, and error handling is centralized into typed BrowserAuthError, BrowserConfigurationAuthError, and NestedAppAuthError classes with dedicated error-code enums rather than ad hoc thrown strings.

API Design The public surface is a single PublicClientApplication class with consistently named methods (loginPopup/loginRedirect/acquireTokenSilent/ssoSilent/logout), which keeps the getting-started path to a handful of calls, though the full configuration surface (authority, cache, system, telemetry options) is large and documented across a dozen separate markdown guides in docs/ rather than in a single reference. Extensive migration guides for each major version (v1 through v4) reduce upgrade friction for a library with a wide, long-lived install base.

Used by 9 apps in this directory

TypeScript
100%
MIT

Botpress

AI Assistants · AI Development · Customer Support

14,893

The open-source hub for building and deploying LLM-powered AI agents with TypeScript-first tooling, 40+ integrations, and a revolutionary code-execution agent framework.

View details
94
Repo Health
82
Technical
64
Dependency
Built with
TypeScript100%
Updated 3 days ago
TypeScript
69%
Other

Budibase

Low Code Platforms · No Code Platforms

28,260

Build AI agents, automations, and internal apps on a single open-source platform with full self-hosting control.

View details
91
Repo Health
81
Technical
63
Dependency
Built with
TypeScript69%
Svelte26%
Updated 2 days ago
TypeScript
97%
MPL 2.0

Logto

Authentication

14,510

Open-source auth infrastructure for SaaS and AI apps with OIDC, SAML, and RBAC

View details
91
Repo Health
83
Technical
63
Dependency
Built with
TypeScript97%
Updated yesterday
TypeScript
95%
MIT

melty

Developer Tools · AI Code Assistants · Code Editors

5,443

The AI code editor where every chat message is a git commit you can revert, branch, or squash

View details
35
Repo Health
75
Technical
67
Dependency
Built with
TypeScript95%
Updated 1 years ago
Python
37%
Other

Open WebUI

AI Assistants · AI Agents

151,143

The extensible, privacy-first AI platform that runs Ollama, OpenAI, and any LLM backend behind a polished, feature-packed web interface.

View details
91
Repo Health
75
Technical
66
Dependency
Built with
Python37%
Svelte34%
JavaScript21%
Updated yesterday
TypeScript
80%
Other

twenty

CRM

56,361

The open-source CRM you build, ship, and version like the rest of your stack — with customizable objects, AI agents, and a TypeScript SDK.

View details
92
Repo Health
82
Technical
64
Dependency
Built with
TypeScript80%
MDX17%
Updated yesterday
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Code Editors · Automation

28,810

Open-source AI code editor with direct LLM integration and data privacy

View details
46
Repo Health
84
Technical
68
Dependency
Built with
TypeScript95%
Updated 3 months ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Code Editors · Automation

28,810

Open-source AI code editor with direct LLM integration and data privacy

View details
46
Repo Health
84
Technical
68
Dependency
Built with
TypeScript95%
Updated 3 months ago
Vue
47%
AGPL 3.0

Wiki.js

Knowledge Management · Collaboration

28,848

A modern, self-hosted wiki platform built on Node.js with a rich plugin ecosystem for authentication, search, storage, and rendering that adapts to any team's infrastructure.

View details
72
Repo Health
67
Technical
60
Dependency
Built with
Vue47%
JavaScript42%
Updated today

Join founders buildingwith open source

Opinionated takes, migration guides, cost-saving tips, and insights from the open source ecosystem.

Subscribe on Substack
Join 750+ subscribers

Search