Security
Twilio through Yomenie
Connect Twilio once in Vault › Providers, use it from every project, and call it from any Twilio SDK with a short custom HTTP client.
Updated
Connect Twilio once in Vault › Providers, add it to a project (From a provider), and your apps call Twilio through Yomenie with a short-lived pass. The API key secret stays in the Vault.
What your app gets
TWILIO_ACCOUNT_SID, TWILIO_API_KEY, TWILIO_API_SECRET (the pass) and TWILIO_BASE_URL (https://yomenie.us/api/v1/proxy/twilio). Ask your AI tool “Load Twilio for cleaningsearch Staging” and it sets them for the app (get_project_variables).
Twilio’s hosts become the first part of the path: https://api.twilio.com/2010-04-01/… is $TWILIO_BASE_URL/api/2010-04-01/…, and https://messaging.twilio.com/v1/… is $TWILIO_BASE_URL/messaging/v1/…. The hosts Yomenie knows: api, messaging, verify, conversations, voice, video, lookups and studio.
curl and fetch
curl -u "$TWILIO_API_KEY:$TWILIO_API_SECRET" \
"$TWILIO_BASE_URL/api/2010-04-01/Accounts/$TWILIO_ACCOUNT_SID/Messages.json" \
--data-urlencode "To=+61400000000" --data-urlencode "From=+61400000001" --data-urlencode "Body=Hello from acme"
Yomenie reads the pass from the Basic password, replaces the header with your real API key, and sends the call on.
Twilio SDKs
Twilio’s SDKs don’t take a base URL, but each takes a custom HTTP client. These few lines send every call to Yomenie instead of *.twilio.com.
Node (twilio):
import twilio from "twilio";
const { RequestClient } = twilio;
class YomenieClient extends RequestClient {
request(opts) {
const u = new URL(opts.uri);
const host = u.hostname.split(".")[0]; // api, messaging, verify…
return super.request({ ...opts, uri: `${process.env.TWILIO_BASE_URL}/${host}${u.pathname}${u.search}` });
}
}
const client = twilio(process.env.TWILIO_API_KEY, process.env.TWILIO_API_SECRET, {
accountSid: process.env.TWILIO_ACCOUNT_SID,
httpClient: new YomenieClient(),
});
Python (twilio):
import os
from urllib.parse import urlsplit
from twilio.http.http_client import TwilioHttpClient
from twilio.rest import Client
class YomenieClient(TwilioHttpClient):
def request(self, method, url, *args, **kwargs):
u = urlsplit(url)
host = u.hostname.split(".")[0]
url = f"{os.environ['TWILIO_BASE_URL']}/{host}{u.path}" + (f"?{u.query}" if u.query else "")
return super().request(method, url, *args, **kwargs)
client = Client(os.environ["TWILIO_API_KEY"], os.environ["TWILIO_API_SECRET"],
os.environ["TWILIO_ACCOUNT_SID"], http_client=YomenieClient())
Go (twilio-go): wrap the default client and rewrite the URL the same way.
type yomenie struct{ client.Client }
func (y *yomenie) SendRequest(method, raw string, data url.Values, headers map[string]interface{}, body ...byte) (*http.Response, error) {
u, _ := url.Parse(raw)
host := strings.Split(u.Hostname(), ".")[0]
return y.Client.SendRequest(method, os.Getenv("TWILIO_BASE_URL")+"/"+host+u.RequestURI(), data, headers, body...)
}
Java (HttpClient), C# (SystemNetHttpClient), PHP (CurlClient) and Ruby (Twilio::HTTP::Client) take a custom client the same way: take the first part of the host, put it after TWILIO_BASE_URL, keep the path and query.
Test credentials
Twilio’s test credentials work for a Local row, with their test Account SID as the username. They only answer a few endpoints with Twilio’s magic numbers, so they can’t send real messages.
Webhooks
Twilio signs the callbacks it sends your app (incoming messages and calls, delivery status). To check those signatures, keep a webhook signing key as an ordinary secret in the project, linked as a variable. Yomenie doesn’t verify Twilio’s callbacks for you yet.