MSAL Node enables 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.
OAuth2.0 grant types supported:
The current version supports the following ways of acquiring tokens:
There are multiple samples included in the repository that use MSAL Node to acquire tokens. These samples are currently used for manual testing, and are not meant to be a reference of best practices, therefore use judgement and do not blindly copy this code to any production applications.
AAD samples:
auth-code: Express app using OAuth2.0 authorization code flow.
auth-code-pkce: Express app using OAuth2.0 authorization code flow with PKCE.
device-code: Command line app using OAuth 2.0 device code flow.
refresh-token: Command line app using OAuth 2.0 refresh flow.
B2C samples:
b2c-user-flows: Express app using OAuth2.0 authorization code flow.
Others:
msal-node-extensions: Uses authorization code flow to acquire tokens and the msal-extensions library to write the MSAL in-memory token cache to disk.
Build and Test
// Install dependencies from root of reponpm install// Change to the msal-node package directorycd lib/msal-node// To run build for common package & node packagenpm run build:all// To run build only for node packagenpm run build// To run testsnpm run test
Local Development
Below is a list of commands you will probably find useful:
npm run build:modules:watch
Runs the project in development/watch mode. Your project will be rebuilt upon changes. TSDX has a special logger for you convenience. Error messages are pretty printed and formatted for compatibility VS Code's Problems tab. The library will be rebuilt if you make edits.
npm run build
Bundles the package to the dist folder.
The package is optimized and bundled with Rollup into multiple formats (CommonJS, UMD, and ES Module).
npm run build:all
Builds both msal-common and msal-node
npm run lint
Runs eslint with Prettier
npm test, npm run test:coverage, npm run test:watch
Runs the test watcher (Jest) in an interactive mode.
By default, runs tests related to files changed since the last commit.
Generate code coverage by adding the flag --coverage. No additional setup needed. Jest can collect code coverage information from entire projects, including untested files.
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
silent-flow: Express app using OAuth2.0 authorization code flow to acquire a token and store in the token cache, and silent flow to use tokens in the token cache.
client-credentials: Daemon app using OAuth 2.0 client credential grant to acquire a token.
on-behalf-of: Web application using OAuth 2.0 auth code flow to acquire a token for a web API. The web API validates the token, and calls Microsoft Graph on behalf of the user who authenticated in the web application.
username-password: Web application using OAuth 2.0 resource owner password credentials (ROPC) flow to acquire a token for a web API.
ElectronTestApp: Electron desktop application using OAuth 2.0 auth code with PKCE flow to acquire a token for a web API such as Microsoft Graph.
Hybrid Spa Sample: Sample demonstrating how to use enableSpaAuthorizationCode to perform SSO for applications that leverage server-side and client-side authentication using MSAL Browser and MSAL Node.