Two-Factor Authentication Message Template
On this page
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#
applicationThe 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]
baseUrlThe base URL for links in the message. FusionAuth uses the Application baseURL, then the Tenant baseURL, then http://localhost:9011.
codeThe code the user enters to complete multi-factor authentication.
emailThe 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.
phoneNumberThe 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.
spokenCodeThe code with the digits separated, so a voice service reads them one at a time. The variable is present only in the voice template.
tenantThe Tenant object. For field definitions, see the Tenant API.
userThe User object for the recipient. For field definitions, see the User API.
userIdThe 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.
Related
Learn when FusionAuth sends the email that contains a two-factor code, and which variables the template receives.
Learn about the message templates FusionAuth sends through messengers and the replacement variables each template receives.
API documentation for the FusionAuth Create an Email Template API.
Learn about the APIs for creating, retrieving, updating and deleting email templates as well as sending emails to users.