| 1 | package Twilio::Http::BearerToken::ApiTokenManager; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use 5.016; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use parent 'Twilio::Http::BearerToken::TokenManager'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Twilio::CredentialProvider::NoAuthCredentialProvider; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use Twilio::Exceptions::TwilioException; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 3 | our $VERSION = '2.001'; | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 3 | my @TOKEN_OPTIONS = qw(client_id client_secret code redirect_uri audience refresh_token scope); | |||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | 25 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||||||||||||||||||
| 16 | 25 | my ($class, $options) = @_; | |||||||||||||||||||||||||||
| 17 | 25 | ▶ | $options //= {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$options //= {}
MC/DC0%0/1
$options //= {}
$options
Truth table50%1/2
A
A= $options
| |||||||||||||||||||||||||||||
| 18 | 25 | my $self = $class->SUPER::new; | |||||||||||||||||||||||||||
| 19 | 25 | ▶ | $self->{grant_type} = $options->{grant_type} // 'client_credentials'; | ||||||||||||||||||||||||||
|
Condition100%2/2
$options->{"grant_type"} // "client_credentials"
MC/DC100%1/1
$options->{"grant_type"} // "client_credentials"
$options->{"grant_type"}
Truth table100%2/2
A
A= $options->{"grant_type"}
| |||||||||||||||||||||||||||||
| 20 | 25 | $self->{$_} = $options->{$_} for @TOKEN_OPTIONS; | |||||||||||||||||||||||||||
| 21 | 25 | return $self; | |||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 19 | ▶ | sub fetch_token { | ||||||||||||||||||||||||||
|
Subroutine
fetch_token: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||
| 25 | 19 | my ($self, $client) = @_; | |||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | my $token = $self->_token_client($client) | ||||||||||||||||||||||||||||
| 28 | 19 | ->oauth->v2->token->create($self->{grant_type}, { map { $_ => $self->{$_} } @TOKEN_OPTIONS }); | |||||||||||||||||||||||||||
| 29 | 18 | my $access_token = $token->access_token; | |||||||||||||||||||||||||||
| 30 | 18 | ▶ | if (!defined $access_token || !length $access_token) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $access_token and length $access_token
MC/DC100%2/2
defined $access_token and length $access_token
defined $access_token
length $access_token
Truth table100%3/3
A and B
A= defined $access_tokenB= length $access_token
| |||||||||||||||||||||||||||||
| 31 | 2 | Twilio::Exceptions::TwilioException->throw('Twilio answered with no OAuth access token'); | |||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | 16 | return $access_token; | |||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | # The token request carries no credentials, so its client has none, and it can't ask for a | ||||||||||||||||||||||||||||
| 37 | # token itself. Unlike twilio-php, it goes through the caller's transport and settings, so a | ||||||||||||||||||||||||||||
| 38 | # proxy, a custom transport, an edge or a fake client in tests applies to it too. | ||||||||||||||||||||||||||||
| 39 | 19 | ▶ | sub _token_client { | ||||||||||||||||||||||||||
|
Subroutine
_token_client: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 40 | 19 | my ($self, $client) = @_; | |||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 19 | require Twilio::Rest::Client; | |||||||||||||||||||||||||||
| 43 | 19 | my %options = (credential_provider => Twilio::CredentialProvider::NoAuthCredentialProvider->new); | |||||||||||||||||||||||||||
| 44 | 19 | ▶ | return Twilio::Rest::Client->new(undef, undef, \%options) if !$client; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 19 | my $token_client = Twilio::Rest::Client->new( | |||||||||||||||||||||||||||
| 47 | undef, undef, | ||||||||||||||||||||||||||||
| 48 | { | ||||||||||||||||||||||||||||
| 49 | %options, | ||||||||||||||||||||||||||||
| 50 | environment => $client->get_environment, | ||||||||||||||||||||||||||||
| 51 | http_client => $client->get_http_client, | ||||||||||||||||||||||||||||
| 52 | region => $client->get_region, | ||||||||||||||||||||||||||||
| 53 | edge => $client->get_edge, | ||||||||||||||||||||||||||||
| 54 | max_retries => $client->get_max_retries, | ||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | ); | ||||||||||||||||||||||||||||
| 57 | 19 | $token_client->set_log_level($client->get_log_level); | |||||||||||||||||||||||||||
| 58 | 19 | return $token_client; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 3 | 1; | |||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | __END__ | ||||||||||||||||||||||||||||