Node.js 用 Azure Active Directory モジュール

概要

重要

ADAL は非推奨になっています。 代わりに、アプリケーション開発で Microsoft 認証ライブラリ (MSAL) と Microsoft Graph APIを使用することをお勧めします。

詳細については、次のリソースを参照してください。

Node.js用 Azure Active Directory 認証ライブラリ (ADAL) を使用すると、Node.jsアプリケーションは、AAD で保護された Web リソースにアクセスするために Azure AD に対する認証を行うことができます。

クライアント パッケージ

npm モジュールのインストール

Azure Storage クライアントまたは管理モジュールをインストールするには npm を使用します。

npm install adal-node

例

この例は、クライアント資格情報サンプルからの抜粋で、クライアントの資格情報を使ってサーバー間の認証を行います。

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

その他のサンプル

さまざまな Azure パッケージを使用するその他のコード サンプルについては、 Node.jsサンプルを参照してください。