# How to use Twilio API keys (not auth tokens) for passwordless SMS?

**URL:** <https://community.auth0.com/t/how-to-use-twilio-api-keys-not-auth-tokens-for-passwordless-sms/88975>\
**Category:** Get Help\
**Tags:** passwordless-sms, twilio\
**Created:** [August 18, 2022, 2:56pm UTC](https://community.auth0.com/t/how-to-use-twilio-api-keys-not-auth-tokens-for-passwordless-sms/88975 "2022-08-18T14:56:57Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![krazzy](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/krazzy/32/39394_2.png) [@krazzy](https://community.auth0.com/u/krazzy)\
**Post date:** [August 18, 2022, 2:56pm UTC](https://community.auth0.com/t/how-to-use-twilio-api-keys-not-auth-tokens-for-passwordless-sms/88975/1 "2022-08-18T14:56:57Z")

</div>

I know I can setup Auth0 passwordless SMS using a Twilio auth token, but using a Twilio API key would be more secure. I don’t see a way to do this through the management UI. Can this be done in some other way?

---

<div class="post-metadata">

**Author:** ![karaken12](https://sea1.discourse-cdn.com/auth0/user_avatar/community.auth0.com/karaken12/32/48750_2.png) [@karaken12](https://community.auth0.com/u/karaken12)\
**Post date:** [July 21, 2023, 12:05pm UTC](https://community.auth0.com/t/how-to-use-twilio-api-keys-not-auth-tokens-for-passwordless-sms/88975/2 "2023-07-21T12:05:38Z")

</div>

Hi, krazzy. I assume you’ve found something for your use case by now, but in case anyone else comes looking I thought I’d drop this in here. I needed this urgently and couldn’t find an answer, but fortunately it wasn’t too difficult a fix. My solution was to switch to a custom action instead of the built-in Twilio integration and use the API credentials in there. I needed to add it to the flow and select that option in the Security settings, too. The actual action needed the Twilio library adding, as well as a couple of secrets. The code I used is as follows, and your own will likely be very similar.

```auto
exports.onExecuteSendPhoneMessage = async (event, api) => {
  const accountSid = event.secrets.TWILIO_ACCOUNT_SID;
  const apiKey = event.secrets.TWILIO_API_KEY;
  const apiSecret = event.secrets.TWILIO_API_SECRET;
  const twilioSmsNumber = event.secrets.TWILIO_SMS_NUMBER;
  const message = event.message_options.text;
  const phoneNumber = event.message_options.recipient;

  const client = require('twilio')(apiKey, apiSecret, { accountSid: accountSid });
  const response = await client.messages.create({
    body: message,
    from: twilioSmsNumber,
    to: phoneNumber,
  });
  return response;
};

```

Hope this helps someone!

Best,  
Kara

---

<div class="post-metadata">

**Author:** ![system](https://global.discourse-cdn.com/auth0/original/3X/b/5/b560f266932fcce5d57f09a6595bd50518cae3f3.jpeg) [@system](https://community.auth0.com/u/system)\
**Post date:** [November 20, 2024, 8:11pm UTC](https://community.auth0.com/t/how-to-use-twilio-api-keys-not-auth-tokens-for-passwordless-sms/88975/3 "2024-11-20T20:11:21Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.
