Skip to content

About

A chapterwise tutorial that will take you through the fundamentals of modern authentication with the Microsoft identity platform in Node.js using MSAL Node

Topics

Resources

Code of conduct

Contributing

Stars

49 stars

Watchers

32 watching

Forks

Repository files navigation

page_type sample
languages
javascript
typescript
products
node-js
ms-graph
msal-node
azure-app-service
azure-key-vault
azure-resource-manager
microsoft-entra-id
microsoft-identity-platform
description Tutorial: Enable your Node.js & Express web app to sign-in users and call APIs with the Microsoft identity platform
urlFragment ms-identity-javascript-nodejs-tutorial

Tutorial: Enable your Node.js & Express web app to sign-in users and call APIs with the Microsoft identity platform

Build Code Scan GitHub issues npm GitHub

The Microsoft identity platform and Microsoft Entra ID are central to the Azure cloud ecosystem. This tutorial aims to take you through the fundamentals of modern authentication with Node.js, using the Microsoft Authentication Library for Node.js (MSAL Node).

This tutorial also features a simple wrapper around MSAL Node ConfidentialClientApplication class in order to streamline routine authentication tasks such as login, logout, token acquisition. You can find the wrapper here: msal-node-wrapper. Fork it and customize as you need. Suggestions and contributions are welcome!

⚠️ msal-node-wrapper is for demo purposes only and is not recommended for production applications. If you're looking for using MSAL Node directly in your web app, please refer to:

For new basic sign-in and Microsoft Graph implementations, start with ms-identity-node, which uses MSAL Node directly. Chapters 1 and 2 remain available as legacy, wrapper-based prerequisites for the deployment and access-control chapters in this tutorial.

We recommend following the chapters in successive order. However, the code samples are self-contained, so feel free to pick samples by topics that you may need at the moment.

⚠️ This is a work in progress. Come back frequently to discover more samples.

Prerequisites

Please refer to each chapter's README for sample-specific prerequisites.

Recommendations

Please refer to each chapter's README for sample-specific recommendations.

Contents

Chapter 1: Add Authentication to your web app

Sign-in with Microsoft Entra ID (legacy tutorial prerequisite)
Sign-in your users with Microsoft Entra ID and learn to work with ID Tokens. For new applications, use ms-identity-node.

Chapter 2: Sign-in a user and get an Access Token for Microsoft Graph

Get an Access Token from Microsoft Entra ID and call Microsoft Graph (legacy tutorial prerequisite)
Authenticate your users and acquire an Access Token for Microsoft Graph. For new applications, use ms-identity-node.

Chapter 3: Deploy your app to Azure

Deploy to Azure App Service
Prepare your app for deployment to various Azure services. Learn how to package and upload files, configure authentication parameters and use Azure services for managing your operations.

Chapter 4: Control access to your app using App Roles and Security Groups

Use App Roles for access control
Define App Roles and use roles claim in a token to implement Role-based Access Control (RBAC) for your web app.
Use Security Groups for access control
Create Security Groups and use groups claim in a token to implement Role-based Access Control (RBAC) for your web app.

Chapter 5: Dive into advanced scenarios

Authenticate using Backend for Frontend proxy
Sign-in users via the Backend for Frontend proxy pattern in a React SPA hosted on top of a Node.js & Express web app using MSAL Node.

We'd love your feedback

Were we successful in addressing your learning objective? Consider taking a moment to share your experience with us.

More information

Learn more about the Microsoft identity platform:

See more code samples:

Community Help and Support

Use Stack Overflow to get support from the community. Ask your questions on Stack Overflow first and browse existing issues to see if someone has asked your question before. Make sure that your questions or comments are tagged with [ms-identity azure-ad msal node].

If you find a bug in the sample, please raise the issue on GitHub Issues.

To provide a recommendation, visit the following User Voice page.

Contributing

This project welcomes contributions and suggestions. Most contributions require you to agree to a Contributor License Agreement (CLA) declaring that you have the right to, and actually do, grant us the rights to use your contribution. For details, visit https://cla.opensource.microsoft.com.

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.

Appendix: Archived Azure AD B2C sample

The Azure AD B2C sign-in scenario has been removed from the active tutorial and is no longer maintained. Its last version remains available for reference on the archive/azure-ad-b2c branch:

About

A chapterwise tutorial that will take you through the fundamentals of modern authentication with the Microsoft identity platform in Node.js using MSAL Node

Topics

Resources

Code of conduct

Contributing

Stars

49 stars

Watchers

32 watching

Forks

Releases

Used by

Contributors

Languages