Azure Active Directory modules for Node.js
Overview
Important
ADAL is being deprecated. We recommend that you use the Microsoft Authentication Library (MSAL) and the Microsoft Graph API in your application development instead.
For more info, see these resources:
- Code samples for your platform - Microsoft identity platform code samples.
- Migration guidance - Migrate to MSAL.js and Migrate Azure AD Graph apps to Microsoft Graph.
The Azure Active Directory Authentication Library (ADAL) for Node.js enables Node.js applications to authenticate to Azure AD in order to access AAD protected web resources.
Client package
Install the npm modules
Use npm to install the Azure storage client or management modules.
npm install adal-node
Example
This example from the client credentials sample illustrates server-to-server authentication via client credentials.
const adal = require('adal-node').AuthenticationContext;
const authorityHostUrl = 'https://login.windows.net';
const tenant = 'your-tenant-id';
const authorityUrl = authorityHostUrl + '/' + tenant;
const clientId = 'your-client-id';
const clientSecret = 'your-client-secret';
const resource = 'your-app-id-uri';
const context = new adal(authorityUrl);
context.acquireTokenWithClientCredentials(
resource,
clientId,
clientSecret,
(err, tokenResponse) => {
if (err) {
console.log(`Token generation failed due to ${err}`);
} else {
console.dir(tokenResponse, { depth: null, colors: true });
}
}
);
Other samples
For more code samples that use various Azure packages, explore the Node.js samples.
Azure SDK for JavaScript