Custom One-Time Password Delivery Process
If you use a custom one-time password (OTP) delivery provider instead of the Salesforce default provider, your provider sends OTP messages to end users.
Required Editions
| Available in: both Salesforce Classic (not available in all orgs) and Lightning Experience |
| Available in: Professional, Enterprise, Unlimited, and Developer Editions |
Custom OTP delivery relies on an Apex handler that implements the Auth.CustomOneTimePasswordDeliveryHandler interface. The interface uses the
sendOneTimePassword method, where you pass in multiple
parameters, including the OTP generated by Salesforce, the user's phone number, the user ID,
and the Experience Cloud site ID, among other parameters. You can use custom code to compose
the content of the message. To send the message, your handler makes an API callout to a
messaging endpoint that's hosted on the provider then handles the response.
This process can begin whenever you require an external user to verify their identity using SMS. The entry point depends on your use case. These use cases support identity verification with SMS.
- Multi-factor authentication
- Passwordless login
- Passwordless registration
- Self-registration
- Headless passwordless login
- Headless passwordless registration
For example, if you use passwordless login, this flow can begin when a user goes to your Experience Cloud site login page and enters their phone number to log in.
- Salesforce calls the
sendOneTimePasswordmethod in the custom OTP delivery Apex handler. - Your Apex implementation uses the
sendOneTimePasswordmethod to send an authenticated request to the provider's callout endpoint. The request includes the user's ID, their phone number, the message content, the Salesforce OTP, and any other parameters that the provider requires.
Note Your Apex implementation is responsible for connecting to the provider and delivering the SMS message. Salesforce doesn't provide this functionality by default. - The provider returns a response, which your Apex handler captures and processes. How you process the response depends on your provider.
- If the response is successful, your handler returns the
Auth.CustomOneTimePasswordDeliveryResultenum valueSUCCESS. - The provider sends an OTP to the user's phone number.
- The user enters the OTP in your Experience Cloud site verification form.
- Salesforce verifies the OTP. This step depends on your use case. For example, for
passwordless login, you can use the
verifyPasswordlessLoginmethod in theSystem.UserManagementclass. - The user's identity is logged in or registered, depending on your use case.

