# Enable Multi-Factor Authentication for a User

Learn how to add MFA methods to a user with the account pages, the Admin UI, the Two-Factor APIs, or the User API.

> For the index of this section of the site, see [llms.txt](https://fusionauth.io/docs/llms.txt)

FusionAuth asks for a second factor only from a user who has an MFA method, unless the login policy is `Required`. Before you add methods, turn on each method on the Tenant. For more information, see [Configure MFA](https://fusionauth.io/docs/authentication/multi-factor-authentication/configure.md).

Add MFA methods to a user in one of the following ways:

*   The self-service account pages let users add and remove their own methods. The account pages require the Starter plan or higher. For more information, see [Enable or Disable MFA](https://fusionauth.io/docs/users/account-management.md#enable-or-disable-mfa) in the account pages guide.
*   When the login policy is `Required`, the [hosted login pages](https://fusionauth.io/docs/concepts/integration-points.md#hosted-login-pages) ask a user without a method to add one during login.
*   The Admin UI adds methods to your own account only.
*   The Two-Factor APIs let you build your own enrollment pages. The user proves access to the method with a code.
*   The User API writes methods to a user directly, with no code. Use the User API to import methods from another system.

## Add a Method to Your Own Admin Account

The Admin UI can't add a method to another user, because adding a method requires a code from the user's device, email, or phone.

1.  Navigate to Users and open your own user.
    
2.  Click the Multi-Factor tab.
    
3.  Click Add two-factor .
    
    ![The Multi-Factor tab of a user in the Admin UI, with the Add two-factor button outlined.](https://fusionauth.io/img/docs/screenshots/authenticate-mfa-admin-add-method.png)
    
4.  Select a method and enter the code that FusionAuth sends or that your authenticator app shows.
    
5.  When the method is your first method, store the recovery codes that FusionAuth shows.
    

The Multi-Factor tab then lists the method:

![The Multi-Factor tab of a user in the Admin UI, with one email method.](https://fusionauth.io/img/docs/screenshots/authenticate-mfa-admin-one-method.png)

## Build Your Own Enrollment Pages

The Two-Factor APIs add a method only after the user enters a valid code. The check confirms that the user controls the authenticator app, email address, or phone.

1.  For an authenticator method, create a shared secret. Call the [Generate a Secret API](https://fusionauth.io/docs/apis/two-factor/generate-a-secret.md), or generate a random secret yourself:
    
    Generate a shared secret
    
    ```shell
    API_KEY=...
    
    curl -XGET -H "Authorization: $API_KEY" 'https://local.fusionauth.io/api/two-factor/secret'
    ```
    
    Generate a shared secret response
    
    ```json
    {
      "secret": "8MJJfCY4ERBtotvenSc3",
      "secretBase32Encoded": "HBGUUSTGINMTIRKSIJ2G65DWMVXFGYZT"
    }
    ```
    
    Show the secret to the user as a QR code or as text. The user adds the secret to an authenticator app, such as Google Authenticator or Authy.
    
2.  For an email or SMS method, send a code with the [Send a Multi-Factor Code When Enabling MFA API](https://fusionauth.io/docs/apis/two-factor/send-a-multi-factor-code-when-enabling-mfa.md):
    
    Send a code
    
    ```shell
    API_KEY=...
    REQUEST_PAYLOAD='{...}'
    
    curl -XPOST -H 'Content-type: application/json' -H "Authorization: $API_KEY" 'https://local.fusionauth.io/api/two-factor/send' -d $REQUEST_PAYLOAD
    ```
    
    Send a code request
    
    ```json
    {
      "messageType": "Voice",
      "method": "sms",
      "mobilePhone": "+13035551212",
      "userId": "c075e472-a732-47d6-865a-d385a5fcb525"
    }
    ```
    
    The Tenant's **Two-Factor one-time code** duration controls how long the code stays valid.
    
3.  Build a page that collects the code. An email or SMS user enters the code from the message. An authenticator user enters the code that the app shows.
    
4.  Call the [Enable Multi-Factor API](https://fusionauth.io/docs/apis/two-factor/enable-multi-factor.md) with the **`method`** and the **`code`**. For an email method, include the **`email`**:
    
    Enable an email method
    
    ```shell
    API_KEY=...
    USER_ID=...
    REQUEST_PAYLOAD='{...}'
    
    curl -XPOST -H 'Content-type: application/json' -H "Authorization: $API_KEY" 'https://local.fusionauth.io/api/user/two-factor/'$USER_ID -d $REQUEST_PAYLOAD
    ```
    
    Enable an email method request
    
    ```json
    {
      "code": "435612",
      "email": "richard@piedpiper.com",
      "method": "email",
      "name": "Work email"
    }
    ```
    
    For an authenticator method, include the **`secret`** from the first step:
    
    Enable an authenticator method request
    
    ```json
    {
      "code": "435612",
      "method": "authenticator",
      "name": "Work authenticator",
      "secret": "8MJJfCY4ERBtotvenSc3",
      "twoFactorId": "a6yRXP9-FF0sqD86L_1n_zRp6iAS_aXuuhQM8OL_nIA"
    }
    ```
    
    In FusionAuth `1.68.0` and later, set **`name`** to give the method a label that the user recognizes, such as `Work email`. The hosted login pages show the name in the list of methods.
    
5.  When the method is the user's first method, the response contains the user's [recovery codes](https://fusionauth.io/docs/authentication/multi-factor-authentication.md#recovery-codes). Show the codes to the user once, and ask the user to store the codes:
    
    Enable response with recovery codes
    
    ```json
    {
      "code": "752185",
      "recoveryCodes": [
        "QJD73-L6GR5",
        "R7RJH-GB7H3",
        "JJ5YZ-KS4C3",
        "CRDHP-7L355",
        "928QS-P9HMJ",
        "8VLFT-Z2WMM",
        "PQZX9-YV5VR",
        "TK9TB-7BT6H",
        "6QYPL-ZPQJV",
        "VJ35W-98RW4"
      ]
    }
    ```
    

To add another method, repeat the steps. The response for a second method has no body, and the recovery codes don't change.

The user's Multi-Factor tab in the Admin UI then lists each method:

![The Multi-Factor tab of a user in the Admin UI, with an email method and an authenticator method.](https://fusionauth.io/img/docs/screenshots/authenticate-mfa-admin-two-methods.png)

## Add Methods With the User API

The [User API](https://fusionauth.io/docs/apis/users.md) adds methods without a code, so FusionAuth never checks that the user controls the email address, phone, or authenticator app. When the email address or phone number is wrong, the user never receives a code and can't log in with the method. Use the User API when you already trust the method, such as during an import.

Send a `PATCH` request with the new methods in **`twoFactor.methods`**:

Add two email methods to a user

```shell
API_KEY=...

curl -XPATCH -H 'Content-type: application/json' -H "Authorization: $API_KEY" \
'https://local.fusionauth.io/api/user/00000000-0000-0000-0000-000000000004' \
-d '{
  "user": {
    "twoFactor": {
      "methods": [{
        "method": "email",
        "email": "dinesh@aol.com"
      }, {
        "method": "email",
        "email": "dinesh@gmail.com"
      }]
    }
  }
}'
```

A `PATCH` request adds the methods to the user's existing methods. To replace the methods, retrieve the user, change **`twoFactor.methods`**, and send the user back with a `PUT` request. For more information, see [The PATCH HTTP Method](https://fusionauth.io/docs/apis.md#the-patch-http-method).

For an authenticator method, set **`secret`** to a base64-encoded secret, and give the secret to the user for the authenticator app.

FusionAuth generates recovery codes for the first method, but the User API doesn't return the codes. To give the user codes, call the [Generate Recovery Codes API](https://fusionauth.io/docs/apis/two-factor/generate-recovery-codes.md) after you add the method.

## Import MFA Methods

FusionAuth can import users with authenticator, email, and SMS methods. Set the **`twoFactor`** fields on each user in a request to the [Import Users API](https://fusionauth.io/docs/apis/users/import.md) for a bulk migration, or the [User API](https://fusionauth.io/docs/apis/users.md) for a slow migration. The following example adds two email methods:

The twoFactor object for a user with two email methods

```json
"twoFactor": {
  "methods": [{
    "method": "email",
    "email": "dinesh@aol.com"
  },
  {
    "method": "email",
    "email": "dinesh@gmail.com"
  }]
}
```

For an authenticator method, include the base64-encoded **`secret`** from the old system, so the user's authenticator app keeps working. The Import Users API also accepts the user's existing **`recoveryCodes`**.

When the old system uses a message-based method that FusionAuth doesn't support, such as push notifications, a [Generic Messenger](https://fusionauth.io/docs/messengers/generic-messenger.md) may fit. The Generic Messenger sends SMS method codes to a service you run. For any other method, open a [GitHub issue](https://github.com/FusionAuth/fusionauth-issues/issues) that describes your use case.

Related

[Authentication Multi-Factor Authentication (MFA) Learn about multi-factor authentication (MFA) in FusionAuth, including the supported methods, recovery codes, and trust tokens. mfatwo-factormulti-factor authentication](https://fusionauth.io/docs/authentication/multi-factor-authentication.md)

[APIs Enable Multi-Factor API API documentation for the FusionAuth Enable Multi-Factor API. multi-factor authenticationmfaenable mfa](https://fusionauth.io/docs/apis/two-factor/enable-multi-factor.md)

[Authentication Configure Multi-Factor Authentication Learn how to turn on MFA methods for a Tenant and set when FusionAuth asks users for a second factor. mfamulti-factor authenticationtwo-factor](https://fusionauth.io/docs/authentication/multi-factor-authentication/configure.md)

[Authentication Disable Multi-Factor Authentication for a User Learn how to remove MFA methods from a user with the account pages, the Admin UI, the Two-Factor APIs, or the User API. mfamulti-factor authenticationtwo-factor](https://fusionauth.io/docs/authentication/multi-factor-authentication/disable.md)
---

## Other pages in Multi Factor Authentication

> For the full index of this section, see [Authentication](https://fusionauth.io/docs/llms-authentication.txt).

- [Configure Multi-Factor Authentication](https://fusionauth.io/docs/authentication/multi-factor-authentication/configure.md): Learn how to turn on MFA methods for a Tenant and set when FusionAuth asks users for a second factor.
- [Contextual Multi-Factor Authentication](https://fusionauth.io/docs/authentication/multi-factor-authentication/contextual.md): Learn how FusionAuth decides when to ask for MFA at login, including Tenant and Application policies, device trust, Intelligent MFA, and custom MFA logic.
- [Disable Multi-Factor Authentication for a User](https://fusionauth.io/docs/authentication/multi-factor-authentication/disable.md): Learn how to remove MFA methods from a user with the account pages, the Admin UI, the Two-Factor APIs, or the User API.
- [Multi-Factor Authentication (MFA)](https://fusionauth.io/docs/authentication/multi-factor-authentication.md): Learn about multi-factor authentication (MFA) in FusionAuth, including the supported methods, recovery codes, and trust tokens.
- [Multi-Factor Authentication at Login](https://fusionauth.io/docs/authentication/multi-factor-authentication/login.md): Learn how users complete an MFA challenge on the hosted login pages or on your own pages with the Login API, including recovery codes.
- [Add Step-Up Authentication With the Two-Factor APIs](https://fusionauth.io/docs/authentication/multi-factor-authentication/step-up-api.md): Learn how to ask a logged in user for another factor before a sensitive action, using the FusionAuth Two-Factor APIs.
- [Step-Up Authentication](https://fusionauth.io/docs/authentication/multi-factor-authentication/step-up.md): Learn about step-up authentication in FusionAuth, including how to choose an approach and how long a step-up stays valid.
