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

# トークンの取得

> Custom Token Exchangeグラントを使用して、既存のIDトークンをAuth0トークンに交換します。

export const ResponseSchema = ({statusCode, type = "{}", children}) => {
  const [open, setOpen] = useState(false);
  return <div className="border border-gray-100 dark:border-gray-800 rounded-lg mb-3 overflow-hidden">
      <div className={`flex items-center gap-2.5 px-4 py-2.5 cursor-pointer select-none ${open ? "bg-gray-50 dark:bg-gray-800" : ""}`} onClick={() => setOpen(!open)}>
        {statusCode && <span className="border border-gray-300 dark:border-gray-600 text-gray-700 dark:text-gray-300 font-mono text-xs px-1.5 py-0.5 rounded">
            {statusCode.startsWith("default") ? "default" : statusCode}
          </span>}
        <span className="text-gray-500 dark:text-gray-400 text-sm font-mono">
          {type}
        </span>
        <span className="text-gray-400 dark:text-gray-500 text-sm italic">
          application/json
        </span>
        <svg className={`ml-auto opacity-50 transition-transform duration-200 ${open ? "rotate-180" : ""}`} width="16" height="16" viewBox="0 0 16 16" fill="none">
          <path d="M4 6l4 4 4-4" stroke="currentColor" strokeWidth="1.5" strokeLinecap="round" strokeLinejoin="round" />
        </svg>
      </div>
      {open && <div className="px-4 pt-1 pb-3 border-t border-gray-100 dark:border-gray-800">
          {children}
        </div>}
    </div>;
};

<div id="endpoint">
  ## エンドポイント
</div>

`POST /oauth/token`

Custom Token Exchange (CTE) は、[RFC 8693](https://datatracker.ietf.org/doc/html/rfc8693) の仕様に準拠し、`/oauth/token` エンドポイントを呼び出すことで、アプリケーションが既存の IDトークンを Auth0 のトークンに交換できる仕組みを提供します。この機能は、同じユーザーに代わって別の対象者にアクセスするために既存の Auth0 トークンを交換する場合や、外部 IDプロバイダーとの統合を容易にする場合、または Auth0 プラットフォームへのシームレスなユーザー移行を可能にする場合など、高度な統合要件に対応するうえで特に有用です。交換プロセスは完全に管理可能であり、開発者は該当するユースケース専用の Auth0 Action で実行されるカスタムロジックを使用して、その詳細を制御できます。

<Note>
  Custom Token Exchange は現在、早期アクセスで提供されています。この機能を使用すると、[Okta’s Master Subscription Agreement](https://www.okta.com/legal/) に記載されている該当する Free Trial 条項に同意したものとみなされます。ユーザーの `subject_token` を安全に検証することは、お客様の責任です。詳細については、[User Guide](https://auth0.com/docs/authenticate/custom-token-exchange) を参照してください。
</Note>

<div id="remarks">
  ### 注記
</div>

* アプリケーションに発行されるスコープは、要求したスコープと異なる場合があります。この場合、レスポンス JSON に `scope` パラメーターが含まれます。スコープは、[API Access Policies for Applications](https://auth0.com/docs/get-started/apis/api-access-policies-for-applications) で説明されているとおりにフィルタリングされます

* `subject_token_type` は、既存の Custom Token Exchange Profile および関連付けられた [Action](https://auth0.com/docs/customize/actions) に対応している必要があります。

* クライアントシークレットを安全に保持できない非機密アプリケーション (たとえばネイティブアプリ) の場合、この エンドポイント ではクライアントシークレットを渡さないことがサポートされています。ただし、アプリケーション自体の `tokenEndpointAuthMethod` プロパティが `none` に設定されている必要があります。これは、UI (**Dashboard > Applications > Application Settings**) から行うことも、Management API を使用して行うこともできます。

* [アプリケーションで Custom Token Exchange を有効にする](https://auth0.com//docs/authenticate/custom-token-exchange/configure-custom-token-exchange#enable-custom-token-exchange-for-your-application)必要があります。詳細については、[Custom Token Exchange のドキュメント](https://auth0.com/docs/authenticate/custom-token-exchange) を参照してください。

* `actor_token` と `actor_token_type` は、両方とも存在するか、両方とも存在しない必要があります。どちらか一方だけを指定すると、code が `invalid_request` の `400` エラーが返されます。

* `actor_token` が存在する場合、リフレッシュトークンは発行されません。`offline_access` スコープはレスポンスから除外されます。

* `setActor()` で actor が設定されたトランザクションでは、MFA は使用できません。MFA が必要で、Custom Token Exchange Action が actor を設定する場合、リクエストは次の `400` エラーを返します: `MFA is not supported using actor_token with the requested token exchange profile.`

* Action が `setActor()` を呼び出すと、発行されたアクセストークンと IDトークンには、[delegation chain](/ja/docs/secure/call-apis-on-users-behalf/on-behalf-of-token-exchange#the-act-claim) を表す `act` クレームが含まれます。`act` クレームは userinfo レスポンスにも含まれます。

<div id="headers">
  ## ヘッダー
</div>

<ParamField header="DPoP" type="string">
  リクエストの DPoP 証明。省略可能で、アプリケーションで Demonstrating Proof-of-Possession (DPoP) を使用している場合にのみ必要です。
</ParamField>

<ParamField header="auth0-forwarded-for" type="string">
  文字列形式のエンドユーザー IP です。サーバーサイドのシナリオで不審な IP スロットリング保護を有効にする場合は、これを設定します。
</ParamField>

<div id="body-parameters">
  ## 本文パラメーター
</div>

<ParamField body="grant_type" type="string" required>
  使用するフローを示します。Custom Token Exchange の場合は、`urn:ietf:params:oauth:grant-type:token-exchange` を使用してください。

  使用可能な値: `urn:ietf:params:oauth:grant-type:token-exchange`
</ParamField>

<ParamField body="subject_token_type" type="string" required>
  サブジェクトトークンのタイプです。Custom Token Exchange では、`http://acme.com/legacy-token` や `urn:acme:legacy-token` のように、自身が所有する名前空間配下の任意の URI を使用できます。次の名前空間は予約されているため、使用できません: `http://auth0.com`, `https://auth0.com`, `http://okta.com`, `https://okta.com`, `urn:ietf`, `urn:auth0`, `urn:okta`.
</ParamField>

<ParamField body="subject_token" type="string" required>
  サブジェクトトークンです。Action でこれを検証し、ユーザーの識別に使用する必要があります。
</ParamField>

<ParamField body="client_id" type="string" required>
  アプリケーションのクライアントIDです。他のグラントタイプと同様に、HTTP Basic Auth を使用して Authorization ヘッダーでクライアントIDを渡すこともできます。
</ParamField>

<ParamField body="client_secret" type="string">
  (省略可能) アプリケーションのクライアントシークレットです。他のグラントタイプと同様に、HTTP Basic Auth を使用して Authorization ヘッダーでクライアントシークレットを渡すこともできます。[Auth0 Authentication API リファレンスドキュメント](https://auth0.com/docs/api/authentication#authentication-methods) で説明しているとおり、ほかの方法も利用できます。Custom Token Exchange はパブリックアプリケーションでも使用できるため、追加のセキュリティを実装するには [アタックプロテクション](https://auth0.com/docs/authenticate/custom-token-exchange/cte-attack-protection) を参照してください。
</ParamField>

<ParamField body="audience" type="string">
  (省略可能) アクセス先の対象 API の一意の識別子です。指定しない場合は、[Tenant Settings](https://auth0.com/docs/get-started/tenant-settings) で設定されたデフォルトのテナント 対象者 が使用されます。
</ParamField>

<ParamField body="resource" type="string">
  (省略可能) アクセス先の対象 API (リソースサーバー) の識別子です。Auth0 テナントに登録されている API Identifier と一致している必要があります。テナントの [Resource Parameter Compatibility Profile](https://auth0.com/docs/get-started/tenant-settings#settings-advanced) が `compatibility` に設定されている場合に、`audience` の代わりに使用します。
</ParamField>

<ParamField body="scope" type="string">
  (省略可能) OAuth2 の scope パラメーターです。
</ParamField>

<ParamField body="organization" type="string">
  (省略可能) リクエストに関連付ける組織または識別子です。また、[Use Organization Names in Authentication API](https://auth0.com/docs/manage-users/organizations/configure-organizations/use-org-name-authentication-api) を有効にしている場合は、組織名を指定することもできます。
</ParamField>

<ParamField body="actor_token" type="string">
  (省略可能) サブジェクトユーザーに代わってデリゲーションを実行するアクターを識別するトークンです。`actor_token_type` とあわせて指定する必要があります。指定した場合、リフレッシュトークンは発行されません。
</ParamField>

<ParamField body="actor_token_type" type="string">
  (省略可能) アクタートークンのタイプです。`actor_token` とあわせて指定する必要があります。Auth0 IDトークンの場合は、自動的にサーバー側で検証 (署名、有効期限、発行元、ユーザー検索) するため、`urn:ietf:params:oauth:token-type:id_token` を使用してください。その他の値については、`subject_token_type` と同じ名前空間の制限に従ってください。
</ParamField>

<div id="response-schema">
  ## レスポンススキーマ
</div>

<ResponseSchema>
  <ResponseField name="access_token" type="string">
    アクセストークン。
  </ResponseField>

  <ResponseField name="refresh_token" type="string">
    リフレッシュトークン。
  </ResponseField>

  <ResponseField name="id_token" type="string">
    IDトークン。
  </ResponseField>

  <ResponseField name="token_type" type="string">
    トークンの種類。
  </ResponseField>

  <ResponseField name="issued_token_type" type="string">
    発行されたトークンの種類。
  </ResponseField>

  <ResponseField name="expires_in" type="integer">
    アクセストークンの有効期限 (秒) 。
  </ResponseField>
</ResponseSchema>

<div id="response-messages">
  ## レスポンスメッセージ
</div>

| ステータス | 説明        |
| ----- | --------- |
| 200   | 成功時のレスポンス |
