Two-Factor Authentication Message Template

On this page
Starter plan required

This feature requires at least a Starter plan.

FusionAuth sends this message with a code when a user completes a multi-factor login with the sms method, or enables or disables the sms method. FusionAuth renders the text template by default, and the voice template when the request sets messageType to Voice. Assign the templates in SMS template and Voice template under Tenants -> Your Tenant -> Multi-Factor -> Phone settings . To override the templates for one Application, set SMS template and Voice template on the Application's Multi-Factor tab.

Default Templates#

FusionAuth ships a default text template and a default voice template. The voice template uses spokenCode, so a voice service reads the digits one at a time:

Two Factor Code: ${code}
This is your two factor code: ${spokenCode}, repeat ${spokenCode}

Replacement Variables#

application
  • Type: Application

The Application object. For field definitions, see the Application API.

The variable is present only when the request that sends the message identifies an Application. Check for the variable before you use it:

[#if application??]
  ${application.name}
[/#if]
baseUrl
  • Type: String
  • Available since 1.68.0

The base URL for links in the message. FusionAuth uses the Application baseURL, then the Tenant baseURL, then http://localhost:9011.

code
  • Type: String

The code the user enters to complete multi-factor authentication.

email
  • Type: String

The email address on the two-factor method. A method that sends messages usually has no email address, so check for the variable before you use it.

phoneNumber
  • Type: String
  • Available since 1.59.0

The mobilePhone of the two-factor method. Before 1.59.0, the variable was named mobilePhone. The Generic messenger request has the same value in phoneNumber.

spokenCode
  • Type: String
  • Available since 1.65.0

The code with the digits separated, so a voice service reads them one at a time. The variable is present only in the voice template.

tenant
  • Type: Tenant

The Tenant object. For field definitions, see the Tenant API.

user
  • Type: User

The User object for the recipient. For field definitions, see the User API.

userId
  • Type: UUID

The Id of the user. The Generic messenger request has the same value in userId.

The application variable is missing when a request that sends the code has no applicationId. The requests are the following:

  • Start Multi-Factor.
  • The Login API, when multi-factor authentication is required. A production login request should always include applicationId.
  • The requests that send a code to enable or disable a method.