> ## Documentation Index
> Fetch the complete documentation index at: https://docs-dev-feat-init-gt-translations.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

> Active Directory ドメイン コントローラーの作成方法とテスト方法について説明します。

# AD/LDAP Connector のテスト環境を設定する

export const AuthCodeBlock = ({filename, icon, language, highlight, children}) => {
  const [displayText, setDisplayText] = useState(children);
  const [copyText, setCopyText] = useState(children);
  const wrapperRef = React.useRef(null);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      if (!window.autorun || !window.rootStore) {
        return;
      }
      unsubscribe = window.autorun(() => {
        let processedChildrenForDisplay = children;
        let processedChildrenForCopy = children;
        for (const [key, value] of window.rootStore.variableStore.values.entries()) {
          const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
          let displayValue = value;
          if (key === "{yourClientSecret}" && value !== "{yourClientSecret}") {
            displayValue = value.substring(0, 3) + "*****MASKED*****";
          }
          processedChildrenForDisplay = processedChildrenForDisplay.replaceAll(new RegExp(escapedKey, "g"), displayValue);
          processedChildrenForCopy = processedChildrenForCopy.replaceAll(new RegExp(escapedKey, "g"), value);
        }
        setDisplayText(processedChildrenForDisplay);
        setCopyText(processedChildrenForCopy);
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  useEffect(() => {
    if (!wrapperRef.current) return;
    const originalWriteText = navigator.clipboard.writeText.bind(navigator.clipboard);
    let isOverriding = false;
    const handleClick = e => {
      const button = e.target.closest('[data-testid="copy-code-button"]');
      if (!button || !wrapperRef.current.contains(button)) return;
      isOverriding = true;
      navigator.clipboard.writeText = text => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
          return originalWriteText(copyText);
        }
        return originalWriteText(text);
      };
      setTimeout(() => {
        if (isOverriding) {
          isOverriding = false;
          navigator.clipboard.writeText = originalWriteText;
        }
      }, 100);
    };
    const wrapper = wrapperRef.current;
    wrapper.addEventListener('click', handleClick, true);
    return () => {
      wrapper.removeEventListener('click', handleClick, true);
      if (navigator.clipboard.writeText !== originalWriteText) {
        navigator.clipboard.writeText = originalWriteText;
      }
    };
  }, [copyText]);
  return <div ref={wrapperRef}>
      <CodeBlock filename={filename} icon={icon} language={language} lines highlight={highlight}>
        {displayText}
      </CodeBlock>
    </div>;
};

export const codeExample = `https://{yourDomain}/authorize?response_type=token&scope=openid%20profile&client_id={yourClientId}&redirect_uri=http%3A%2F%2Fjwt.io&connection=auth0-test-ad`;

クラウド上にデプロイした仮想マシン (VM) に最小構成の AD Domain Controller をインストールすることで、テスト環境を構築できます。VM は任意のクラウドプラットフォームで実行できます。この例では、Microsoft Azure 上での設定方法を示します。

1. [Azure Management](https://azure.microsoft.com/en-us/features/azure-portal/) コンソールで仮想マシンを作成します。
2. 新しい VM の **ENDPOINTS** タブをクリックし、**Remote Desktop** エンドポイントの **PUBLIC PORT** を控えます。
3. Microsoft Remote Desktop クライアント (Windows または Mac) またはお好みのクライアント (Linux システム用の [rdesktop](http://www.rdesktop.org/) など) を開きます。VM への新しい接続を作成します。
4. 接続を開き、Remote Desktop クライアントに表示される証明書の警告は無視します。ローカル ネットワーク上の PC、デバイス、コンテンツを検出するかどうかを求められた場合は、**No** を選択します。
5. Windows タスク バーの PowerShell アイコンをクリックして **PowerShell Command Prompt** を開きます。ADDS をインストールします。
6. サーバーを、`mycompany.local` という FQDN を管理するドメイン コントローラーに昇格させます。
7. **SafeModeAdministratorPassword** の入力を求められたら、VM の作成時に使用した Administrator パスワードを入力します。Enter キーを押して続行します。昇格スクリプトが実行され、VM は自動的に再起動します。
8. テスト用のグループとユーザーを追加します。Remote Desktop クライアントを使って VM にログインし、PowerShell Command Prompt を開きます。次のスクリプトを実行します。

   ```text lines theme={null}
   > New-ADGroup -Name "Accounting" -GroupScope "DomainLocal"
   > New-ADGroup -Name "IT" -GroupScope "DomainLocal"

   > New-ADUser -GivenName Bob -Surname Johnson -Name "Bob Johnson" -SamAccountName bob.johnson -Enabled $True -AccountPassword (ConvertTo-SecureString "Pass@word1!" -AsPlainText -force) -PasswordNeverExpires $True
   > New-ADUser -GivenName Mary -Surname Smith -Name "Mary Smith" -SamAccountName mary.smith -Enabled $True -AccountPassword (ConvertTo-SecureString "Pass@word1!" -AsPlainText -force) -PasswordNeverExpires $True

   > Add-ADGroupMember -Identity Accounting -Members "bob.johnson", "mary.smith"
   > Add-ADGroupMember -Identity IT -Members "mary.smith"
   ```

<h2 id="install-and-configure-adldap-connector">
  AD/LDAP Connector をインストールして設定する
</h2>

1. [Auth0 Dashboard > Authentication > Enterprise](https://manage.auth0.com/#/connections/enterprise) に移動し、`auth0-test-ad` という名前の新しい **Active Directory/LDAP** 接続を作成します。手順の最後で生成される **Ticket URL** は、必ずコピーしておいてください。
2. VM で **Internet Explorer Enhanced Security Configuration** を無効にします。
3. 手順 1 で保存した **Ticket URL** を使って **Internet Explorer** を開きます。
4. ブラウザーの指示に従って **Connector** をダウンロード、インストール、設定します。LDAP サービスアカウントの入力を求められたら、VM 用に作成した管理者アカウントを使用します: **Username**: `mycompany\ad-admin,` **Pas**sword:  (前と同じ) 。
5. Connector の設定とインストールが完了したら、サーバーを再起動します。
6. Remote Desktop を使って VM に再度ログインします。
7. `http://localhost:8357/` にアクセスして Connector の設定サイトを開きます。
8. **Connector** がユーザーを見つけられることを確認します。

   1. **Search** タブをクリックします。
   2. 「Find User by Login」に `mary.smith` と入力します。
   3. **Search** をクリックします。そのユーザーの AD プロファイルデータを含む JSON が返されるはずです:

<h2 id="test-authentication-from-auth0">
  Auth0 から認証をテストする
</h2>

Auth0 アカウントを使用してすべてが正しく動作していることを確認するため、Auth0 で **Default App** が新しい **Active Directory / LDAP** 接続を使用するように設定し、`/authorize` endpoint を使って認証フローを開始します。

1. [Auth0 Dashboard > Applications > Applications](https://manage.auth0.com/#/applications) に移動します。

2. **Default App** の **Settings** アイコンをクリックします。

3. アプリケーションの **Allowed Callback URLs** の一覧に `http://jwt.io` を追加します。

4. **Connections** タブをクリックします。

5. **Enterprise** で、`auth0-test-ad` の **Active Directory / LDAP** 接続を有効にします。

6. 次のリンクをブラウザーで開き、認証フローをテストします。

   <AuthCodeBlock children={codeExample} language="http" />

7. ディレクトリで作成されたテストユーザーのいずれかでログインします。

   * ユーザー名: `mary.smith` または `bob.johnson`
   * パスワード: `Pass@word1!`

8. すべてが正しく動作していれば、JWT.io の Web サイトにリダイレクトされ、生成された JWT の内容を確認できます。
