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

# Directory Sync を使用して Google Workspace のユーザーとグループを Auth0 に同期する

export const ReleaseStageNotice = ({feature, stage, plans, contact, terms}) => {
  const stageTextMap = {
    "beta": "ベータ",
    "ea": "早期アクセス"
  };
  const stageText = stageTextMap[stage] || "製品リリース段階";
  const prsLink = "/docs/troubleshoot/product-lifecycle/product-release-stages";
  const linkify = (text, url) => {
    return <a href={url} target="_blank" rel="noreferrer" class="link">{text}</a>;
  };
  const includeDetails = (plans, contact, terms) => {
    const hasDetails = terms || plans || contact;
    if (!hasDetails) return null;
    return <span data-as="p">
            {plans && <>この機能は、{linkify(`${plans}プラン`, "https://auth0.com/pricing")}で利用できます。 </>}
            {contact && "参加するには、" + contact + " までお問い合わせください。 "}
            {terms && <>この機能を使用すると、Okta の{linkify("Master Subscription Agreement", "https://www.okta.com/legal")}に定める該当する無料トライアル条件に同意したものとみなされます。</>}
        </span>;
  };
  return <Warning>
            <span data-as="p">
                <strong>{feature} 機能は現在、{linkify(stageText, prsLink)}です。</strong>
            </span>

            {includeDetails(plans, contact, terms)}
        </Warning>;
};

<ReleaseStageNotice feature="グループ向け Google Workplace Directory Sync" stage="ea" terms="true" />

[Google Workspace エンタープライズ接続](/ja/docs/authenticate/identity-providers/enterprise-identity-providers/google-apps) で Directory Sync を有効にすると、Google Workspace から Auth0 にユーザープロファイル、グループ構造、グループ メンバーシップを同期できます。

同期は、自動または手動で実行できます。

* 自動同期は、前回の同期が完了してから 30 分ごとに実行されます。

* 手動同期は、実行したときに開始されます。

<div id="enable-directory-sync">
  ## Directory Sync を有効にする
</div>

Auth0 Dashboard または Management API を使用して、Directory Sync を有効にできます。

<Tabs>
  <Tab title="Auth0 Dashboard">
    <Steps>
      <Step title="前提条件">
        開始する前に、次のものが必要です。

        * [Auth0 での Google Workspace エンタープライズ接続](./google-apps)

        * Google Workspace 組織の管理者権限
      </Step>

      <Step title="エンタープライズ接続で Admin Directory API を有効にする">
        ディレクトリ同期を有効にするには、Google Workspace エンタープライズ接続の Google アクセストークンに、Google の API にアクセスするための適切なスコープが含まれている必要があります。

        既存の Google Workspace エンタープライズ接続の **Settings** タブ (または新しい接続の作成時) の **Identity Provider API** セクションで、**Use Admin Directory API** を選択し、次のいずれかを選びます。

        * **Users scopes**: ユーザーにアクセスするためのスコープのみを追加します。

        * **Users and Groups scopes**: ユーザーとグループの両方にアクセスするためのスコープを追加します。

        <Tip>
          Directory Sync を使用する場合は、複数の同期方法による更新の競合を避けるため、このセクションの **Sync User Profile Attributes at Login** も無効にすることをおすすめします。
        </Tip>

        **Save Changes** をクリックします。
      </Step>

      <Step title="Google 管理者の同意を確認する">
        [Auth0 Dashboard > Authentication > Enterprise](https://manage.auth0.com/#/connections/enterprise) から Google Workspace 接続を開きます。**Setup** タブで、次のいずれかを行います。

        * Google の Admin API を使用するよう Google Workspace の設定を構成する管理者権限がある場合は、**Continue** リンクに従います。

        * 必要な設定を管理者が調整できるよう、表示された URL を管理者に共有します
      </Step>

      <Step title="Directory Sync を有効にする">
        接続の **Provisioning** タブで、**Provision Users Using Directory Sync** をオンにして、構成オプションを選択します。

        * **Resources** の **Sync** で、**Users** または **Users and Groups** のどちらを同期するかを選択します。

          ユーザーとグループの両方を同期する場合は、同期対象のグループ (デフォルトでは **Syncing all groups**) が表示されるようにセクションが展開されます。同期するグループをカスタマイズする方法については、次の手順を参照してください。

        * **Schedule** で、必要に応じて **Enable Automatic Synchronization** を選択すると、30 分ごとに自動同期されます。

          **Synchronize now** を選択すると、手動で同期を開始できます。

        * **Attribute Mapping** では、Google の属性から Auth0 のユーザープロファイル属性へのマッピングをカスタマイズできます。
      </Step>

      <Step title="同期するグループをカスタマイズする（任意）">
        Directory Sync を有効にして Google Workspace からユーザーとグループの両方を同期すると、デフォルトですべてのグループが同期されます。同期するグループは、同期対象にしたいグループ ID を含む JSON ファイルをアップロードしてカスタマイズできます。

        まず、JSON ファイルを作成します。[Google Workspace Directory API を使用してすべてのグループ ID の一覧を取得](https://developers.google.com/workspace/admin/directory/reference/rest/v1/groups/list)できます。プレースホルダーの例の値を実際のグループ ID に置き換え、次の形式でファイルを作成します。

        ```json theme={null}
        {
            "groups": [
                {
                    "id": "example-id-1"
                },
                {
                    "id": "example-id-2"
                },
                {
                    "id": "example-id-3"
                }
            ]
        }
        ```

        次に、そのファイルを Auth0 にアップロードします。

        1. 接続の **Provisioning** タブで、有効にした **Provision Users Using Directory Sync** オプションの下にある **Resources** セクションを見つけ、**Select Groups...** ボタンを選択します。

        2. 開いた **Select Groups** ウィンドウで、**Pick specific groups** を選択して **Groups JSON file** セクションを表示します。

        3. **+ Choose file** を選択し、JSON ファイルをアップロードします。

        4. ファイルのアップロード後、ウィンドウ下部の **Select Groups** を選択します。

        **Resources** セクションに **Syncing specific groups** と表示されます。同期するグループを更新するには、同じ **Select Groups** ウィンドウに戻って新しい JSON をアップロードするか、**Sync all** を選択します。

        Google Workspace Directory で同期対象のグループ ID が削除されたことを検出した場合、以降のジョブ同期に向けて、そのグループ ID は設定から自動的に削除されます。
      </Step>
    </Steps>
  </Tab>

  <Tab title="Management API">
    <Steps>
      <Step title="前提条件">
        開始する前に、以下を用意してください。

        * [Auth0 の Google Workspace エンタープライズ接続](./google-apps)

        * Google Workspace 組織の管理者権限。

        * 次のスコープを持つ [Management API アクセストークン](/ja/docs/secure/tokens/access-tokens/management-api-access-tokens#management-api-access-tokens):
          * `create:directory_provisionings`
          * `read:directory_provisionings`
          * `update:directory_provisionings`
          * `delete:directory_provisionings`

        * Google Workspace 接続 ID (`CONNECTION_ID`) 。
      </Step>

      <Step title="エンタープライズ接続で Admin Directory API を有効にする">
        [接続を作成するエンドポイント](https://auth0.com/docs/api/management/v2/connections/post-connections) (`POST /v2/connections`) を使用して新しい Google Workspace エンタープライズ接続を作成する場合、または [接続を更新するエンドポイント](https://auth0.com/docs/api/management/v2/connections/patch-connections-by-id) (`PATCH /v2/connections/{id}`) を使用して既存のエンタープライズ接続を変更する場合は、次のボディパラメーターを設定します。

        * ユーザーにアクセスするためのスコープを追加するには、`option.api_enable_users` を `true` に設定します。
        * グループにアクセスするためのスコープも追加するには、`option.api_enable_groups` を `true` に設定します。グループにアクセスするには、ユーザーへのアクセスも必要です。

        <Tip>
          Directory Sync を使用する場合は、複数の同期方法による更新の競合を避けるため、ログイン時のユーザープロファイル同期 (`options.set_user_root_attributes` を `never_on_login` に設定) を無効にすることを推奨します。
        </Tip>
      </Step>

      <Step title="Google 管理者の同意を確認する">
        [Auth0 Dashboard > Authentication > Enterprise](https://manage.auth0.com/#/connections/enterprise) で Google Workspace 接続を開きます。**Setup** タブで、次のいずれかを行います。

        * Google の Admin APIs を使用するよう Google Workspace の設定を構成できる管理者権限がある場合は、**Continue** リンクをクリックします

        * 必要な設定を調整できるよう、表示された URL を管理者に共有します
      </Step>

      <Step title="Directory Sync を有効にする">
        [ディレクトリプロビジョニング設定を作成するエンドポイント](https://auth0.com/docs/api/management/v2/connections/post-directory-provisioning) (`POST /v2/connections/{id}/directory-provisioning`) を使用して Directory Sync を有効にするか、[ディレクトリプロビジョニング設定を更新するエンドポイント](https://auth0.com/docs/api/management/v2/connections/patch-directory-provisioning) (`PATCH /v2/connections/{id}/directory-provisioning`) を使用して既存の Directory Sync 設定を更新し、次のリクエストボディパラメーターを使用します。

        * `mapping` で、Google の属性を Auth0 ユーザープロファイル属性にどのように対応付けるかを定義します。

        * `synchronize_automatically` を `true` に設定すると 30 分ごとに自動同期し、`false` に設定すると自動同期を無効にします。

        * `synchronize_groups` を次のいずれかに設定します:
          * `all` は、ユーザーに加えてすべてのグループを同期します
          * `selected` は、指定したグループのみを同期します
          * `off` は、ユーザーのみを同期します

        特定のグループのみを同期する場合は、同期対象のグループも指定する必要があります。

        まず、[Google Workspace Directory API を使用してグループ ID の一覧を取得します](https://developers.google.com/workspace/admin/directory/reference/rest/v1/groups/list)。次に、Management API の [同期するグループを設定するエンドポイント](https://auth0.com/docs/api/management/v2/connections/put-synchronized-groups) (`PUT /v2/connections/{id}/directory-provisioning/synchronized-groups`) を使用し、同期するグループのグループ ID を次の形式でリクエストボディパラメーターに指定します。

        ```json theme={null}
        "groups" [
            {
                "id": "example-id-string",
            },
            {
                "id": "example-id-string-2",
            },
            {
                "id": "example-id-string-3",
            }
        ]
        ```

        手動で同期を実行するには、[ディレクトリプロビジョニング設定を作成するエンドポイント](https://auth0.com/docs/api/management/v2/connections/post-synchronizations) を使用します。
      </Step>
    </Steps>
  </Tab>
</Tabs>

<div id="monitor-directory-sync-activity">
  ## Directory Sync アクティビティを監視する
</div>

同期アクティビティは、[Auth0 テナントログ](/ja/docs/deploy-monitor/logs)の **Directory Sync Started** および **Directory Sync Completed** ログタイプ (イベントコード `directory_sync_started` と `directory_sync_completed`) で監視できます。

<div id="limits">
  ## 制限
</div>

* 最後に完了した同期から30分以内に手動で同期すると、400 エラーが返されます。再度同期する前に、少なくとも30分待ってください。

* [ユーザーアカウントリンク](/ja/docs/manage-users/user-accounts/user-account-linking)を使用する場合は、同期でプロビジョニングされたユーザーアカウントをプライマリのユーザーアカウントとして設定する必要があります。Enterprise ユーザーアカウントをソーシャルアカウントや個人用アカウントにリンクすることは推奨しません。

* Google Workspace Directory のグループ名は一意である必要があります。Google では大文字と小文字を区別しない重複名を許可していますが、Auth0 では表示名の一意性を必須としています。Google Workspace Directory に同じ名前のグループが複数ある場合、それらの重複グループは同期されず、同期は失敗としてマークされます。

* Google では、ユーザーの削除後20日以内に限って削除済みとして報告されるため、Google Workspace Directory でユーザーを削除してから20日以内に Auth0 と同期しないと、そのユーザーが削除されたことを検出できません。この問題を回避するため、自動同期を推奨します。
