@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.26.0
4,142 stars
MIT License

Repository Health

Pre-computed score based on development activity, maintenance, community, maturity, and trend momentum. How we score it →
97 /100 Excellent
Development Activity 100
Maintenance 96
Community 92
Maturity 60
Momentum 40

Technical Analysis

AI-assessed by reading the actual repository — architecture, code quality, innovation, and documentation. How we score it →
89 /100 Excellent
Architecture 88
Code Quality 92
Innovation 85
Learning Curve 90

@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,964

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
95
Repo Health
82
Technical
64
Dependency
Built with
TypeScript 100%
Updated 6 days ago
TypeScript
72%
Other

Budibase

Low Code Platforms · No Code Platforms

28,345

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

View details
92
Repo Health
81
Technical
63
Dependency
Built with
TypeScript 72%
Svelte 24%
Updated 6 days ago
TypeScript
98%
MPL 2.0

Logto

Authentication

14,769

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

View details
92
Repo Health
83
Technical
63
Dependency
Built with
TypeScript 98%
Updated 6 days ago
TypeScript
95%
MIT

melty

AI Code Assistants · Code Editors · Developer Tools

5,462

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
TypeScript 95%
Updated 1 years ago
Python
38%
Other

Open WebUI

AI Agents · AI Assistants

156,607

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

View details
92
Repo Health
75
Technical
66
Dependency
Built with
Python 38%
Svelte 35%
JavaScript 19%
Updated 5 days ago
TypeScript
84%
Other

twenty

CRM

59,615

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
TypeScript 84%
MDX 14%
Updated 6 days ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Automation · Code Editors

28,733

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

View details
44
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 95%
Updated 4 months ago
TypeScript
95%
Apache 2.0

Void

AI Code Assistants · Automation · Code Editors

28,733

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

View details
44
Repo Health
84
Technical
68
Dependency
Built with
TypeScript 95%
Updated 4 months ago
TypeScript
41%
AGPL 3.0

Wiki.js

Collaboration · Knowledge Management

29,081

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
95
Repo Health
67
Technical
60
Dependency
Built with
TypeScript 41%
Vue 39%
JavaScript 16%
Updated 5 days ago

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