page_type | languages | products | description | urlFragment | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
sample |
|
|
Tutorial: Enable your Node.js & Express web app to sign-in users and call APIs with the Microsoft identity platform |
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
The Microsoft identity platform, along with Microsoft Entra ID (Microsoft Entra ID) and Azure Active Directory B2C (Azure Active Directory B2C) 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:
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.
- Node.js (>= v16.x)
- Express.js (>= v4.x)
- Visual Studio Code
- VS Code Azure Tools Extension
- A modern web browser
Please refer to each chapter's README for sample-specific prerequisites.
- jwt.ms for inspecting your tokens
- Fiddler for monitoring your network activity and troubleshooting
- Check the MSAL Node FAQ for your questions first
- Follow the Microsoft Entra ID Blog to stay up-to-date with the latest developments
Please refer to each chapter's README for sample-specific recommendations.
Sign-in with Microsoft Entra ID Sign-in your users with Microsoft Entra ID and learn to work with ID Tokens. |
|
Sign-in with Azure Active Directory B2C Sign-in your customers with Azure Active Directory B2C. Learn to integrate with external social identity providers. Learn how to use user-flows and custom policies. |
Get an Access Token from Microsoft Entra ID and call Microsoft Graph Authenticate your users and acquire an Access Token for Microsoft Graph and then call the Microsoft Graph API. |
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. |
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. |
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. |
Were we successful in addressing your learning objective? Consider taking a moment to share your experience with us.
Learn more about the Microsoft identity platform:
- Microsoft identity platform
- Azure Active Directory B2C
- Overview of Microsoft Authentication Library (MSAL)
- Application types for Microsoft identity platform
- Understanding Microsoft Entra application consent experiences
- Understand user and admin consent
- Application and service principal objects in Microsoft Entra ID
- Microsoft identity platform best practices and recommendations
See more code samples:
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
azure-ad-b2c
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.
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.
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.