NAME

Twilio::Http::ValidationClient - An HTTP client that signs each request for Public Key Client Validation

SYNOPSIS

use Twilio;
use Twilio::Http::ValidationClient;

my $http = Twilio::Http::ValidationClient->new({
  account_sid    => $account_sid,       # AC...
  api_key_sid    => $api_key_sid,       # SK...
  credential_sid => $credential_sid,    # CR..., the public key you gave Twilio
  private_key    => $private_key_pem,
});
my $client = Twilio->new($api_key_sid, $api_key_secret,
  { account_sid => $account_sid, http_client => $http });

DESCRIPTION

When an account enforces Public Key Client Validation (a setting in the Twilio Console), Twilio accepts only requests that carry a Twilio-Client-Validation header: a JWT signed with the account's private key. This client adds one to every request; see Twilio::Jwt::Validation::ClientValidationJwt.

To set it up, create an RSA key pair, give Twilio the public key as a credential ($client->accounts->v1->credentials->public_key->create($pem), which returns the CR... SID), and use this client with an API key. It works like Twilio::Http::TinyClient otherwise, and takes its options too. It is the ValidationClient of twilio-python and twilio-node; twilio-php has none.

Use it only with an account that has the setting on. Twilio refuses a signed request to any other account, with HTTP 401 and "Public key client validation is not enabled for the account" (seen on 2026-11-11).

Signing needs the optional module Crypt::OpenSSL::RSA, version 0.38 or later, or one before 0.35.

METHODS

new

my $http = Twilio::Http::ValidationClient->new(\%options);

account_sid, api_key_sid, credential_sid and private_key (in PEM form) are required. It throws Twilio::Exceptions::ConfigurationException when one is missing, and Twilio::Exceptions::TwilioException when the key can't sign.

prepare_request

Prepares the request as the parent class does, and adds the Twilio-Client-Validation header.

validation_token

my $token = $http->validation_token($request);

Returns the signed token for a prepared request, covering its Authorization and Host headers.

LICENSE

Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.