Microsoft Authentication Library for React (msal-react)
|Getting Started||AAD Docs||Library Reference||Samples|
- Build and Test
- Security Reporting
- Code of Conduct
@azure/msal-react package described by the code in this folder uses the
@azure/msal-reactis meant to be used in Single-Page Application scenarios.
@azure/msal-reactyou will need to register a Single Page Application in Azure AD to get a valid
clientIdfor configuration, and to register the routes that your app will accept redirect traffic on.
The MSAL React package is available on NPM.
npm install react react-dom npm install @azure/msal-react @azure/msal-browser
Build and Test
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
@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
For help getting started with
@azure/msal-react please see our getting started doc.
@azure/msal-react is a wrapper around
@azure/msal-browser many docs from the
msal-browser repo are relevant here as well. For concepts specific to
@azure/msal-react please see below
- Acquiring and using an access token
- Managing token lifetimes
- Managing Accounts
- Logging out
MSAL React Specific Concepts
Our samples directory contains several example apps you can spin up to see how this library can be used in different contexts.
More advanced samples backed with a tutorial can be found in the Azure Samples space on GitHub:
- React SPA calling Express.js web API
- React SPA calling Express.js web API using Proof of Possesion tokens
- React SPA calling Microsoft Graph via Express.js web API using on-behalf-of flow
- Deployment tutorial for Azure Static Web Apps
If you find a security issue with our libraries or services please report it to email@example.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.
Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License.