|Getting Started||AAD Docs||Library Reference|
- Build and Test
- Authorization Code vs Implicit
- Framework Wrappers
- Security Reporting
- Code of Conduct
@azure/msal-browser package described by the code in this folder uses the
This is an improvement upon the current
msal-core library which will utilize the authorization code flow in the browser. Most features available in the old library will be available in this one, but there are nuances to the authentication flow in both. The
@azure/msal-browser package does NOT support the implicit flow.
@azure/msal-browseris meant to be used in Single-Page Application scenarios.
@azure/msal-browseryou 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.
npm install @azure/msal-browser
See here for more info on how to use this package from the Microsoft CDN.
Migrating from Previous MSAL Versions
If you have MSAL v1.x currently running in your application, you can follow the instructions here to migrate your application to using the
- Logging in a User
- Acquiring and Using an Access Token
- Managing Token Lifetimes
- Managing Accounts
- Logging Out a User
- Configuration Options
- Request and Response Details
- Cache Storage
- Performance Enhancements
- Instance Aware Flow
msal-browser-samples folder contains sample applications for our libraries.
- You can run any VanillaJSTestApp2.0 sample by changing the
authConfig.jsfile in the respective folder to match your app registration and running the
npm start -- -s <sample-name> -p <port>in the VanillaJSTestApp2.0 folder.
- You can run the TypescriptTestApp2.0 sample by changing the
AuthModule.tsfile to match your app registration and running the
npm startin the TypescriptTestApp2.0 folder.
msal-angular-v2-samples folder contains an Angular 10 sample app that uses msal-browser.
- You can run the angular10-browser sample by changing the
app.module.tsfile to match your app registration and running the
npm startin the angular-10-browser-sample folder.
Here is a complete list of samples for the MSAL.js 2.x library:
|Sample||Description||How to Run|
|TypeScript Sample||A TypeScript sample showing usage of MSAL 2.0 with the Microsoft Graph API.||
|Multiple Resources Sample||A vanilla JS sample showing usage of MSAL 2.0 with authentication on page load with a redirect.||
|On Page Load Sample||A vanilla JS sample showing usage of MSAL 2.0 with authentication on page load with a redirect.||
|ssoSilent() Sample||A vanilla JS sample showing usage of the ssoSilent API, allowing you to sign in a user silently if a context exists on the authentication server.||
|Internet Explorer 11 Sample||A vanilla JS sample showing usage of
|Angular 10 Sample||An Angular 10 sample showing usage of MSAL 2.0 with the Microsoft Graph API.||
|Hybrid Spa Sample (w/ MSAL Node)||Sample demonstrating how to use
|Vue 3 Sample||A Vue 3 sample showing usage of MSAL 2.0 with the Microsoft Graph API.||
More instructions to run the samples can be found in the
README.md file of the VanillaJSTestApp2.0 folder.
More advanced samples backed with a tutorial can be found in the Azure Samples space on GitHub:
- React & Redux SPA calling Microsoft Graph via ASP.NET Core web API using on-behalf-of flow
- Deployment tutorial for Azure App Service and Azure Storage
We also provide samples for addin/plugin scenarios:
Build and Test
contributing.md file for more information.
Linking local package dependencies
If you are having issues with
lerna and wish to use the local version of the
@azure/msal-common library (to reflect changes made in both repositories) you can run do the following:
// Change to the msal-browser package directory cd lib/msal-browser/ // Install package dependencies npm install // Change to the msal-common package directory cd ../msal-common/ // Install package dependencies npm install // Prepare the local msal-common package for linking npm link // Change back to the msal-browser package directory cd ../msal-browser/ // Link to the local build of msal-common npm link @azure/msal-common
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 only for browser package npm run build:all
// To run tests npm test // To run tests with code coverage npm run test:coverage:only
If you are using a framework such as Angular or React you may be interested in using one of our wrapper libraries:
Implicit Flow vs Authorization Code Flow with PKCE
Our goal is that the library abstracts enough of the protocol away so that you can get plug and play authentication, but it is important to know and understand the implicit flow from a security perspective. The MSAL 1.x client for single-page applications runs in the context of a web browser which cannot manage client secrets securely. It uses the implicit flow, which optimized for single-page applications and has one less hop between client and server so tokens are returned directly to the browser. These aspects make it naturally less secure. These security concerns are mitigated per standard practices such as: use of short lived tokens (and so no refresh tokens are returned), the library requiring a registered redirect URI for the app, and library matching the request and response with a unique nonce and state parameter. You can read more about the disadvantages of the implicit flow here.
The MSAL library will now support the Authorization Code Flow with PKCE for Browser-Based Applications without a backend web server.
We plan to continue support for the implicit flow in the
If you find a security issue with our libraries or services please report it to firstname.lastname@example.org 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.