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

# トークンを取得

> PKCE を使用した Authorization Code フローの最終ステップとして、Authorization Code をトークンと交換します。

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`

これは、モバイルアプリがAPIにアクセスする際に使用するフローです。このエンドポイントでは、Authorization Code をトークンに交換します。

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

* アプリケーションとの互換性を高めるため、Auth0 は今後、OIDC 仕様で定義された構造化クレーム形式でプロファイル情報を返します。つまり、IDトークンまたはアクセストークンにカスタムクレームを追加する場合は、標準の OIDC クレームとの競合を避けるため、名前空間付きの形式に準拠している必要があります。
* POST /oauth/token からリフレッシュトークンを取得するには、`scope` リクエストパラメーターに `offline_access` を含めてください。API Settings で Allow Offline Access フィールドが有効になっていることも確認してください。
* `redirect_uri` の値は、アプリケーションの Settings で有効なコールバック URL として指定する必要があります。
* サイレント認証を使用すると、Auth0 がリダイレクトのみを返し、ログインページは表示しない認証フローを実行できます。アクセストークンの有効期限が切れた場合でも、ユーザーのシングルサインオン (SSO) セッションが有効であれば、サイレント認証を使ってユーザー操作なしで新しいトークンを取得できます。

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

* [Proof Key for Code Exchange (PKCE) を使用した Authorization Code フロー](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-pkce)
* [PKCE を使用した Authorization Code フローで API を呼び出す](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-pkce/call-your-api-using-the-authorization-code-flow-with-pkce)
* [サイレント認証](https://auth0.com/docs/authenticate/login/configure-silent-authentication)

<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="grant_type" type="string" required>
  使用するフローを示します。Authorization Code (PKCE) の場合は `authorization_code` を使用します。

  使用可能な値: `authorization_code`
</ParamField>

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

<ParamField body="client_secret" type="string">
  アプリケーションの `client_secret`。`client_secret_post` トークンエンドポイント認証方法を使用する機密アプリケーションでは必須です。
</ParamField>

<ParamField body="code" type="string" required>
  最初の `/authorize` 呼び出しで受け取った Authorization Code。
</ParamField>

<ParamField body="code_verifier" type="string" required>
  `/authorize` に渡した `code_challenge` の生成に使用した、暗号学的にランダムなキーです。
</ParamField>

<ParamField body="redirect_uri" type="string">
  `GET` `/authorize` エンドポイントで設定されている場合にのみ必要です。
</ParamField>

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

<ResponseSchema statusCode="200">
  <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">
    トークンの種類。通常は `Bearer`。
  </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 | 予期しないエラー        |
