NAME
Twilio::Jwt::Validation::ClientValidationJwt - The token that signs a request for client validation
SYNOPSIS
use Twilio::Jwt::Validation::ClientValidationJwt;
my $jwt = Twilio::Jwt::Validation::ClientValidationJwt->new(
$account_sid, $api_key_sid, $credential_sid, $private_key_pem,
{
method => 'POST',
path => '/2010-04-01/Accounts/ACxxx/Messages.json',
query_string => q{},
all_headers => { Authorization => 'Basic ...', Host => 'api.twilio.com' },
body => 'Body=Hi&To=%2B15558675309',
}
);
my $token = $jwt->to_jwt; # the value of the Twilio-Client-Validation header
DESCRIPTION
With Public Key Client Validation, every request to Twilio carries a JWT signed with the account's private key, and Twilio checks it with the public key it holds as a credential (CR...). The token covers the method, the path, the query, the Authorization and Host headers and the body, and lasts five minutes.
Twilio::Http::ValidationClient builds one for each request, so most code does not use this class directly. It follows ClientValidationJwt in twilio-python, and signs with RS256, which needs Crypt::OpenSSL::RSA.
METHODS
new
my $jwt = Twilio::Jwt::Validation::ClientValidationJwt->new(
$account_sid, $api_key_sid, $credential_sid, $private_key, \%validation_payload
);
The private key is in PEM form. The payload describes the request with method, path, query_string (without the ?), all_headers, body, and optionally signed_headers, which defaults to authorization and host. It throws Twilio::Exceptions::ConfigurationException when a value is missing.
to_jwt
Returns the signed token. Its header has cty twilio-pkrv;v=1 and kid, the credential SID.
get_payload
my $claims = $jwt->get_payload($now);
Returns the claims: iss (the API key), sub (the account), nbf, exp, hrh (the names of the signed headers) and rqh (the SHA-256 of the canonical request). $now defaults to the current time.
canonical_request
Returns the request in the form that is hashed into rqh.
LICENSE
Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.