File Coverage

blib/lib/Dancer2/Plugin/Auth/OAuth/Provider/Google.pm
Criterion Covered Total %
statement 17 17 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 23 26 88.4


line stmt bran cond sub pod time code
1              
2             use strict;
3 1     1   828 use parent 'Dancer2::Plugin::Auth::OAuth::Provider';
  1         2  
  1         39  
4 1     1   20  
  1         2  
  1         10  
5             use HTTP::Request::Common;
6 1     1   68  
  1         2  
  1         306  
7             version => 2,
8             urls => {
9 3     3 0 63 authorize_url => 'https://accounts.google.com/o/oauth2/auth',
10             access_token_url => 'https://accounts.google.com/o/oauth2/token',
11             user_info => 'https://www.googleapis.com/oauth2/v2/userinfo',
12             },
13             query_params => {
14             authorize => {
15             response_type => 'code',
16             scope => 'openid email',
17             }
18             }
19             } }
20              
21             my ($self, $session) = @_;
22              
23             my $session_data = $session->read('oauth');
24 1     1 0 5  
25             my $resp = $self->{ua}->request(
26 1         5 GET $self->provider_settings->{urls}{user_info},
27             Authorization => "Bearer ".$session_data->{google}{access_token}
28             );
29              
30             if( $resp->is_success ) {
31 1         23 my $user = $self->_stringify_json_booleans(
32             JSON::MaybeXS::decode_json( $resp->decoded_content )
33 1 50       405 );
34 1         25 $session_data->{google}{user_info} = $user;
35             $session->write('oauth', $session_data);
36             }
37 1         4 }
38 1         5  
39             1;