This code is just for demo purposes. The TOTPService
class is basicaly to show you how you can verify TOTP codes using invocable actions in Salesforce from Flows and other components, or directly from Apex. It’s like adding an extra security layer for your records and processes. In this demo, we’ve included a couple of fields and a triggered Flow to illustrate how it works. Imagine your account is a VIP – this setup prevents any changes to your data without a valid TOTP code.
Note: It’s been a bit challenging to test with stubs, so we’re using dependency injection among other things to make testing easier and more effective.
To deploy the TOTPService
, you can either deploy the entire repository or just the necessary classes if you prefer to implement your own examples.
- Clone the repository or download the zip file.
- Deploy the
TOTPService
class. - Optionally, deploy the
TOTP_Triggered_flow_Action_Account
Flow and fields (TOTP__c
andVIP__c
) for testing. - Drag the account fields to the Account Lightning page.
The TOTPService
class provides an invocable method verify TOTP
that can be used in Salesforce Flows. This method verifies the provided TOTP code and returns the verification result.
- Add an action in your Triggered-Flow and select
Verify TOTP
. - Provide the necessary inputs (TOTP code).
- Use the output of the action to handle the verification result in your Flow logic.
You can also use the TOTPService
class directly from Apex code. Here's an example of how to call the service from an anonymous Apex block:
TOTPService.VerificationRequest request = new TOTPService.VerificationRequest();
request.totpCode = '123456'; // Set a valid TOTP code
TOTPService.VerificationResult result = (new TOTPService()).verify(request);
System.debug('Verification Result: ' + result.message);
System.debug('Is Success: ' + result.isSuccess);
Any comments, feedback, suggestions for improvement, or reports of bugs are more than welcome. Feel free to reach me out at develop@mpdigitals.com.