Message Variables
Templates & Replacement Variables
The message template body supports replacement variables. This means place holders can be inserted and the value will be calculated at the time the message template is rendered and sent to a user.
Most templates will contain the User object as returned on the Retrieve User API. This means you can utilize any value found on the User object such as email, first name, last name, etc.
Below you will find each stock template that FusionAuth ships for reference. The available replacement values will be outlined below for each template.
Previewing Message Templates
FusionAuth provides the capability to preview message templates via the Message Template API or the administrative user interface by navigating to Customizations -> Message Templates -> Edit -> Preview . The following sample values are used when rendering the template.
Parameter | Sample Value | Purpose |
---|---|---|
${application} | { "name": "My Application", "oauthConfiguration": { "clientId": "123456" } } | Application name, oauthConfiguration.clientId for themed message links |
${changePasswordId} | 1234567890 | Embedded in change password and set password URLs |
${code} | 123456 | Embedded in MFA/Two Factor messages |
${event} | { "type": "UserLoginSuspicious", "info": {...} } | Embedded in User Event messages |
${method} | { "id" : "FQLM", "method" : "email" } | Embedded in Two Factor Add/Remove event messages |
${oneTimeCode} | 88888 | Embedded in passwordless login messages |
${tenant} | { "name": "My Tenant", "id": "78910" } | tenant.id allows links embedded in messages to render using the correct theme for that tenant. |
${user} | { "firstName": "John", "lastName": "Doe" } | User information and user.tenantId for themed message links |
${verificationId} | 987654 | Embedded in phone number verification messages |
${verificationOneTimeCode} | abcdef | Embedded in phone number verification messages |
Retrieving Default Templates
In order to version control the templates or customize them, you can use the admin UI. But you can also pull retrieve them all by using the following command:
wget -i https://raw.githubusercontent.com/FusionAuth/fusionauth-site/main/astro/src/content/docs/_shared/message/template_url_list
This will place all the message templates in the current working directory.
Using Replacement Variables
Below are some basic examples of using replacement values in your message templates.
Consider the following User represented by this condensed JSON object.
{
"phoneNumber": "+15555551234",
"firstName": "Monica",
"id": "1c592f8a-59c6-4a09-82f8-f4257e3ea4c8",
"lastName": "Hall"
}
The following are example usages with a rendered output based upon the above mentioned example User. The replacement variables are rendered using Apache FreeMarker which is an HTML template language.
A default value should be provided for variables that may be undefined at runtime such as firstName
. See firstName
in the example below
is followed by a bang !
and then the string Unknown User
. This indicates that if firstName
is undefined when the template is rendered the value
of Unknown User
should be used as a default value.
Template Source
Hi ${user.firstName!'Unknown User'}, welcome to Pied Piper.
Please verify your phone number ${user.phoneNumber} by following the provided link.
https://piedpiper.fusionauth.io/identity/verify/${verificationId}
- Admin
Rendered Output
Hi Monica, welcome to Pied Piper.
Please verify your phone number +15555551234 by following the provided link.
https://piedpiper.fusionauth.io/identity/verify/YkQY5Gsyo4RlfmDciBGRmvfj3RmatUqrbjoIZ19fmw4
- Admin
Available Message Templates
Below is an overview of each message template that ships with FusionAuth.
The templates ship with a base URL of http://localhost:9011
for links, such as the verify or change password link. While this works for local development, for production, make sure to update all base URLs to a public URL, such as https://auth.example.com
.
One option is to store a base URL value on the tenant.data object. For example, set tenant.data.baseURL to https://auth.example.com
, and then access it from each template. Setting the tenant.data.baseURL field can be done using the API or the client libraries.
There is currently no support for changing the base URL in all templates in an instance, though there is an open feature request.
Forgot Password
This is also known as the “Change Password” template.
[#setting url_escaping_charset="UTF-8"]
To change your password click on the following link.
[#-- The optional 'state' map provided on the Forgot Password API call is exposed in the template as 'state'.
If we have an application context, append the client_id to ensure the correct application theme when applicable.
--]
[#assign url = "http://localhost:9011/password/change/${changePasswordId}?client_id=${(application.oauthConfiguration.clientId)!''}&tenantId=${user.tenantId}" /]
[#list state!{} as key, value][#if key != "tenantId" && key != "client_id" && value??][#assign url = url + "&" + key?url + "=" + value?url/][/#if][/#list]
${url}
- FusionAuth Admin
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
Note: This object may not be available depending upon when this template is constructed. If you utilize this object in your template, ensure you first check to see if it is defined.
changePasswordId
StringThe change password Id that must be included as a path segment in the /password/change
link. See the theme variables documentation for more information on how this value is used.
state
ObjectIf the state
was provided during the Forgot Password request, it will be available to you in the message template.
tenant
TenantThe Tenant object, see the Tenant API for field definitions.
user
UserThe User object, see the User API for field definitions of a User.
Passwordless Login
[#setting url_escaping_charset="UTF-8"]
You have requested to log into FusionAuth using this phone number. If you do not recognize this request please ignore this message.
[#if oneTimeCode??]
Login code: ${oneTimeCode}
[#else]
[#-- The optional 'state' map provided on the Start Passwordless API call is exposed in the template as 'state' --]
[#assign url = "http://localhost:9011/oauth2/passwordless/${code}?tenantId=${user.tenantId}" /]
[#list state!{} as key, value][#if key != "tenantId" && value??][#assign url = url + "&" + key?url + "=" + value?url/][/#if][/#list]
${url}
[/#if]
- FusionAuth Admin
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
Note: This object may not be available depending upon when this template is constructed. If you utilize this object in your template, ensure you first check to see if it is defined.
code
StringThe unique code intended to be used by the Complete a Passwordless Login API.
state
ObjectIf the state
was provided when the Passwordless request was initiated, it will be available to you in the template.
tenant
TenantThe Tenant object, see the Tenant API for field definitions of a Tenant.
user
UserThe User object, see the User API for field definitions of a User.
Phone Verification
[#-- When a one-time code is provided, you will want the user to enter this value interactively using a form. In this workflow the verificationId
is not shown to the user and instead the one-time code must be paired with the verificationId which is usually in a hidden form field. When the two
values are presented together, the phone number can be verified --]
[#if verificationOneTimeCode??]
Verification code: ${verificationOneTimeCode}
[#else]
To complete your phone number verification click on the following link.
http://localhost:9011/phone/verify/${verificationId}?client_id=${(application.oauthConfiguration.clientId)!''}&tenantId=${tenant.id}
[/#if]
- FusionAuth Admin
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
Note: This object may not be available depending upon when this template is constructed. If you utilize this object in your template, ensure you first check to see if it is defined.
tenant
TenantThe Tenant object, see the Tenant API for field definitions.
user
UserThe User object, see the User API for field definitions of a User.
verificationId
StringThe verification Id intended to be used by the Identity Verify API.
verificationOneTimeCode
StringThe verification One Time Code (OTP) to be used with the gated Phone Verification workflow. The user enters this code to verify their phone number.
Set Up Password
Your account has been created and you must click the following link to set a password.
http://localhost:9011/password/change/${changePasswordId}?client_id=${(application.oauthConfiguration.clientId)!''}&tenantId=${user.tenantId}
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
Note: This object may not be available depending upon when this template is constructed. If you utilize this object in your template, ensure you first check to see if it is defined.
changePasswordId
StringThe change password Id intended to be used by the Change a User’s Password API.
tenant
TenantThe Tenant object, see the Tenant API for field definitions.
user
UserThe User object, see the User API for field definitions of a User.
Threat Detected
This feature is only available in the Enterprise plan. Please visit our pricing page to learn more.
[#setting url_escaping_charset="UTF-8"]
[#if event.type == "UserLoginSuspicious"]
A suspicious login was made on your account. If this was you, you can safely ignore this message. If this wasn't you, we recommend that you change your password as soon as possible.
[#elseif event.type == "UserLoginNewDevice"]
A login from a new device was detected on your account. If this was you, you can safely ignore this message. If this wasn't you, we recommend that you change your password as soon as possible.
[#else]
Suspicious activity has been observed on your account. In order to secure your account, it is recommended to change your password at your earliest convenience.
[/#if]
Device details
* Device name: ${(event.info.deviceName)!'-'}
* Device description: ${(event.info.deviceDescription)!'-'}
* Device type: ${(event.info.deviceType)!'-'}
* User agent: ${(event.info.userAgent)!'-'}
Event details
* IP address: ${(event.info.ipAddress)!'-'}
* City: ${(event.info.location.city)!'-'}
* Country: ${(event.info.location.country)!'-'}
* Zipcode: ${(event.info.location.zipcode)!'-'}
* Lat/long: ${(event.info.location.latitude)!'-'}/${(event.info.location.longitude)!'-'}
- FusionAuth Admin
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
event.info
EventInfoThe EventInfo object, see the User Login Suspicious event definition for example field definitions.
tenant
TenantThe Tenant object, see the Tenant API for field definitions.
user
UserThe User object, see the User API for field definitions of a User.
Two Factor Authentication
This feature is only available in the Enterprise plan. Please visit our pricing page to learn more.
To complete your login request, enter this one-time code code on the login form when prompted.
${code}
- FusionAuth Admin
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
Note:
This object may not be available depending upon when this template is constructed. If you utilize this object in your template, ensure you first check to see if it is defined. You can check for this variable safely in FreeMarker using the missing value test operator and an if
statement:
[#if application??]
[#-- Use application here --]
[/#if]
This object is not available on the message template when:
- The multi-factor workflow was started without providing the
applicationId
on that request. - Multi-factor authentication is required during a call to the login API without providing the
applicationId
parameter. That documentation points out that there is likely no production use case where calling the API without theapplicationId
parameter is useful. - The message is being sent to enable or disable a multi-factor method without providing the
applicationId
on the request.
code
StringA code that the user must provide to complete multi-factor authentication.
email
StringEmail address associated with the user
.
mobilePhone
StringMobile phone number associated with the user
.
tenant
TenantThe Tenant object, see the Tenant API for field definitions.
user
UserThe User object, see the User API for field definitions of a User.
Two Factor Authentication Method Added
This feature is only available in the Enterprise plan. Please visit our pricing page to learn more.
The following two factor method was added to ${user.phoneNumber}:
- Method: ${method.method}
- Identifier: ${method.id}
- FusionAuth Admin
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
Note:
This object may not be available depending upon when this template is constructed. If you utilize this object in your template, ensure you first check to see if it is defined. You can check for this variable safely in freemarker by wrapping the variable as such: ${(application)!""}
.
event
EventThe Event object for a two factor add event. See the Webhooks & Events section for field definitions.
method
ObjectThe two-factor method that was added. See the Multi Factor/Two Factor APIs for property definitions and example JSON.
tenant
TenantThe Tenant object, see the Tenant API for field definitions.
user
UserThe User object, see the User API for field definitions of a User.
Two Factor Authentication Method Removed
This feature is only available in the Enterprise plan. Please visit our pricing page to learn more.
The following two factor method was removed from ${user.phoneNumber}:
- Method: ${method.method}
- Identifier: ${method.id}
- FusionAuth Admin
Replacement Variables
application
ApplicationThe Application object, see the Application API for field definitions.
Note:
This object may not be available depending upon when this template is constructed. If you utilize this object in your template, ensure you first check to see if it is defined. You can check for this variable safely in freemarker by wrapping the variable as such: ${(application)!""}
.
event
EventThe Event object for a two factor remove event. See the Webhooks & Events section for field definitions.
method
ObjectThe two-factor method that was removed. See the Multi Factor/Two Factor APIs for property definitions and example JSON.
tenant
TenantThe Tenant object, see the Tenant API for field definitions.
user
UserThe User object, see the User API for field definitions of a User.