Newer Version Available
CustomOneTimePasswordDeliveryHandler Interface
To use a custom SMS provider to send one-time passwords (OTPs) for Experience Cloud
identity verification, create a class that implements the Auth.CustomOneTimePasswordDeliveryHandler interface.
Namespace
CustomOneTimePasswordDeliveryHandler Methods
The following are methods for CustomOneTimePasswordDeliveryHandler.
sendOneTimePassword(userId, phoneNumber, oneTimePassword, networkId, defaultText, expId)
Calls out to an external SMS messaging provider to send a Salesforce one-time password to
an external user for identity verification. Returns an Auth.CustomOneTimePasswordDeliveryResult indicating whether the provider sent the
message.
Signature
public Auth.CustomOneTimePasswordDeliveryResult sendOneTimePassword(Id userId, String phoneNumber, String oneTimePassword, String defaultText, Id networkId, String experienceId)
Parameters
- userId
- Type: Id
- ID of the external user.
- phoneNumber
- Type: String
- The user’s phone number. The phone number isn't necessarily verified by Salesforce.
- oneTimePassword
- Type: String
- The OTP that the user receives.
- networkId
- Type: String
- ID of the Experience Cloud site.
- defaultText
- Type: Id
- The content of the default SMS message that the user receives. You can create custom messages instead of sending the default. For example, write code to send custom messages based on the Experience Cloud site ID.
- expId
- Type: String
- A custom value that determines what the user experiences.
Return Value
CustomOneTimePasswordDeliveryHandler Example Implementation
This example implements the Auth.CustomOneTimePasswordDeliveryHandler interface. For a detailed explanation of
this example, see Example: Custom One-Time Password
Delivery Handler in Salesforce
Help.
1global class TelesignMessaging implements Auth.CustomOneTimePasswordDeliveryHandler{
2
3 global Auth.CustomOneTimePasswordDeliveryResult sendOneTimePassword(Id userId, String phoneNumber, String oneTimePassword,
4 String defaultText, Id networkId, String experienceId){
5
6 //Send the message from Telesign
7 HttpRequest request = new HttpRequest();
8 //The commented-out code on the next line isn't necessary if you use named credentials
9 //request.setEndpoint('https://rest-ww.telesign.com/v1/messaging');
10 request.setEndpoint('callout:Telesign_SMS_Named');
11 request.setMethod('POST');
12 String requestBody = 'is_primary=true&phone_number=' + phoneNumber + '&message='+'Custom OTP%20'+ oneTimePassword+';
13'+defaultText+'&message_type=OTP';
14
15 request.setHeader('accept', 'application/json');
16 request.setHeader('content-type', 'application/x-www-form-urlencoded');
17 //The commented-out code on the next line isn't necessary if you use named credentials
18 //request.setHeader('authorization', 'Basic <Base64-encoded Telesign customer ID:API key>');
19 request.setBody(requestBody);
20
21 HttpResponse response = new Http().send(request);
22 // Handle the response as needed
23 return Auth.CustomOneTimePasswordDeliveryResult.SUCCESS;
24 }
25}