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

# トークンを取得

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

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`

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

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

<div id="request-headers">
  ### リクエストヘッダー
</div>

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

<div id="responses">
  ### レスポンス
</div>

<div id="200">
  #### 200
</div>

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

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

<div id="remarks">
  ### 備考
</div>

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

<div id="learn-more">
  ### 詳細はこちら
</div>

* [高信頼アプリケーションから 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)

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

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

<div id="body-parameters">
  ## 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>
  使用するフローを示します。Resource Owner Password の場合は `password` を使用します。
</ParamField>

<ParamField body="username" type="string" required>
  ユーザー名やメールアドレスなどの、Resource Owner の識別子。
</ParamField>

<ParamField body="password" type="string" required>
  Resource Owner のシークレット。
</ParamField>

<ParamField body="audience" type="string">
  アクセス先の対象 API の一意の識別子。
</ParamField>

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

<ParamField body="scope" type="string">
  アプリケーションが要求する各スコープを表す文字列値。
</ParamField>

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

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

<ParamField body="realm" type="string">
  ユーザーが属するレルムを表す文字列値。
</ParamField>

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

<ResponseSchema>
  <ResponseField name="access_token" type="string">
    アクセストークンです。
  </ResponseField>

  <ResponseField name="token_type" type="string">
    トークンの種類です。通常は `Bearer` です。
  </ResponseField>

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

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

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