> ## Documentation Index
> Fetch the complete documentation index at: /docs/llms.txt
> Use this file to discover all available pages before exploring further.

# トークンを取得

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

## エンドポイント

`POST /oauth/token`

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

### 注記

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

### 詳細

* [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)

## ヘッダー

**DPoP** `string`

リクエスト用の DPoP プルーフです。これは任意で、アプリケーションで Demonstrating Proof-of-Possession を使用している場合にのみ必要です。

## ボディパラメータ

リクエストボディは `application/x-www-form-urlencoded` 形式です。

**grant\_type** `string` *required*

使用するフローを示します。Authorization Code (PKCE) の場合は `authorization_code` を使用します。

使用可能な値: `authorization_code`

**client\_id** `string` *required*

アプリケーションの Client ID。

**client\_secret** `string`

アプリケーションの `client_secret`。`client_secret_post` トークンエンドポイント認証方法を使用する機密アプリケーションでは必須です。

**code** `string` *required*

最初の `/authorize` 呼び出しで受け取った Authorization Code。

**code\_verifier** `string` *required*

`/authorize` に渡した `code_challenge` の生成に使用した、暗号学的にランダムなキーです。

**redirect\_uri** `string`

`GET` `/authorize` エンドポイントで設定されている場合にのみ必要です。

## レスポンススキーマ

200

\{}

application/json

**access\_token** `string`

アクセストークン。

**refresh\_token** `string`

新しいアクセストークンの取得に使用するリフレッシュトークン。

**id\_token** `string`

IDトークン。

**token\_type** `string`

トークンの種類。通常は `Bearer`。

**expires\_in** `integer`

アクセストークンの有効期限 (秒) 。

default

\{}

application/json

**error** `string`

エラーコード。

**error\_description** `string`

エラーの詳細。

## レスポンスメッセージ

| Status | Description |
| - | - |
| 200 | トークンの交換に成功しました。 |
| default | 予期しないエラー |
