> ## 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 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="Custom Token Exchange (CTE)" stage="ea" plans="B2C Professional, B2B Professional, and Enterprise" terms="true" />

Custom Token Exchange を使用すると、[RFC 8693](https://datatracker.ietf.org/doc/html/rfc8693) で定義されているとおり、アプリケーションは `/oauth/token` エンドポイントの呼び出し時に、既存のトークンを Auth0 トークンに交換できます。Custom Token Exchange の一般的なユースケースには、次のようなものがあります。

* 別の <Tooltip tip="オーディエンス: 発行されたトークンの対象となる相手を示す一意の識別子です。トークン内では aud という名前で表され、その値には、IDトークンの場合はアプリケーション（クライアントID）の ID、アクセストークンの場合は API（API Identifier）の ID が含まれます。" cta="用語集を表示" href="/ja/docs/glossary?term=audience">オーディエンス</Tooltip> 向けの Auth0 トークンを取得する
* 外部の <Tooltip tip="IDプロバイダー（IdP）: デジタル ID を保存および管理するサービスです。" cta="用語集を表示" href="/ja/docs/glossary?term=identity+provider">IDプロバイダー</Tooltip> と統合する
* Auth0 へ移行する
* 委任された認可: プリンシパル (サービス、AI エージェント、サポート エージェントなど) がユーザーに代わって動作する

詳細については、[Example Use Cases and Code Samples](/ja/docs/authenticate/custom-token-exchange/cte-example-use-cases) を参照してください。

各 Custom Token Exchange リクエストは、[Action](/ja/docs/customize/actions) によって制御される [Custom Token Exchange Profile](/ja/docs/authenticate/custom-token-exchange/configure-custom-token-exchange#create-custom-token-exchange-profile) にマッピングされます。ここでは、次のことを行えます。

* `/oauth/token` エンドポイントに渡される `subject_tokens` をデコードして検証するカスタム コードを記述する
* アクセスを認可し、トランザクションを続行するユーザーを設定する。

アプリケーションには、[複数の Custom Token Exchange Profile を設定](/ja/docs/authenticate/custom-token-exchange/configure-custom-token-exchange#create-custom-token-exchange-profile) できます。Auth0 認可サーバーが、Custom Token Exchange リクエストが有効であり、既存の Custom Token Exchange Profile にマッピングされることを検証すると、[Custom Token Exchange trigger](/ja/docs/customize/actions/explore-triggers/signup-and-login-triggers/custom-token-exchange-trigger) により、そのプロファイルに関連付けられた単一の Action が実行されます。その後、アプリケーションは Custom Token Exchange を利用して認証を行い、ユーザーの Auth0 のアクセストークン、IDトークン、リフレッシュトークンを取得できます。

<Callout icon="file-lines" color="#0EA5E9" iconType="regular">
  Custom Token Exchange では、トランザクションに使用するユーザーを設定できる柔軟性が得られる一方で、そのユーザーを識別する対応する subject token を安全に検証する責任も伴います。

  Custom Token Exchange で使用する subject token と actor token は、Action コードで解釈できる限り、必要に応じて任意のトークン形式やトークンタイプを使用できます。**受け取ったトークンについては、必ず厳格な検証を実装してください。** これを怠ると、なりすましやリプレイ攻撃など、さまざまな攻撃ベクトルにさらされ、不正な第三者が他人のユーザー ID で認証したり、許可なくそのユーザーに代わって行動したりできるようになります。

  subject token の安全な検証を実装するさまざまな方法については、[Example Use Cases and Code Samples](/ja/docs/authenticate/custom-token-exchange/cte-example-use-cases) に記載されている推奨事項を確認し、適用してください。また、[Attack Protection](/ja/docs/authenticate/custom-token-exchange/cte-attack-protection) の機能についても考慮し、適用してください。
</Callout>

<div id="tenant-logs">
  ## テナントログ
</div>

各 Custom Token Exchange トランザクションでは、テナントイベントログが生成されます。

* 成功したトランザクション: `secte` ログ
* 失敗したトランザクション: `fecte` ログ

`setActor()` でアクターが設定されている場合、監査目的で、`sub` とネストされた `actor` を含む `actor` プロパティが `secte` ログエントリに含まれます。

トークン交換で発生した問題のトラブルシューティングには、テナントログを活用してください。

<div id="limitations">
  ## 制限事項
</div>

Custom Token Exchange では、以下はサポートされていません。

* MFA API メソッド `api.authentication.challengeWith()` および `api.authentication.EnrollWith()`
* インポートモードが `ON` の Custom DB Connections は、`setUserByConnection()` 操作ではサポートされません
* サードパーティ製クライアントおよび OIDC 非準拠のクライアント
* 非インタラクティブフローでは同意を取得できないため、対象の API では **Allow Skipping User Consent** を有効にしておく必要があります。
