NAME

Twilio::Http::BearerToken::ApiTokenManager - Gets OAuth tokens from Twilio

DESCRIPTION

Used by Twilio::CredentialProvider::ClientCredentialProvider. It asks https://oauth.twilio.com/v2/token for an access token, with $client->oauth->v2->token->create.

METHODS

new

my $token_manager = Twilio::Http::BearerToken::ApiTokenManager->new({
  grant_type    => 'client_credentials',
  client_id     => $client_id,
  client_secret => $client_secret,
});

grant_type defaults to client_credentials. The other options, all sent as given, are client_id, client_secret, code, redirect_uri, audience, refresh_token and scope.

fetch_token

my $token = $token_manager->fetch_token($client);

Returns a new access token. The request has no credentials besides the options, and uses the transport, edge, region, retries and log level of $client. With no $client, it uses a new Twilio::Rest::Client with the defaults.

It throws Twilio::Exceptions::RestException when Twilio refuses the request, and Twilio::Exceptions::TwilioException when the answer has no token.

LICENSE

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