Azure Active Directory-moduler för Node.js

Översikt

Viktigt

ADAL håller på att bli inaktuell. Vi rekommenderar att du använder Microsoft Authentication Library (MSAL) och Microsoft Graph API i din programutveckling i stället.

Mer information finns i följande resurser:

Med Azure Active Directory Authentication Library (ADAL) för Node.js kan Node.js program autentisera till Azure AD för att få åtkomst till AAD-skyddade webbresurser.

Klientpaketet

Installera npm-modulerna

Använd npm för att installera Azure Storage-klienten eller hanteringsmodulerna.

npm install adal-node

Exempel

Det här exemplet från exemplet med klientautentiseringsuppgifter illustrerar server-till-server-autentisering via klientautentiseringsuppgifter.

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 });
    }
  }
);

Andra exempel

Om du vill ha fler kodexempel som använder olika Azure-paket kan du utforska deNode.js exemplen.