| 1 | package Google::Cloud::Speech::Auth; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Mojo::Base '-base'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Mojo::Collection; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use Mojo::JSON qw(encode_json decode_json); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Mojo::JWT::Google; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Mojo::UserAgent; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 0 | ▶ | has scopes => sub { ['https://www.googleapis.com/auth/cloud-platform']; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 10 | 1 | has grant_type => 'urn:ietf:params:oauth:grant-type:jwt-bearer'; | |||||||||||||||||||||||||||
| 11 | 1 | has oauth_url => 'https://www.googleapis.com/oauth2/v4/token'; | |||||||||||||||||||||||||||
| 12 | 0 | ▶ | has ua => sub { Mojo::UserAgent->new; }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 13 | 1 | ▶ | has from_json => sub { }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 1 | has jwt_token_enc => undef; | |||||||||||||||||||||||||||
| 15 | 1 | has jwt_token => undef; | |||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 0 | ▶ | sub jwt { | ||||||||||||||||||||||||||
|
Subroutine
jwt: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 18 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 0 | return Mojo::JWT::Google->new( | |||||||||||||||||||||||||||
| 21 | from_json => $self->from_json, | ||||||||||||||||||||||||||||
| 22 | target => $self->oauth_url, | ||||||||||||||||||||||||||||
| 23 | scopes => Mojo::Collection->new( $self->scopes )->flatten, | ||||||||||||||||||||||||||||
| 24 | issue_at => time, | ||||||||||||||||||||||||||||
| 25 | expires_in => 20, | ||||||||||||||||||||||||||||
| 26 | ); | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 1 | has token => undef; | |||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 0 | ▶ | sub request_token { | ||||||||||||||||||||||||||
|
Subroutine
request_token: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 32 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 0 | $self->jwt_token( $self->jwt ); | |||||||||||||||||||||||||||
| 35 | 0 | $self->jwt_token_enc( $self->jwt_token->encode ); | |||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 0 | my $tx = $self->ua->post( | |||||||||||||||||||||||||||
| 38 | $self->oauth_url, | ||||||||||||||||||||||||||||
| 39 | form => { | ||||||||||||||||||||||||||||
| 40 | grant_type => $self->grant_type, | ||||||||||||||||||||||||||||
| 41 | assertion => $self->jwt_token_enc | ||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||
| 43 | ); | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 0 | my $res = $tx->res; | |||||||||||||||||||||||||||
| 46 | 0 | ▶ | if ( $res->is_success and $res->json('/access_token') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$res->is_success and $res->json("/access_token")
MC/DC0%0/2
$res->is_success and $res->json("/access_token")
$res->is_success
$res->json("/access_token")
Truth table0%0/3
A and B
A= $res->is_successB= $res->json("/access_token")
| |||||||||||||||||||||||||||||
| 47 | 0 | my $token_obj = $res->json; | |||||||||||||||||||||||||||
| 48 | 0 | my $token = $token_obj->{'token_type'} . ' ' . $token_obj->{'access_token'}; | |||||||||||||||||||||||||||
| 49 | 0 | $self->{'token'} = $token; | |||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||
| 51 | 0 | return $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my $error_obj = $tx->res->json; | |||||||||||||||||||||||||||
| 55 | 0 | die "No authorization provided: `$error_obj->{error_description}`"; | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||
| 58 | 0 | ▶ | sub has_valid_token { | ||||||||||||||||||||||||||
|
Subroutine
has_valid_token: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 59 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 60 | 0 | ▶ | return undef unless my $token = $self->token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | return undef unless my $jwt = $self->jwt_token; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | return undef | ||||||||||||||||||||||||||||
| 63 | 0 | ▶ | unless my $expires_in | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 64 | = $self->jwt_token->issue_at + $self->jwt_token->expires_in; | ||||||||||||||||||||||||||||
| 65 | 0 | ▶ | return undef unless time < ( $expires_in - 10 ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 0 | return 1; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||
| 70 | 0 | ▶ | sub refresh { | ||||||||||||||||||||||||||
|
Subroutine
refresh: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 71 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | 0 | delete $self->{'token'}; | |||||||||||||||||||||||||||
| 74 | 0 | $self->{'token'} = $self->_request_token; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 0 | return $self; | |||||||||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 1 | 1; | |||||||||||||||||||||||||||