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

# トークンを取得

> Authorization Code Flow を使用して認可コードをトークンに交換します。

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`

トークンベースの認証では、`oauth/token` エンドポイントを使用して、アプリケーションが保護された API に対して認証付きリクエストを行うためのアクセストークンを取得します。必要に応じて、ID トークンやリフレッシュトークンも取得できます。ID トークンにはユーザー情報が含まれており、アプリケーションはそこからスコープを取り出して、より優れたユーザー体験を提供できます。リフレッシュトークンを使用すると、現在のトークンの有効期限が切れた後でも、ユーザー体験を中断することなく新しいアクセストークンを要求できます。詳しくは、[ID Tokens](https://auth0.com/docs/secure/tokens/id-tokens) と [Refresh Tokens](https://auth0.com/docs/secure/tokens/refresh-tokens) をご覧ください。

リフレッシュトークンを取得できる OAuth 2.0 フローは、次のものに限られます。

* [Authorization Code Flow (Authorization Code)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow)
* [Authorization Code Flow with PKCE (Authorization Code with PKCE)](https://auth0.com/docs/get-started/authentication-and-authorization-flow/authorization-code-flow-with-pkce)
* [Resource Owner Password](https://auth0.com/docs/get-started/authentication-and-authorization-flow/resource-owner-password-flow)
* [Device Authorization Flow](https://auth0.com/docs/get-started/authentication-and-authorization-flow/device-authorization-flow)
* Token Exchange\*

これは、通常の Web アプリが API にアクセスするために使用するフローです。このエンドポイントを使用して、Authorization Code をトークンに交換します。

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

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

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

<ParamField body="grant_type" type="string" required>
  使用するフローを示します。Authorization Code の場合は、`authorization_code` を使用します。
</ParamField>

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

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

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

<ParamField body="redirect_uri" type="string">
  これは、[GET /authorize](#authorization-code-grant) エンドポイントで設定した場合にのみ必要です。`/authorize` で指定した値は、`/oauth/token` で設定する値と一致している必要があります。
</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">
    トークンの種類です。通常は `Bearer` です。
  </ResponseField>

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

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

| ステータス | 説明         |
| ----- | ---------- |
| 200   | トークンを正常に取得 |
