> ## Documentation Index
> Fetch the complete documentation index at: https://auth0.generaltranslation.app/llms.txt
> Use this file to discover all available pages before exploring further.

> Learn how to configure a custom phone provider with Twilio Verify

# Configure a Custom Phone Provider with Twilio Verify

You can configure a custom phone provider with [Twilio Verify](https://www.twilio.com/docs/verify), which helps fight fraud and protect user accounts. This sets up Twilio Verify as your custom phone provider.

## Prerequisites

You must have a [Twilio](https://twilio.com/) account with a valid SMS and/or phone delivery option.

## Set up Twilio Verify service

You can create a Twilio Verify service through the [Twilio Console](https://www.twilio.com/console/verify/services) or the [Verify REST API](https://www.twilio.com/docs/verify/api/service#create-a-verification-service). You will need the following to connect your Auth0 custom phone provider with Twilio Verify:

* TWILIO\_ACCOUNT\_SID
* TWILIO\_AUTH\_TOKEN
* TWILIO\_VERIFY\_SID

## Connect custom phone provider with Twilio Verify

1. In the Auth0 Dashboard, navigate to [Branding > Phone Provider](https://manage.auth0.com/dashboard/#/phone/templates/phone/provider). This takes you to the **Phone Message Provider** page.
2. Select **Custom** as a **Phone Provider**.
3. Under **Provider Configuration**, add the following code sample to allow the Twilio API to send phone messages to a user's phone number:

```javascript lines expandable theme={null}
/**
* Handler to be executed while sending a phone notification
* @param {Event} event - Details about the user and the context in which they are logging in.
* @param {CustomPhoneProviderAPI} api - Methods and utilities to help change the behavior of sending a phone notification.
*/
exports.onExecuteCustomPhoneProvider = async (event, api) => {
 const { TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN, TWILIO_VERIFY_SID } = event.secrets;

  const client = require('twilio')(TWILIO_ACCOUNT_SID, TWILIO_AUTH_TOKEN);

  // map auth0 voice value to call
  const messageType = event.notification.delivery_method === 'voice' ? 'call' : 'sms';

  const { recipient, code } = event.notification;

  // add this to fix " 1333444999  "
  // "333 444 5555"
  const sanitizedNumber = recipient.replace(/\s/g, '').trim();

  await client.verify.v2.services(TWILIO_VERIFY_SID)
    .verifications.create({
      to: sanitizedNumber,
      channel: messageType,
      customCode: code
    })

};
```

3. Click the **Key** icon to open the **Secrets** menu. Add the following values from your Twilio Verify service setup:

* TWILIO\_ACCOUNT\_SID
* TWILIO\_AUTH\_TOKEN
* TWILIO\_VERIFY\_SID

4. To load the Twilio helper library, click the **Dependency** icon. Then, click the **Add Dependency** button. When the **Add Dependency** pop-up window appears, enter the following:

* **Name:** Twilio
* **Version:** latest (should be auto populated)

When you click **Create**, Auth0 will search for the Twilio helper library and load the latest version.

5. Click **Save**. When you click **Save,** the Action automatically saves and deploys. To test the custom phone provider configuration before using it in a production environment, click **Send Test Message**.
