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

# トークンを取得

> リダイレクトを使用できない信頼済みアプリケーション向けに、リソースオーナーパスワードグラントを使用してユーザーの認証情報で認証します。

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 のグラントです。このフローでは、通常、ユーザーエージェント (ブラウザー) 内の対話形式のフォームを使用して、エンドユーザーに認証情報 (username/password) の入力を求めます。この情報はバックエンドに送信され、そこから 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` パラメーターが含まれます。
* 特定のスコープを要求しない場合、このグラントではアプリケーションが暗黙的に信頼されるため、オーディエンスに定義されているすべてのスコープが返されます。
* realm のサポートを追加するには、`grant_type` を `http://auth0.com/oauth/grant-type/password-realm` に設定し、`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)
* [MFA と 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">
  ## ボディパラメーター
</div>

<ParamField body="grant_type" type="string" required>
  使用するフローを示します。リソースオーナーパスワード の場合は `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>
  アプリケーションのクライアントIDです。
</ParamField>

<ParamField body="client_secret" type="string">
  アプリケーションのクライアントシークレットです。
</ParamField>

<ParamField body="realm" type="string">
  ユーザーが属する realm を表す文字列値です。
</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   | アクセストークンが返されます。 |
