Azure Active Directory modules for Node.js



We strongly recommend that you use Microsoft Graph instead of Azure AD Graph API to access Azure Active Directory resources. Our development efforts are now concentrated on Microsoft Graph and no further enhancements are planned for Azure AD Graph API. There are a very limited number of scenarios for which Azure AD Graph API might still be appropriate; for more information, see the Microsoft Graph or the Azure AD Graph blog post in the Office Dev Center.

The Azure Active Directory Authentication Library (ADAL) for Node.js enables Node.js applications to authenticate to AAD 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


This example from the client credentials sample illustrates server-to-server authentication via client credentials.

const adal = require('adal-node').AuthenticationContext;

const authorityHostUrl = '';
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);

  (err, tokenResponse) => {
    if (err) {
      console.log(`Token generation failed due to ${err}`);
    } else {
      console.dir(tokenResponse, { depth: null, colors: true });


Azure Active Directory
Securing a web API with Azure AD A NodeJS web API that is secured using Azure AD and OAuth 2.0 access tokens.
Integrating Azure AD into a NodeJS web application A NodeJS web application that authenticates Azure AD users with OpenID Connect.

For more code samples that use various Azure packages, explore the Node.JS samples.