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

# ネイティブソーシャル向けのトークン交換

> トークン交換グラントを使用して、ネイティブソーシャルのトークン（Apple や Google など）を 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`

<Note>
  このフローは、**ネイティブソーシャルにのみ**使用することを想定しています。ネイティブソーシャル以外でこのフローを使用することは、強く非推奨です。
</Note>

ブラウザを介さない方法 (モバイルプラットフォームの SDK など) でユーザーを認証すると、その結果としてアーティファクトがアプリケーションコードに返されるのが一般的です。このような場合、この grant type を使用すると、Auth0 プラットフォームは信頼できるソースからアーティファクトを受け取り、応答としてトークンを発行できます。これにより、ブラウザを介さない認証方式 (ネイティブアプリで一般的な方式) を使用するアプリでも、追加のユーザー操作を求めることなく Auth0 トークンを取得できます。

このフローで返されるアーティファクト (およびその内容) は、`subject_token_type` とテナントの設定によって決まります。

<div id="remarks">
  ## 注意事項
</div>

* アプリケーションに発行されるスコープは、要求したスコープと異なる場合があります。その場合、レスポンスJSONに `scope` パラメーターが含まれます。
* 特定のスコープを要求しない場合、このグラントではアプリケーションが暗黙的に信頼されるため、audience に定義されたすべてのスコープが返されます。返されるスコープはルールでカスタマイズできます。詳しくは、[Calling APIs from Highly Trusted Applications](https://auth0.com/docs/get-started/authentication-and-authorization-flow/resource-owner-password-flow) をご覧ください。

<div id="learn-more">
  ## 詳細情報
</div>

* [ネイティブ iOS アプリに Sign In with Apple を追加する](https://auth0.com/docs/authenticate/identity-providers/social-identity-providers/apple-native)
* [iOS Swift - Sign In with Apple クイックスタート](https://auth0.com/docs/quickstart/native/ios-swift)

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

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

<div id="body-parameters">
  ## ボディパラメーター
</div>

<div className="prose-sm prose-gray dark:prose-invert">
  <span data-as="p">リクエストボディは `application/x-www-form-urlencoded` 形式です。</span>
</div>

<ParamField body="auth0-forwarded-for" type="string">
  エンドユーザーの IP を表す文字列値です。サーバーサイドのシナリオでブルートフォース対策を機能させたい場合は、これを設定します。このヘッダーをいつどのように使用するかについて詳しくは、[サーバーサイドから resource owner password を使用する](/api-auth/tutorials/using-resource-owner-password-from-server-side)を参照してください。
</ParamField>

<ParamField body="grant_type" type="string" required>
  使用するフローを示します。ネイティブソーシャル向けのトークン交換には、`urn:ietf:params:oauth:grant-type:token-exchange` を使用します。
</ParamField>

<ParamField body="subject_token" type="string" required>
  ユーザーを表す、外部で発行された ID アーティファクトです。
</ParamField>

<ParamField body="subject_token_type" type="string" required>
  `subject_token` のタイプを示す識別子です。
</ParamField>

<ParamField body="client_id" type="string" required>
  アプリケーションの Client ID です。
</ParamField>

<ParamField body="audience" type="string">
  アクセス先の API の一意の識別子です。
</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">
  アプリケーションが要求する各スコープを表す文字列値です。複数のスコープは空白で区切ります。
</ParamField>

<ParamField body="user_profile" type="object">
  プロファイルの更新が発生する可能性があるネイティブ iOS 連携で使用される、任意の要素です。想定されるパラメーター値は、`{ name: { firstName: 'John', lastName: 'Smith' }}` 形式の JSON です。

  <Expandable title="properties">
    <ParamField body="name" type="object" />
  </Expandable>
</ParamField>

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

<ResponseSchema statusCode="200">
  <ResponseField name="access_token" type="string">
    発行されたアクセストークン。
  </ResponseField>

  <ResponseField name="id_token" type="string">
    発行されたIDトークン。
  </ResponseField>

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

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

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

<ResponseSchema statusCode="default error">
  <ResponseField name="error" type="string">
    エラーコード。
  </ResponseField>

  <ResponseField name="error_description" type="string">
    エラーの説明。
  </ResponseField>
</ResponseSchema>

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

| Status  | Description |
| ------- | ----------- |
| 200     | 成功レスポンス     |
| default | 予期しないエラー    |
