Skip to content

Files

Latest commit

838b472 · Jan 15, 2021

History

History
This branch is 6580 commits behind AzureAD/microsoft-authentication-library-for-js:dev.

Folders and files

NameName
Last commit message
Last commit date

parent directory

..
Dec 11, 2020
Dec 3, 2020
Jan 15, 2021
Oct 20, 2020
Jan 12, 2021
Sep 29, 2020
Jan 12, 2021
Jan 12, 2021
Jan 14, 2021
Jan 5, 2021
Nov 2, 2020
Dec 17, 2020
Jan 12, 2021
Nov 1, 2020
Nov 1, 2020

Microsoft Authentication Library for React (msal-react)

npm versionnpm version

msal-react is under development. We do not recommend using this in a production environment yet.

AAD Docs Support Samples
  1. About
  2. FAQ
  3. Prerequisites
  4. Installation
  5. Build and Test
  6. Usage
  7. Samples
  8. Security Reporting
  9. License
  10. Code of Conduct

About

The MSAL library for JavaScript enables client-side JavaScript applications to authenticate users using Azure AD 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-react package described by the code in this folder uses the @azure/msal-browser package as a peer 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 in the msal-browser readme.

Prerequisites

Installation

The MSAL React package is available on NPM.

npm install react react-dom
npm install @azure/msal-react @azure/msal-browser

Build and Test

See the contributing.md file for more information.

Building the package locally

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

// Install dev dependencies from root of repo
npm install
// Change to the msal-react package directory
cd lib/msal-react/
// To run build only for react package
npm run build

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

// Install dev dependencies from root of repo
npm install
// Change to the msal-react package directory
cd lib/msal-react/
// To run build for react and browser packages
npm run build:all

Running Tests

@azure/msal-react uses jest to run unit tests and coverage.

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

Usage

For help getting started with msal-react please see our getting started doc.

MSAL Basics

Since msal-react is built on top of @azure/msal-browser a lot of the same docs are relevant. For concepts specific to msal-react please see below

  1. Initialization
  2. Acquiring and using an access token
  3. Managing token lifetimes
  4. Managing Accounts
  5. Logging out

Advanced Topics

MSAL React Specific Concepts

  1. Hooks

Samples

Our samples directory contains several example apps you can spin up to see how this library can be used in different contexts.

Security Reporting

If you find a security issue with our libraries or services please report it to [email protected] 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 [email protected] with any additional questions or comments.