Overview
This article explains how to automate Salesforce's Time-Based One-Time Password (TOTP) authentication using Virtuoso's JavaScript extension.
It covers retrieving the Salesforce OTP secret, configuring the extension, and generating verification codes during journey execution.
1. Prerequisites
Before starting, ensure you have:
- Access to the Salesforce account requiring OTP authentication.
- Access to Virtuoso's JavaScript Extensions.
- Google Authenticator or Microsoft Authenticator for initial verification.
- A secure location to store the OTP secret.
2. Obtain the OTP Secret from Salesforce
- Log in to Salesforce.
- Select Other Verification Options → One-Time Password Authenticator App, if prompted.
- On the Connect an Authenticator App page, click I Can't Scan the QR Code.
- Copy the shared secret displayed by Salesforce.
- Register the same secret in Google Authenticator or Microsoft Authenticator and complete Salesforce enrollment.
Important: Keep the secret secure, as it will be used by Virtuoso to generate OTPs automatically.
[Screenshot 1: Salesforce manual setup key screen, with the secret hidden]
3. Configure the OTP Extension in Virtuoso
Step 1: Open the Extension Manager
Open the JavaScript extension named OTP_Authenticator_V3 in Virtuoso.
If the extension does not exist, create a new JavaScript extension with the same functionality.
Step 2: Configure the Parameter
Under Parameters, add:
| Parameter | Description |
|---|---|
secret | Shared TOTP secret obtained from Salesforce |
Step 3: Add the Required Resources
Under Resources, add:
https://unpkg.com/@otplib/preset-browser@^12.0.0/buffer.js https://unpkg.com/@otplib/preset-browser@^12.0.0/index.js
Step 4: Add the JavaScript Code
const key = String(secret)
.trim()
.replace(/\s+/g, "")
.toUpperCase();
otplib.authenticator.resetOptions();
otplib.authenticator.options = {
algorithm: "sha1",
digits: 6,
step: 30
};
return otplib.authenticator.generate(key);Save the extension.
[Screenshot 2: Virtuoso Extension Manager showing the parameter, resources, and code]
4. Configure the Journey
Store the Salesforce shared secret securely and reference it using a variable such as $Totp.
Add the following steps to your Salesforce login journey:
| Step | Virtuoso action |
|---|---|
| 1 | OTP_Authenticator_V3($Totp) returning $token |
| 2 | Write $token in field "Verification Code" |
| 3 | Click on "Verify" |
| 4 | Verify successful Salesforce login |
During initial enrollment, the submission button may be labelled Connect instead of Verify.
[Screenshot 3: Virtuoso journey showing OTP generation and verification steps]
Note: Generate the OTP immediately before submitting it, as the code changes every 30 seconds.
5. Troubleshooting
| Issue | Recommended action |
|---|---|
| Virtuoso OTP differs from Google/Microsoft Authenticator | Confirm both use the same registered secret and SHA-1 configuration. |
| Salesforce rejects the generated OTP | Check whether the code expired or the registered secret changed. |
| OTP matches only in the previous or next time window | Check clock synchronization between the execution environment and authenticator. |
| OTP stopped working after MFA reset | Update Virtuoso with the newly registered secret. |
| Journey steps pass but login fails | Add an assertion to confirm successful Salesforce login. |
Re-registering an Existing Authenticator
If the original shared secret is unavailable:
- In Salesforce, navigate to Advanced User Details.
- Locate App Registration: One-Time Password Authenticator.
- Click Disconnect, provided you have an approved recovery method or administrator assistance.
- Re-enroll the authenticator and obtain the new shared secret.
- Update the secure Virtuoso variable and verify that the generated OTP matches.
6. Important Notes
- Initial authenticator enrollment is a one-time activity. Subsequent journeys only need to generate and submit OTPs.
- Do not expose shared secrets in journey steps, screenshots, or execution logs.
- Ensure automated OTP authentication is permitted by the customer's security policies.
- Use an approved secure storage mechanism for the secret and rotate it if exposed.
7. Expected Result
Once configured, Virtuoso generates the same six-digit OTP as the registered authenticator application and uses it to complete Salesforce login verification automatically.
Comments
0 comments
Please sign in to leave a comment.