> ## 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` パラメーターが含まれます。
* 特定のスコープを要求しない場合、この許可付与ではアプリケーションが暗黙的に信頼されるため、オーディエンスに定義されているすべてのスコープが返されます。返されるスコープはルールでカスタマイズできます。詳しくは、[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>

<ParamField body="auth0-forwarded-for" type="string">
  エンドユーザーの IP アドレスを文字列で指定します。サーバーサイドのシナリオでブルートフォース対策を有効にする場合は、これを設定してください。このヘッダーの使用方法と使用するタイミングの詳細については、[Using resource owner password from server-side](/ja/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>
  アプリケーションのクライアント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="プロパティ">
    <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>

| ステータス   | 説明       |
| ------- | -------- |
| 200     | 成功レスポンス  |
| default | 予期しないエラー |
