> ## 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.

> 一貫したユーザー体験を提供するために、テナントでデフォルトのカスタムドメインを設定する方法を紹介します。

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

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) + "*****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>;
};

[複数のカスタムドメイン](/docs/ja-jp/customize/custom-domains/multiple-custom-domains) が Auth0 テナントに設定されている場合、そのうち 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`) をデフォルトのカスタムドメインとして設定できます。テナントには、常に 1 つのデフォルトのカスタムドメインが設定されます。

<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** > **Branding > 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 {
      // Handle error
  }

  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](/docs/ja-jp/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連携](/docs/ja-jp/customize/custom-domains/multiple-custom-domains/actions-integration)を参照してください。

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

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

* **安定したドメインを選ぶ**: デフォルトには、頻繁に変更する必要のない安定したドメインを選択します
* **設定前に確認する**: デフォルトに設定する前に、そのドメインが完全に検証され、正常に動作していることを確認します
* **決定内容を文書化する**: 今後参照できるように、特定のドメインをデフォルトとして選んだ理由を記録します
* **メール関連のフローをテストする**: デフォルトドメインを設定した後は、パスワードリセットフローとメールアドレス確認フローをテストします
* **トークンの発行元を確認する**: デフォルトを設定した後、トークンに想定どおりの `iss` claim が含まれていることを確認します
* **マルチブランド構成を考慮する**: 複数のブランドを提供している場合は、デフォルトとして汎用的なドメインまたは管理用ドメインを選択します
* **連携設定を更新する**: 適切な連携設定が行えるよう、デフォルトドメインについてチームに周知します

<div id="learn-more">
  ## さらに詳しく
</div>

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