> ## 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": "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 のグループ向けディレクトリ同期" stage="ea" terms="true" />

[Google Workspace エンタープライズ接続](/docs/ja-jp/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 organization の管理者権限
      </Step>

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

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

        * ユーザーのみにアクセスする scope を追加する場合は **Users scopes**

        * ユーザーとグループの両方にアクセスする scope を追加する場合は **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 Workspace の設定を構成して Google の Admin API を使用するための管理者権限がある場合は、**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 organization に対する管理者権限。

        * 次の scopes を持つ [Management API access token](/docs/ja-jp/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 を有効にする">
        [Create a connection endpoint](https://auth0.com/docs/api/management/v2/connections/post-connections) (`POST /v2/connections`) を使用して新しい Google Workspace エンタープライズ接続を作成する場合、または [Update a connection endpoint](https://auth0.com/docs/api/management/v2/connections/patch-connections-by-id) (`PATCH /v2/connections/{id}`) を使用して既存のエンタープライズ接続を変更する場合は、次のボディパラメーターを設定します:

        * ユーザーにアクセスするための scopes を追加するには、`option.api_enable_users` を `true` に設定します。
        * グループにアクセスするための scopes も追加するには、`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 Workspace の設定を構成して Google の Admin APIs を使用するための管理者権限がある場合は、**Continue** リンクをクリックします。または

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

      <Step title="Directory Sync を有効にする">
        [Create a directory provisioning configuration endpoint](https://auth0.com/docs/api/management/v2/connections/post-directory-provisioning) (`POST /v2/connections/{id}/directory-provisioning`) を使用して Directory Sync を有効にするか、[Patch a directory provisioning configuration endpoint](https://auth0.com/docs/api/management/v2/connections/patch-directory-provisioning) (`PATCH /v2/connections/{id}/directory-provisioning`) を使用して既存の Directory Sync 設定を更新し、次のリクエストボディパラメーターを使用します:

        * Google 属性から Auth0 のユーザープロファイル属性へのマッピングを定義するには、`mapping` を使用します。

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

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

        指定したグループだけを同期する場合は、追加で同期するグループを指定する必要があります。

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

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

        手動で同期を実行するには、[Create a directory provisioning configuration endpoint](https://auth0.com/docs/api/management/v2/connections/post-synchronizations) を使用します。
      </Step>
    </Steps>
  </Tab>
</Tabs>

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

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

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

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

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

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

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