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

> Correlation ID を使用して認証フロー内のイベントを追跡する方法について説明します。

# Correlation ID を設定

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="Correlation ID" stage="ea" terms="true" contact="Auth0サポートまたは担当のテクニカルアカウントマネージャー" />

<Card title="前提条件">
  `correlation_id` を使用するには、次の条件を満たしている必要があります。

  * **Auth0 の Universal Login が設定されていること**: Correlation ID は Universal Login フローで利用できます。
  * **一意の ID を生成できるアプリケーションがあること**: アプリケーションは UUID またはトランザクション ID を生成できる必要があります。 (例: `txn_12345_xyz`、セッション ID、注文 ID)

  <Callout icon="file-lines" color="#0EA5E9" iconType="regular">
    認可リクエストで `correlation_id` を使用できない場合は、テナントでこの機能が有効になっていない可能性があります。
  </Callout>
</Card>

Auth0 では、Correlation ID を使用して認証トランザクションを追跡できます。この追跡機能により、サポート対応時間を短縮し、認証イベントの後続にある複数のシステムにまたがって追跡できるようになります。

`correlation_id` パラメーターは、アプリケーションが生成した一意の識別子を認可 URL に追加します。この ID は自動的に記録されるため、[Auth0 テナントログ](/ja/docs/deploy-monitor/logs) でイベントを追跡および絞り込みできます。

Correlation ID は、次のイベント全体で保持されます。

* サインアップ
* ログイン
* Multi-Factor Authentication (MFA) の登録とチャレンジ
* パスワードのリセット

Correlation ID は、Universal Login、Universal Login Page Templates、メールテンプレート、SMSテンプレート、カスタムエラーページ、Flows、Auth0 Actions で使用できます。

<div id="configure-correlation-id">
  ## Correlation ID を設定する
</div>

`correlation_id` の値には、次の制限があります。

* **使用できる文字**: `/^[-\w.*~@+/:]{1,64}$/` に一致する英数字および特殊文字
* **最大長**: 64 文字
* **禁止事項**: 個人を特定できる情報 (PII) を含めないこと

次の例のように、一意の ID を認可 URL に追加するには、`authorizationParams` オブジェクトに `correlation_id` パラメーターを渡します。

```javascript wrap lines theme={null}
const { loginWithRedirect } = useAuth0();
loginWithRedirect({
  authorizationParams: {
    // トラッキング用にURLに "&correlation_id=..." を追加します
    correlation_id: "YOUR_CORRELATION_ID"
  }
});
```

<div id="universal-login">
  ## Universal Login
</div>

すべての Universal Login フローで `correlation_id` がサポートされています。correlation ID の値を `/authorize` エンドポイントに渡すと、認証イベントにより、追跡に使用できる correlation ID を含むテナントログが生成されます。Management API SDK を使用して最新のイベントを取得し、フィルタリングすることで、特定のトランザクションを特定できます。

次のサンプルコールでは、Management API SDK を使用して最新の認証イベントを取得し、その後ローカルでフィルタリングして特定のイベントを特定します。

```javascript wrap lines theme={null}
// 1. Management API を呼び出す（SDK v5 構文）
const { data: logs } = await management.logs.list({
  per_page: 100,
  sort: 'date:-1'
});
// 2. クライアント側で配列をフィルタリングして対象の ID を見つける
const transactionEvents = logs.filter(log =>
  log.references?.correlation_id === "YOUR_CORRELATION_ID"
);
console.log(`Found ${transactionEvents.length} events for this transaction.`);
```

<div id="login-page-template">
  ### ログインページテンプレート
</div>

[Universal Login Page Templates](/ja/docs/customize/login-pages/universal-login/customize-templates) を使用してログインエクスペリエンスをカスタマイズする場合は、カスタムログインの認証イベントを追跡できるよう、テンプレートに `correlation_id` を追加します。

次のサンプルは、`{%- auth0:widget -%}` に `correlationId: "{{correlation_id}}"` を追加する例を示しています。

```html wrap lines theme={null}
<!-- 例: IDをクライアントサイドスクリプトに注入する -->
<!-- 注意: {{ }} はAuth0によってサーバーサイドで評価されるLiquidテンプレート構文です。ドキュメントのプレースホルダーではありません -->
<script>
  window.addEventListener("load", function () {
    const loginContext = {
      application: "{{application.name}}",
      // Liquid構文でcorrelation_idに直接アクセスする
      correlationId: "{{correlation_id}}"
    };

    console.log("Tracking Context:", loginContext);
    // loginContext.correlationIdを分析ツールに渡せます
  });
</script>
```

<div id="email-templates">
  ## メールテンプレート
</div>

パスワードのリセットや確認用メールの送信など、メール通知をトリガーした認証イベントを追跡しやすくするために、[メールテンプレート](/ja/docs/customize/email/email-templates/customize-email-templates) に `correlation_id` を含めることができます。

次のサンプルは、メールテンプレートの本文に `{{correlation_id}}` を追加した例です。

```liquid wrap lines theme={null}
<p>If you did not initiate this request, please ignore this email.</p>
<p>Tracking reference: {{correlation_id}}</p>
```

<div id="sms-templates">
  ## SMSテンプレート
</div>

MFA チャレンジなど、SMS 通知をトリガーする認証イベントを追跡するために、[SMSテンプレート](/ja/docs/customize/phone-messages/phone-templates) に `correlation_id` を含めることができます。

次のサンプルは、SMSテンプレートに `{{correlation_id}}` を追加した例です。

```liquid wrap lines theme={null}
Your verification code is: {{code}}. Ref: {{correlation_id}}
```

<div id="custom-error-pages">
  ## カスタムエラーページ
</div>

[カスタムエラーページ](/ja/docs/customize/login-pages/custom-error-pages) に `correlation_id` を含めると、追跡用の参照 ID をエラーページに直接表示できます。これにより、ユーザーは問題を報告しやすくなり、サポートチームも失敗したトランザクションを追跡しやすくなります。

次のサンプルは、カスタムエラーページのテンプレートに `{{correlation_id}}` を追加した例です。

```liquid wrap lines theme={null}
<h1>{{error | escape}}: {{error_description | escape}}</h1>
<p>If you need support, reference this ID: {{correlation_id}}</p>
```

<div id="auth0-actions">
  ## Auth0 Actions
</div>

Auth0 Actions の [Signup and Login Triggers](/ja/docs/customize/actions/explore-triggers/signup-and-login-triggers) では、`event` オブジェクトを使用してイベントをサードパーティサービスにログとして記録したり、ダウンストリーム API に渡したりできます。

次のイベントオブジェクトでは `correlation_id` を利用できます。

* [ユーザー登録前](/ja/docs/customize/actions/explore-triggers/signup-and-login-triggers/pre-user-registration-trigger/pre-user-registration-event-object)
* [ログイン後](/ja/docs/customize/actions/explore-triggers/signup-and-login-triggers/login-trigger/post-login-event-object)
* [チャレンジ後](/ja/docs/customize/actions/explore-triggers/password-reset-triggers/post-challenge-trigger/post-challenge-event-object)
* [パスワード変更後](/ja/docs/customize/actions/explore-triggers/password-reset-triggers/post-change-password-trigger/post-change-password-event-object)
* [カスタムメールプロバイダー](/ja/docs/customize/email/smtp-email-providers/custom/action-triggers-custom-email-provider-event-object)
* [カスタム電話番号プロバイダー](/ja/docs/customize/phone-messages/configure-phone-messaging-providers/configure-a-custom-phone-provider/actions-triggers-custom-phone-provider-event-object)
* [MFA Notification send-phone-message](/ja/docs/customize/actions/explore-triggers/mfa-notifications-trigger/send-phone-message-event-object)
* [認証情報交換](/ja/docs/customize/actions/explore-triggers/machine-to-machine-trigger/credentials-exchange-event-object)

サンプルの Post-Login Action では、`event` オブジェクトから `correlation_id` を抽出する方法を示しています。

```javascript wrap lines theme={null}
exports.onExecutePostLogin = async (event, api) => {
  console.log('PostLogin Action Start');
  const correlation_id = event.transaction?.correlation_id;
  // correlation_idが存在するか確認
  if (correlation_id) {
    console.log(`Correlation ID found: ${correlation_id}`);
  } else {
    console.log('No correlation_id found in transaction');
  }
  console.log('PostLogin Action End');
};
```

<div id="forms">
  ## Forms
</div>

Forms と Flows では Correlation ID を使用できます。Forms では、Flows で作成したカスタムロジックを使って、サインアップとログインをカスタマイズできます。Forms と Flows で Correlation ID を使用するには、Flows エディターで `context` オブジェクトを使用し、関連イベント変数 `{{context.transaction.correlation_id}}` をロジックに追加します。詳細については、[変数とヘルパー関数](/ja/docs/customize/forms/variables)を参照してください。
