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

# トークンの取得

> Authorization Code Flow を使用して、認可コードからトークンを取得します。

## エンドポイント

`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 をトークンに交換します。

## ヘッダー

**DPoP** `string`

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

## リクエストボディのパラメータ

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

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

使用するフローを指定します。認可コード の場合は `authorization_code` を使用します。

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

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

**client\_secret** `string` *required*

アプリケーションの Client Secret です。

**code** `string` *required*

最初の `/authorize` 呼び出しで受け取った 認可コード です。

**redirect\_uri** `string`

[GET /authorize](#authorization-code-grant) エンドポイントで設定している場合にのみ必要です。`/authorize` で指定した値は、`/oauth/token` で設定する値と一致している必要があります。

## レスポンススキーマ

\{}

application/json

**access\_token** `string`

アクセストークン。

**refresh\_token** `string`

新しいアクセストークンを取得するためのリフレッシュトークン。

**id\_token** `string`

IDトークン。

**token\_type** `string`

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

**expires\_in** `integer`

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

## エージェントアクセストークン

> [!WARNING]
>
> **Agent as Principal機能は現在、[早期アクセス](/docs/docs/troubleshoot/product-lifecycle/product-release-stages)です。**
>
> 参加をご希望の場合は、Auth0 Supportまでお問い合わせください。
>
> この機能を使用することにより、Oktaの該当する無料トライアル規約および[Master Subscription Agreement](https://www.okta.com/legal)に同意したものとみなされます。

認可コードを交換するアプリケーションがエージェントにリンクされ、対象 API でエージェントの subject クレームが有効になっている場合、発行されるアクセストークンには、ユーザーに代わって動作する actor としてエージェントが記録されます。

* `sub` クレームは引き続きユーザー識別子です。エージェントのアイデンティティは `sub` ではなく `act` クレームに示されます。
* `act` クレームはエージェントを識別します: `{ "sub": "agt_72jbvv7LfRKYp59gtRLtkn", "sub_profile": "ai_agent", "client_id": "YOUR_CLIENT_ID", "iss": "https://YOUR_DOMAIN/" }`。
* トークンには `sub_profile: "user"` と、たとえば `web_app ai_agent` のように `ai_agent` 接尾辞が付いた `client_profile` が含まれます。

アクセストークンにセッション転送または On-Behalf-Of トークン交換による actor がすでに含まれている場合は、その actor が優先され、エージェントの actor は追加されません。これらのクレームはアクセストークンにのみ適用され、ID トークンには影響しません。レスポンスオブジェクトのスキーマは変更されません。詳細については、[Access Token Profiles](/docs/docs/ja-jp/secure/tokens/access-tokens/access-token-profiles#claims)を参照してください。

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

| ステータス | 説明 |
| - | - |
| 200 | トークンの取得成功 |
