JSPM

  • Created
  • Published
  • Downloads 4384251
  • Score
    100M100P100Q233863F
  • License MIT

Microsoft Authentication Library for js

Package Exports

  • @azure/msal-browser
  • @azure/msal-browser/custom-auth
  • @azure/msal-browser/package.json
  • @azure/msal-browser/redirect-bridge

Readme

Microsoft Authentication Library for JavaScript (MSAL.js) for Browser-Based Single-Page Applications

npm version npm version codecov

Getting Started AAD Docs Library Reference
  1. About
  2. FAQ
  3. Changelog
  4. Roadmap
  5. Prerequisites
  6. Installation
  7. Usage
  8. Samples
  9. Build and Test
  10. Authorization Code vs Implicit
  11. Framework Wrappers
  12. Security Reporting
  13. License
  14. Code of Conduct

About

The MSAL library for JavaScript enables client-side JavaScript applications to authenticate users using Microsoft Entra ID work and school accounts (AAD), Microsoft personal accounts (MSA) and social identity providers like Facebook, Google, LinkedIn, Microsoft accounts, etc. through Azure AD B2C service. It also enables your app to get tokens to access Microsoft Cloud services such as Microsoft Graph.

The @azure/msal-browser package described by the code in this folder uses the @azure/msal-common package as a dependency to enable authentication in JavaScript Single-Page Applications without backend servers. This version of the library uses the OAuth 2.0 Authorization Code Flow with PKCE. To read more about this protocol, as well as the differences between implicit flow and authorization code flow, see the section below.

The @azure/msal-browser package does NOT support the implicit flow.

FAQ

See here.

Prerequisites

Installation

CDN Deprecation

⚠️ The @azure/msal-browser CDN has been fully deprecated as of @azure/msal-browser@3.0.0 and is no longer supported. App developers using the MSAL CDN must upgrade to the latest possible version and consume MSAL through a package manager or bundling tool of their choice. For more information on version support, consult the table in the project README.md.

Via NPM

npm install @azure/msal-browser

Via Yarn

yarn add @azure/msal-browser

Usage

Migrating from Previous MSAL Versions

Select the guide that matches your current MSAL version:

MSAL Basics

  1. Initialization
  2. Logging in a User
  3. Acquiring and Using an Access Token
  4. Managing Token Lifetimes
  5. Managing Accounts
  6. Logging Out a User

Advanced Topics

Samples

The msal-browser-samples folder contains sample applications for our libraries.

More advanced samples backed with a tutorial can be found in the Azure Samples space on GitHub:

We also provide samples for addin/plugin scenarios:

Build and Test

See the contributing.md file for more information.

Building the package

To build the @azure/msal-browser library, you can do the following:

// Change to the msal-browser package directory
cd lib/msal-browser/
// To run build only for browser package
npm run build

To build both the @azure/msal-browser library and @azure/msal-common libraries, you can do the following:

// Change to the msal-browser package directory
cd lib/msal-browser/
// To run build for both browser and common packages
npm run build:all

Running Tests

@azure/msal-browser uses jest to run unit tests.

// To run tests
npm test
// To run tests with code coverage
npm run test:coverage

Authorization Code Flow with Proof Key for Code Exchange (PKCE)

@azure/msal-browser implements the OAuth 2.0 Authorization Code Flow with PKCE for browser-based applications.

The Authorization Code Flow with Proof Key for Code Exchange (PKCE) is the current industry standard for securing OAuth 2.0 authorization in public clients, including single-page applications (SPAs). Key benefits include:

  • Enhanced Security: PKCE provides protection against authorization code interception attacks
  • No Tokens in URLs: Tokens are never exposed in the browser's URL or history
  • Refresh Token Support: Enables long-lived sessions through refresh tokens
  • OIDC Compliance: Fully compliant with OpenID Connect standards

Framework Wrappers

If you are using a framework such as Angular or React you may be interested in using one of our wrapper libraries:

Security Reporting

If you find a security issue with our libraries or services please report it to secure@microsoft.com with as much detail as possible. Your submission may be eligible for a bounty through the Microsoft Bounty program. Please do not post security issues to GitHub Issues or any other public site. We will contact you shortly upon receiving the information. We encourage you to get notifications of when security incidents occur by visiting this page and subscribing to Security Advisory Alerts.

License

Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.

We Value and Adhere to the Microsoft Open Source Code of Conduct

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.