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

# MFA を使用した Resource Owner Password Flow で認証する

> MFA を使用した Resource Owner Password Flow でユーザーを認証する方法を学びます。

[Auth0 MFA API](/docs/docs/ja-jp/api/authentication#multi-factor-authentication) を使用すると、Resource Owner (Resource Owner: 保護されたリソースへのアクセスを許可できるエンティティ（ユーザーやアプリケーションなど）。) Password Grant または ROPG とも呼ばれる [Resource Owner Password Flow](/docs/docs/ja-jp/get-started/authentication-and-authorization-flow/resource-owner-password-flow) を使って、MFA (Resource Owner: 保護されたリソースへのアクセスを許可できるエンティティ（ユーザーやアプリケーションなど）。) が有効な場合に認証フローを完了できます。

## 前提条件

MFA APIを使用するには、事前にアプリケーションでMFAのグラントタイプを有効にしておく必要があります。[Auth0 Dashboard > アプリケーション > Advanced Settings > グラントタイプ](https://manage.auth0.com/#/applications) に移動し、**MFA** を選択します。

## ユーザーを認証する

Resource Owner Password Flow を使用して認証する場合は、ユーザーのユーザー名とパスワードを指定して `/oauth/token` エンドポイントを呼び出します。

MFA が有効な場合、レスポンスには `mfa_required` エラーと `mfa_token` が含まれます。

`https://{yourDomain}/mfa/*` audience を持つアクセストークンのデフォルトの有効期限は 10 分です。この値は変更できません。

```json lines theme={null}
{
    "error": "mfa_required",
    "error_description": "Multifactor authentication required",
    "mfa_token": "Fe26...Ha"
}
```

## 登録済みの認証器を取得する

上記のエラーが返されたら、ユーザーに MFA 認証要素が登録されているかどうかを確認する必要があります。前のセクションで取得した MFA トークンを使用して、[MFA 認証器エンドポイント](/docs/docs/ja-jp/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authenticator-factors-mfa-api) を呼び出します。

利用可能な認証器の配列が返されます。ユーザーが認証要素を登録していない場合、その配列は空になります。

```json lines theme={null}
[
    {
        "id": "recovery-code|dev_O4KYL4FtcLAVRsCl",
        "authenticator_type": "recovery-code",
        "active": true
    },
    {
        "id": "email|dev_NU1Ofuw3Cw0XCt5x",
        "authenticator_type": "oob",
        "active": true,
        "oob_channel": "email",
        "name": "email@address.com"
    }
]
```

## MFA認証要素を登録する

ユーザーがMFAに未登録の場合は、先ほど取得したMFA トークンを使用して、MFA Associate endpointで登録します。認証要素に応じてこのフローを実装する方法については、次のリンクを参照してください。

* [SMS または音声](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-challenge-sms-voice-authenticators)
* [ワンタイムパスワード (OTP)](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-otp-authenticators)
* [Push](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-push-authenticators)
* [Email](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-email-authenticators)

## MFA でユーザーにチャレンジする

ユーザーがすでに MFA に登録済みの場合は、既存の認証要素のいずれかを使ってチャレンジする必要があります。MFA Challenge エンドポイントを呼び出す際は、MFA 認証器 エンドポイントから返される `authenticator_id` を使用します。

チャレンジが完了したら、認証フローを完了して認証トークンを取得するために、`/oauth/token` エンドポイントをもう一度呼び出します。

認証要素に応じてこのフローを実装するには、以下のリンクを参照してください。

* [SMS または音声](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-challenge-sms-voice-authenticators)
* [ワンタイムパスワード (OTP)](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-otp-authenticators)
* [Push](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-push-authenticators)
* [Email](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-email-authenticators)

### MFA OTPコードの制限事項

**有効期限**: MFA OTPコードの有効期限は5分です。この値は設定できません。

**コードのバリデーション**: ユーザーがMFA OTPコードをバリデーションすると、そのコードは再度使用できません。

**コードのバリデーションに対するレート制限**: ユーザーによるバリデーションが失敗した場合、バケットアルゴリズムによってレート制限されます。バケットは最初に10回分の試行回数を持ち、6分ごとに1回分回復します。

## MFA をカスタマイズ

> [!WARNING]
>
> Resource Owner Password Grant、埋め込み、またはリフレッシュトークンのフローでのカスタマイズ可能な MFA は、早期アクセスです。この機能を使用することで、Okta の [Master Subscription Agreement](https://www.okta.com/legal/) に記載されている該当する Free Trial 条項に同意したものとみなされます。Auth0 のリリースステージの詳細については、[Product Release Stages](/docs/docs/ja-jp/troubleshoot/product-lifecycle/product-release-stages) をご覧ください。

MFA API を使用して、MFA フローをカスタマイズできます。MFA API を使うと、アプリケーションでサポートしている特定の認証要素について、ユーザーが登録やチャレンジを行えるようにできます。

認証のために Resource Owner Password Flow で MFA が有効になっている場合は、`/oauth/token endpoint` を呼び出してアクセストークンをリクエストします。認可サーバーは `mfa_required` エラーを返し、次の情報を提供します。

* 登録とチャレンジのために MFA API を呼び出す際に必要な `mfa_token`。
* `mfa_requirements` パラメーター。これには、チャレンジでアプリケーションがサポートする認証要素の種類が含まれます。

```json theme={null}
{
  "error": "mfa_required",
  "error_description": "Multifactor authentication required",
  "mfa_token": "Fe26...Ha",
  "mfa_requirements": {
    "challenge": [
      { "type": "otp" },
      { "type": "push-notification" },
      { "type": "phone" },
      { "type": "recovery-code" }
    ]
  }
}
```

`mfa_token` を使用して [`mfa/authenticator エンドポイント`](/docs/docs/ja-jp/api/authentication/multi-factor-authentication/list-authenticators) を呼び出し、ユーザーが登録済みの認証要素をすべて一覧表示して、アプリケーションがサポートしている同じ種類のものを特定します。  また、チャレンジを発行するには、対応する `authenticator_type` も取得する必要があります:

```json theme={null}
[
  {
    "type": "recovery-code",
    "id": "recovery-code|dev_qpOkGUOxBpw6R16t",
    "authenticator_type": "recovery-code",
    "active": true
  },
  {
    "type": "otp",
    "id": "totp|dev_6NWz8awwC8brh2dN",
    "authenticator_type": "otp",
    "active": true
  }
]
```

[`request/mfa/challenge`](/docs/docs/ja-jp/api/authentication/multi-factor-authentication/request-mfa-challenge) エンドポイントを呼び出して、MFA チャレンジを必須にします。

Auth0 Actions を使用すると、MFA フローをさらにカスタマイズできます。詳しくは、[Actions トリガー: post-challenge - API オブジェクト](/docs/docs/ja-jp/actions/reference/password-reset-post-challenge/password-reset-post-challenge-api-object) をご覧ください。

## 詳細はこちら

* [SMS および音声認証器の登録とチャレンジ](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-challenge-sms-voice-authenticators)
* [OTP 認証器の登録とチャレンジ](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-otp-authenticators)
* [Push 認証器の登録とチャレンジ](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-push-authenticators)
* [Email 認証器の登録とチャレンジ](/docs/docs/ja-jp/secure/multi-factor-authentication/authenticate-using-ropg-flow-with-mfa/enroll-and-challenge-email-authenticators)
* [Authentication API を使用して認証要素を管理する](/docs/docs/ja-jp/secure/multi-factor-authentication/manage-mfa-auth0-apis/manage-authenticator-factors-mfa-api)
* [多要素認証の認証要素](/docs/docs/ja-jp/secure/multi-factor-authentication/multi-factor-authentication-factors)
