NAME
Twilio::AuthStrategy::TokenAuthStrategy - Requests with an OAuth access token
DESCRIPTION
Returned by Twilio::CredentialProvider::ClientCredentialProvider. It sends Authorization: Bearer with a token from its token manager, and keeps that token until 30 seconds before the expiry written in it, so most requests don't ask for a new one.
A token is a JWT, and its exp claim gives the expiry. A token whose expiry can't be read counts as expired, so a token manager that returns something other than a JWT gets a new token for each request.
METHODS
new
my $strategy = Twilio::AuthStrategy::TokenAuthStrategy->new($token_manager);
$token_manager is a Twilio::Http::BearerToken::TokenManager.
get_auth_string
my $header = $strategy->get_auth_string($client);
Returns Bearer and the token from "fetch_token".
requires_authentication
Returns true.
fetch_token
my $token = $strategy->fetch_token($client);
Returns the token it holds, or asks the token manager for a new one when it has none or it is about to expire. $client is passed to the token manager. An error from the token manager reaches the caller.
is_token_expired
my $expired = $strategy->is_token_expired($token);
Returns true when the token expires within 30 seconds, or its expiry can't be read.
LICENSE
Copyright (c) 2026 Francisco Zarabozo. Released under the MIT License.