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

> Auth0 でデフォルトのカスタムドメインを設定して使用する方法について説明します。

# デフォルトのカスタムドメイン

export const AuthCodeGroup = ({children, dropdown}) => {
  const [processedChildren, setProcessedChildren] = useState(children);
  useEffect(() => {
    let unsubscribe = null;
    function init() {
      unsubscribe = window.autorun(() => {
        const processChildren = node => {
          if (typeof node === "string") {
            let processedNode = node;
            for (const [key, value] of window.rootStore.variableStore.values.entries()) {
              const escapedKey = key.replaceAll(/[.*+?^${}()|[\]\\]/g, (String.raw)`\$&`);
              processedNode = processedNode.replaceAll(new RegExp(escapedKey, "g"), value);
            }
            return processedNode;
          } else if (Array.isArray(node)) {
            return node.map(processChildren);
          } else if (node && node.props && node.props.children) {
            return {
              ...node,
              props: {
                ...node.props,
                children: processChildren(node.props.children)
              }
            };
          }
          return node;
        };
        setProcessedChildren(processChildren(children));
      });
    }
    if (window.rootStore) {
      init();
    } else {
      window.addEventListener("adu:storeReady", init);
    }
    return () => {
      window.removeEventListener("adu:storeReady", init);
      unsubscribe?.();
    };
  }, [children]);
  return <CodeGroup dropdown={dropdown}>{processedChildren}</CodeGroup>;
};

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) + "*****マスク済み*****";
          }
          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>;
};

Auth0テナントに[複数のカスタムドメイン](/ja/docs/customize/custom-domains/multiple-custom-domains)が設定されている場合は、そのうちの 1 つを**デフォルトのカスタムドメイン**として指定できます。デフォルトドメインを設定すると、カスタムドメインが明示的に指定されていない場合でも、設定が簡素化され、一貫したユーザーエクスペリエンスを確保できます。

<div id="what-is-a-default-custom-domain">
  ## デフォルトのカスタムドメインとは何ですか？
</div>

デフォルトのカスタムドメインとは、Auth0 が次の用途で自動的に使用するカスタムドメインです。

* **メールおよび電話番号を使った通知**: 特定のカスタムドメインが指定されていない場合に、パスワードリセットメール、メールアドレス確認リンク、その他の Auth0 によって生成される通知の送信に使用されます。これには、認証中に通知が送信されるケースも含まれます。
* **Management API 呼び出し**: `auth0-custom-domain` ヘッダーなしで通知を発生させる API リクエストを処理する場合

正規のテナントドメイン (`YOUR_TENANT.auth0.com` または `YOUR_TENANT.REGION.auth0.com`) をデフォルトのカスタムドメインとして設定できます。テナントには、常にデフォルトのカスタムドメインが設定されます。

<div id="benefits-of-setting-a-default-domain">
  ## デフォルトドメインを設定する利点
</div>

デフォルトのカスタムドメインを設定すると、次のような利点があります。

* **設定の簡素化**: すべての Management API 呼び出しや設定で、カスタムドメインを毎回指定する必要がなくなります
* **一貫したブランディング**: 特定のドメインが指定されていない場合でも、ユーザーに常に自社ブランドを表示できます
* **`auth0-custom-domain` ヘッダーの任意化**: Management API リクエストでカスタムドメインヘッダーの指定が任意になります
* **フォールバック動作**: マルチブランドまたはマルチテナントの実装で、適切なデフォルト動作を提供します
* **移行の容易化**: 単一のカスタムドメインから複数のカスタムドメインへの移行を簡素化します

<div id="configure-a-default-domain">
  ## デフォルトドメインを設定する
</div>

Auth0 Dashboard または Management API を使用して、デフォルトのカスタムドメインを設定できます。

<div id="using-the-auth0-dashboard">
  ### Auth0 Dashboard を使用する
</div>

Auth0 Dashboard でデフォルトのカスタムドメインを設定するには、次の手順を実行します。

1. **Auth0 Dashboard** > **ブランディング > Custom Domains** に移動します
2. 一覧から、デフォルトに設定する検証済みのカスタムドメインを探します
3. 対象のドメインの **Set as Default** ボタンをクリックします
4. 表示されたダイアログで操作を確定します

設定後、そのドメインにはカスタムドメイン一覧で "Default" バッジが表示されます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  デフォルトに設定できるのは、検証済みのカスタムドメインのみです。デフォルトとして指定する前に、カスタムドメインが完全に検証され、有効になっていることを確認してください。
</Callout>

<div id="using-the-management-api">
  ### Management API を使用する
</div>

Management API でデフォルトのカスタムドメインを設定するには、`PATCH /api/v2/custom-domains/default` エンドポイントを使用します。

<AuthCodeGroup>
  ```bash cURL theme={null}
  curl --request PATCH \
    --url 'https://{yourDomain}/api/v2/custom-domains/default' \
    --header 'authorization: Bearer {yourMgmtApiAccessToken}' \
    --header 'content-type: application/json' \
    --data '{
      "domain": "my-custom-domain.com"
    }'
  ```

  ```javascript Node.js theme={null}
  import { ManagementClient } from "auth0";

  const management = new ManagementClient({
    domain: '{yourDomain}',
    clientId: '{yourClientId}',
    clientSecret: '{yourClientSecret}',
  });

  await management.customDomains.setDefault({
    domain: 'my-custom-domain.com',
  });
  ```

  ```python Python theme={null}
  from auth0.management import ManagementClient

  client = ManagementClient(
      domain='{yourDomain}',
      client_id='{yourClientId}',
      client_secret='{yourClientSecret}',
  )

  client.custom_domains.set_default({
      'domain': 'my-custom-domain.com',
  })
  ```

  ```go Go theme={null}
  import (
      "context"
      "github.com/auth0/go-auth0/v2/management"
      management_client "github.com/auth0/go-auth0/v2/management/client"
      "github.com/auth0/go-auth0/v2/management/option"
  )

  mgmt, err := management_client.New(
      "{yourDomain}",
      option.WithClientCredentials("{yourClientId}", "{yourClientSecret}"),
  )
  if err != nil {
      // エラーを処理
  }

  err = mgmt.CustomDomains.SetDefault(context.Background(), &management.SetDefaultCustomDomainRequestContent{
      Domain: "my-custom-domain.com",
  })
  ```

  ```java Java theme={null}
  import com.auth0.client.mgmt.ManagementAPI;
  import com.auth0.json.mgmt.customdomains.SetDefaultCustomDomainRequest;

  ManagementAPI mgmt = ManagementAPI.newBuilder(
      "{yourDomain}",
      "{yourMgmtApiAccessToken}"
  ).build();

  SetDefaultCustomDomainRequest request = new SetDefaultCustomDomainRequest("my-custom-domain.com");

  mgmt.customDomains()
      .setDefault(request)
      .execute();
  ```
</AuthCodeGroup>

<div id="remove-default-domain-designation">
  ## デフォルトドメイン指定を削除する
</div>

カスタムドメインからデフォルト指定を削除するには、次のいずれかを実行します。

1. 別のカスタムドメインをデフォルトに設定する (同時にデフォルトに設定できるドメインは 1 つだけです) 、または
2. Management API を使用して、現在のデフォルトドメインの `is_default` を `false` に設定する

デフォルトに設定されたカスタムドメインがない場合、Auth0 は正規のテナントドメインを使用します。

<div id="how-the-default-domain-is-used">
  ## デフォルトドメインの用途
</div>

<div id="email-notifications">
  ### メール通知
</div>

Auth0 がメール通知 (パスワードリセット、メールアドレス確認、ウェルカムメール) を送信する際、これらの通知内のリンクやカスタマイズにはデフォルトドメインが使用されます。メールテンプレートをカスタマイズすることで、"From" アドレス、件名、メール本文にカスタムドメインの情報を使用できます。

<div id="management-api-endpoints-that-trigger-notifications">
  ### 通知をトリガーする Management API エンドポイント
</div>

デフォルトのカスタムドメインは、メール通知または電話番号通知をトリガーする Management API エンドポイントで使用されます。デフォルトのドメインを設定している場合、これらのエンドポイントでは `auth0-custom-domain` ヘッダーは省略可能です。

**メール通知をトリガーするエンドポイント:**

* `POST /api/v2/tickets/password-change` - パスワードリセットメールを送信します
* `POST /api/v2/tickets/email-verification` - メールアドレス確認メールを送信します
* `POST /api/v2/jobs/verification-email` - ユーザーに確認メールを送信します
* `POST /api/v2/users` - 設定によってはウェルカムメールをトリガーできます
* `PATCH /api/v2/users/{id}` - メールアドレスの更新時に確認メールをトリガーできます

**電話番号通知をトリガーするエンドポイント:**

* `POST /api/v2/users/{id}/phone/verification` - SMS認証の確認コードを送信します

**例:**

<AuthCodeGroup>
  ```bash Without custom domain header (uses default) theme={null}
  # パスワードリセットチケットでは、メール内のリンクにデフォルトドメインが使用されます
  curl --request POST \
    --url 'https://{yourDomain}/api/v2/tickets/password-change' \
    --header 'authorization: Bearer {yourMgmtApiAccessToken}' \
    --header 'content-type: application/json' \
    --data '{
      "user_id": "auth0|123456",
      "result_url": "https://example.com/password-changed"
    }'
  ```

  ```bash With custom domain header (overrides default) theme={null}
  # この通知に別のカスタムドメインを明示的に指定します
  curl --request POST \
    --url 'https://{yourDomain}/api/v2/tickets/password-change' \
    --header 'authorization: Bearer {yourMgmtApiAccessToken}' \
    --header 'auth0-custom-domain: brand-specific.com' \
    --header 'content-type: application/json' \
    --data '{
      "user_id": "auth0|123456",
      "result_url": "https://example.com/password-changed"
    }'
  ```
</AuthCodeGroup>

これらの通知エンドポイントで `auth0-custom-domain` ヘッダーを指定しない場合、Auth0 はメールまたは SMS 内のリンクやカスタマイズに、デフォルトのカスタムドメインを自動的に使用します。`auth0-custom-domain` ヘッダーを含めることで、リクエストごとにこれを上書きできます。

<div id="using-the-default-domain-with-actions">
  ## Actions でデフォルトドメインを使用する
</div>

[Actions](/ja/docs/customize/actions) を使用して、カスタムドメインに応じたロジックを実装します。

```javascript theme={null}
exports.onExecutePostLogin = async (event, api) => {
  const domain = event.custom_domain?.domain;

  // ログインドメインをユーザーメタデータに保存する
  if (domain) {
    api.user.setAppMetadata('login_domain', domain);
  }
};
```

Actions でカスタムドメイン情報を使用する方法の詳細については、[複数のカスタムドメインを使用する Actions の統合](/ja/docs/customize/custom-domains/multiple-custom-domains/actions-integration)を参照してください。

<div id="best-practices">
  ## ベストプラクティス
</div>

デフォルトのカスタムドメインを設定する際は、次のベストプラクティスを参考にしてください。

* **安定したドメインを選択する**: デフォルトとして、頻繁に変更する必要のないドメインを選択します
* **設定前に検証する**: ドメインをデフォルトに設定する前に、検証が完了し、正常に動作していることを確認します
* **決定内容を文書化する**: 将来参照できるよう、特定のドメインをデフォルトとして選択した理由を記録します
* **メールフローをテストする**: デフォルトドメインを設定した後、パスワードリセットとメールアドレス確認のフローをテストします
* **トークンの Issuer を確認する**: デフォルトを設定した後、トークンの `iss` クレームが想定どおりの値であることを確認します
* **複数ブランドのシナリオを想定する**: 複数のブランドを提供している場合は、デフォルトとして汎用ドメインまたは管理用ドメインを選択します
* **統合設定を更新する**: 適切な統合設定を行えるよう、デフォルトドメインについてチームに周知します

<div id="learn-more">
  ## 詳細
</div>

* [複数のカスタムドメイン](/ja/docs/customize/custom-domains/multiple-custom-domains)
* [機能でカスタムドメインを使用するための設定](/ja/docs/customize/custom-domains/configure-features-to-use-custom-domains)
* [カスタムドメインの概要](/ja/docs/customize/custom-domains)
* [メールでカスタムドメインを使用する](/ja/docs/customize/custom-domains/configure-features-to-use-custom-domains#use-custom-domains-in-emails-and-phone-notifications)
* [カスタムドメインとActionsの統合](/ja/docs/customize/actions)
