Gate Users Until They Verify Their Phone

On this page

As of version 1.59.0, FusionAuth can be configured to gate users' accounts until their phone numbers have been verified. While users can successfully start the login process, they will be blocked from completing it until they have verified possession of the phone number they registered with.

To enable phone verification gating, do the following:

  • Configure a messenger
  • Configure the tenant with your messenger
  • Configure the tenant to enable phone gating
  • Optionally customize the phone verification template
  • Enable self-service registrationA feature that lets users create their own accounts.
  • Configure your application with a redirect URLThe URL where the authorization server sends the browser after login, with an authorization code or an error.

Let's step through each of these, but first, there are some required prerequisites.

Prerequisites#

Starter plan required

This feature requires at least a Starter plan.

This tutorial assumes you are running FusionAuth version 1.59.0 or greater. If you aren't, head on over to the installation guide or the update guide to move to a version with support for this feature.

This tutorial also assumes you have a paid plan and valid license. If you need to buy a plan, please visit the pricing page. If you need to activate your instance, see Licensing.

Although you do not have to use Twilio to send messages, this tutorial assumes you will use Twilio as your SMS messenger. If you want to use a different messenger, you can do so by creating a generic messenger instead of a Twilio messenger.

Gating vs Verification vs Pre-Verification#

Note

Phone Verification is not a premium feature; gating is a premium feature. When you enable gating, users cannot receive a JWT to complete the authentication workflow until they verify their phone number.

FusionAuth ships with phone verification flows. These verification flows update the verified and verifiedReason attributes on a user identity. You have the option to gate the user (or prevent them from "continuing" auth) based on these attributes when writing your application and integration code.

With paid FusionAuth plans, you can elect to have FusionAuth "gate" your users based on these verification attributes. Gating in this sense, would prevent the user from authenticating further or obtaining a JWT and would be enforced by the FusionAuth User Interface. Gating happens after user creation.

Pre-verification applies the same concept, but user identities must be verified before user creation.

Configure the Messenger#

Log in to the FusionAuth Admin UI. You could do all of this configuration with the API or kickstart, but for this tutorial you'll use the UI.

Navigate to Settings -> Messengers and then click Add Twilio messenger and enter your Twilio account information.

Configure the Tenant with the Messenger#

Navigate to Tenants -> Your Tenant and then select the Identities tab. Scroll to the Messenger settings section. Configure this with the messenger you just created.

The tenant Identities tab with a messenger selected.

Enable Phone Verification Gating#

  • Under Phone, enable Verify identity.
  • Choose your message template. The default template is Phone Verification, and that will work fine for this tutorial.
  • Update the Verification strategy. This can be either ClickableLink or FormField. The former sends an SMS message with a link to verify the user's phone number. The latter sends a code which the user will provide to FusionAuth. For this tutorial, keep the default value of FormField.
  • Ensure that the Unverified behavior value is Gated.

After these steps, you should end up with a configuration screen that looks like this:

The tenant Identities tab with gated phone verification.

Make sure you save the configuration.

Customize the Phone Verification Template#

Navigate to Customizations -> Message Templates . Edit the Phone Verification template by clicking on the blue Edit button.

Modify the text template as desired and then save. You can also localize the messages.

The Phone Verification message template.

Configure the Application#

Navigate to Applications . Edit your application by clicking on the blue Edit button.

Enable self service registration by selecting the Registration tab, and then scrolling to the Self service registration section.

Note

You can create a user with an unverified phone number in other ways than self service registration. However, self service registration is the simplest way to create a user without a verified phone number.

Enable self service registration and configure the displayed and required fields as desired (in particular, choose Phone for the Login type).

The application Registration tab with self-service registration enabled for phone numbers.

Next, navigate to the OAuth tab. Enable the Authorization Code grant.

In addition, ensure you have entered a valid URL in the Authorized redirect URLs field. (The value of this redirect URL doesn't really matter for this tutorial. But for production use, ensure the code at that endpoint can exchange an authorization code for a token.)

Save the application configuration. You'll be returned to the list of applications.

Click on the View button of your application to see the details of your application.

The application details dialog with the login and registration URLs highlighted.

Look for the Registration URL. It'll be something like https://local.fusionauth.io/oauth2/register?client_id=85a03867-dccf-4882-adde-1a79aeec50df&response_type=code&redirect_uri=http%3A%2F%2Flocalhost%3A3000%2Foauth-redirect. Copy that value as you'll use it below.

At the same time, find the OAuth IdP login URL, and copy that as well.

Test It Out#

Now, test out the functionality. Register a new account. Make sure to use a different browser or incognito mode so that the admin account you logged in with while configuring FusionAuth doesn't interfere with new user registration.

Visit the registration URL copied above. You'll be prompted to register. Fill out the form with a valid phone number. After registration is complete, you'll receive a message prompting you to verify the phone number.

This user account will be gated and unable to completely log in if you have registered but not yet verified the phone number. In your browser where you registered, you'll see a screen similar to below:

The phone verification gate page for the form field strategy.

To test the gating, open a different browser (not a window, but an entirely different browser) and visit the login URL copied above. Enter the phone number and password for the user you just registered.

You'll be sent to the same phone verification gate page.

No matter which API or hosted login page you use, no JWT will be issued until the user has been verified. The user will continue to see the verification prompt when they log in until then.

If an API is being used to authenticate the user, the API will return a status code indicating phone verification has not yet occurred. Please see the Login API for more details.

If you view the user in the Admin UI, you'll see a question mark next to their phone number. This indicates that their phone number has not yet been verified.

The user details page with an unverified phone number.

Once you have verified the phone number by entering the code from the message, you can now log in and will be sent to the configured redirect URL.

The User Object#

The user object changes before, during, and after the phone verification occurs. Let's look at the JSON.

If a user is created and phone verification is disabled, the verified attribute of the identity object will be false with a reason of Disabled.

User Object With Phone Verification Turned Off Initially JSON
{
  "active": true,
  "birthDate": "1981-06-04",
  "connectorId": "e3306678-a53a-4964-9040-1c96f36dda72",
  "data": {
    "Company": "PiedPiper",
    "PreviousCompany": "Aviato",
    "user_type": "iconclast"
  },
  "phoneNumber": "+13035551212",
  "encryptionScheme": "salted-pbkdf2-hmac-sha256",
  "firstName": "Erlich",
  "id": "00000000-0000-0000-0000-000000000001",
  "identities": [
    {
      "primary": true,
      "type": "phoneNumber",
      "value": "+13035551212",
      "verified": false,
      "verifiedReason": "Disabled"
    }
  ],
  "insertInstant": 1630520102103,
  "lastLoginInstant": 1630639038934,
  "lastName": "Bachman",
  "lastUpdateInstant": 1630602397679,
  "passwordChangeRequired": false,
  "passwordLastUpdateInstant": 1630520102697,
  "tenantId": "30663132-6464-6665-3032-326466613934",
  "twoFactor": {},
  "usernameStatus": "ACTIVE",
  "verified": false
}

If a user is created while phone verification is enabled, the verified attribute of the identity object will be false with a reason of Pending

User Object With Phone Verification Turned On Initially JSON
{
  "active": true,
  "birthDate": "1981-06-04",
  "connectorId": "e3306678-a53a-4964-9040-1c96f36dda72",
  "data": {
    "Company": "PiedPiper",
    "PreviousCompany": "Aviato",
    "user_type": "iconclast"
  },
  "phoneNumber": "+13035551212",
  "encryptionScheme": "salted-pbkdf2-hmac-sha256",
  "firstName": "Erlich",
  "id": "00000000-0000-0000-0000-000000000001",
  "identities": [
    {
      "primary": true,
      "type": "phoneNumber",
      "value": "+13035551212",
      "verified": false,
      "verifiedReason": "Pending"
    }
  ],
  "insertInstant": 1630520102103,
  "lastLoginInstant": 1630639038934,
  "lastName": "Bachman",
  "lastUpdateInstant": 1630602397679,
  "passwordChangeRequired": false,
  "passwordLastUpdateInstant": 1630520102697,
  "tenantId": "30663132-6464-6665-3032-326466613934",
  "twoFactor": {},
  "usernameStatus": "ACTIVE",
  "verified": false
}

Naturally, the user's phone number identity will change to verified: true with verifiedReason: "Completed" once the user verifies their phone number.

Note

Users imported through the Import API will have whatever attributes are initially imported regardless of verification or gate settings.

Common Questions#

Do Existing Users Get Messages When I Enable a Gate?#

No. Enabling a gate sends no messages. Instead, an existing user with an unverified identity must verify the identity at their next login. An identity is unverified when the identity has verified: false and verifiedReason: "Pending". During login, the user clicks a link, and FusionAuth then sends the verification message.

When you use Elasticsearch for search, you can find the users that a gate will affect. Navigate to Users and search for verified: false. The search matches users with an unverified email address and users with an unverified registration.

Note

User search doesn't index the verification status of phone numbers. You can't search for users with an unverified phone number.

How Do I Mark an Imported User as Verified?#

To verify the email address or phone number of one user in the Admin UI:

  1. Navigate to Users and open the details page of the user.
  2. Click the down arrow next to Edit user , then select Verify identity .
  3. Select the identity and click Confirm .

The Admin UI can't mark a registration as verified. To verify a registration, or to verify many users at once, use the API:

  1. Get a verification Id from the Resend Verification API for an email address, or from the Resend Registration Verification API for a registration. Set sendVerifyEmail or sendVerifyRegistrationEmail to false, so FusionAuth returns the Id without sending an email.
  2. Send the verification Id to the Verify Email API or the Verify Registration API.

To skip this step in future imports, set users[x].verified and users[x].registrations[x].verified in the Import Users API.

What Happens When I Enable Both Email and Registration Verification?#

Email verification confirms that the user owns an email address, once per Tenant. Registration verification confirms that the user opted in to one Application. For example, nine Applications in a Tenant might require only email verification, while a tenth Application also requires registration verification.

When a new user signs up for the tenth Application, FusionAuth sends one email: the registration verification email. Completing registration verification also verifies the email address. When an existing user registers for the tenth Application, FusionAuth sends a registration verification email, even if the user already verified their email address.

When you turn off Allow implicit verification in the Tenant, registration verification doesn't verify the email address. Users then verify the registration and the email address separately. The setting is on the Identities tab of the Tenant. See Identity Verification Settings.

Troubleshooting Phone Verification#

Users cannot verify their application registration or verify their email. The link or code does not work (it is expired or there is some other error).

Check the Email Template#

Ensure you have selected the correct email template.

For Email Verification

If attempting to verify email addresses, ensure you have selected the appropriate template (Email Verification as opposed to Registration Verification in this instance)

The tenant email verification template set to the Email Verification template.
The tenant email verification template set to the Registration Verification template.

For Application Registration

If attempting to verify application registration, ensure you have selected the appropriate template (Registration Verification as opposed to Email Verification in this instance)

The application registration verification template set to the Registration Verification template.
The application registration verification template set to the Email Verification template.

Check External Identifier Timeouts#

Ensure your external identifier timeouts are appropriate. Reasonable defaults are set, but they can be adjusted (Tenants -> Advanced Tab -> External identifier durations ), with particular attention paid to Email Verification, Phone Verification, and Registration Verification durations.

The tenant Advanced tab with the verification durations highlighted.

Users cannot verify their phone number. The link or code does not work (it is expired or there is some other error).

Check External Identifier Timeouts#

Ensure your external identifier timeouts are appropriate. Reasonable defaults are set, but they can be adjusted (Tenants -> Advanced Tab -> External identifier durations ), with particular attention paid to Phone Verification duration.

The tenant Advanced tab with the phone verification duration highlighted.

Next Steps#

Now that you've successfully set up gated phone verification, take the next steps to integrate this functionality into your application: