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

# トークンを取得

> リダイレクトを使用できない信頼できるアプリケーション向けに、Resource Owner Password grant を使用してユーザーの認証情報で認証を行います。

## エンドポイント

`POST /oauth/token`

> [!NOTE]
>
> このフローは、**リダイレクトできない**、高信頼アプリケーションでのみ使用してください。アプリでリダイレクトベースのフローを使用できる場合は、代わりに [Authorization Code Flow](#regular-web-app-login-flow) を使用することを推奨します。

これは、高い信頼性が求められるアプリが API にアクセスするために使用する OAuth 2.0 のグラントです。このフローでは通常、ユーザーエージェント (ブラウザ) 上の対話型フォームを使って、エンドユーザーに認証情報 (ユーザー名/パスワード) を入力してもらいます。この情報はバックエンドに送信され、そこから Auth0 に送られます。そのため、アプリケーションがこの情報を安全に扱えるほど十分に信頼できることが不可欠です。

### リクエストヘッダー

| Parameter | Description |
| :- | :- |
| `auth0-forwarded-for` | エンドユーザーの IP アドレスを文字列で指定します。サーバー側の環境でブルートフォース対策を有効にする場合は、これを設定してください。 |

### レスポンス

#### 200

リクエストが成功すると、アクセストークンが返されます。

```json theme={null}
HTTP/1.1 200 OK
Content-Type: application/json
{
  "access_token":"eyJz93a...k4laUWw",
  "token_type":"Bearer",
  "expires_in":86400
}
```

### 備考

* アプリケーションに発行されるスコープは、要求したスコープと異なる場合があります。その場合、レスポンスの JSON には `scope` パラメーターが含まれます。
* 特定のスコープを要求しない場合、このグラントではアプリケーションが暗黙的に信頼されているため、audience に定義されているすべてのスコープが返されます。
* レルムのサポートを追加するには、`grant_type` を `http://auth0.com/oauth/grant-type/password-realm` に設定し、`realm` にはユーザーが属するレルムを指定します。これは Auth0 のコネクションに対応します。
* Auth0 では、ユーザー名とパスワードに加えて、本人確認のためにエンドユーザーへ追加の認証要素の提示を求める場合があります。リクエストでは、多要素認証用の `mfa_token` とともに `mfa_required` エラーが返されることがあります。

### 詳細はこちら

* [高信頼アプリケーションから API を呼び出す](https://auth0.com/docs/get-started/authentication-and-authorization-flow/resource-owner-password-flow)
* [Resource Owner Password Grant を実行する](https://auth0.com/docs/get-started/authentication-and-authorization-flow/resource-owner-password-flow/call-your-api-using-resource-owner-password-flow)
* [多要素認証と Resource Owner Password フロー](https://auth0.com/docs/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa)

## ヘッダー

**DPoP** `string`

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

## Body Parameters

リクエスト本文は `application/x-www-form-urlencoded` 形式です。

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

使用するフローを示します。Resource Owner Password の場合は `password` を使用します。

**username** `string` *required*

ユーザー名やメールアドレスなどの、Resource Owner の識別子。

**password** `string` *required*

Resource Owner のシークレット。

**audience** `string`

アクセス先の対象 API の一意の識別子。

**resource** `string`

アクセス先の対象 API (リソースサーバー) の識別子。Auth0 テナントに登録されている API Identifier と一致している必要があります。テナントの [Resource Parameter Compatibility Profile](https://auth0.com/docs/get-started/tenant-settings#settings-advanced) が `compatibility` に設定されている場合、`audience` の代わりに使用されます。

**scope** `string`

アプリケーションが要求する各スコープを表す文字列値。

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

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

**client\_secret** `string`

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

**realm** `string`

ユーザーが属するレルムを表す文字列値。

## レスポンススキーマ

\{}

application/json

**access\_token** `string`

アクセストークンです。

**token\_type** `string`

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

**expires\_in** `integer`

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

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

| ステータス | 説明 |
| - | - |
| 200 | アクセストークンを返します。 |
