File Coverage

blib/lib/Dancer2/Plugin/Auth/OAuth/Provider/Linkedin.pm
Criterion Covered Total %
statement 21 21 100.0
branch 2 4 50.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 28 32 87.5


line stmt bran cond sub pod time code
1              
2             use strict;
3 1     1   432 use parent 'Dancer2::Plugin::Auth::OAuth::Provider';
  1         2  
  1         28  
4 1     1   5  
  1         2  
  1         5  
5             use HTTP::Request::Common;
6 1     1   50  
  1         3  
  1         262  
7             version => 2,
8             urls => {
9 3     3 0 35 access_token_url => "https://www.linkedin.com/oauth/v2/accessToken",
10             authorize_url => "https://www.linkedin.com/oauth/v2/authorization",
11             user_info => "https://api.linkedin.com/v1/people/~?format=json",
12             },
13             query_params => {
14             authorize => {
15             response_type => 'code',
16             }
17             }
18             } }
19              
20             my ($self, $session) = @_;
21              
22             my $session_data = $session->read('oauth');
23 1     1 0 3  
24             my $fields = '';
25 1         3 if ( exists $self->provider_settings->{fields} ) {
26             $fields = sprintf(":(%s)", $self->provider_settings->{fields});
27 1         20 $self->provider_settings->{urls}{user_info} =~ s/~\?/~$fields?/;
28 1 50       3 }
29 1         3  
30 1         3 my $resp = $self->{ua}->request(
31             GET $self->provider_settings->{urls}{user_info},
32             Authorization => "Bearer ".$session_data->{linkedin}{access_token}
33             );
34              
35             if( $resp->is_success ) {
36 1         4 my $user = $self->_stringify_json_booleans(
37             JSON::MaybeXS::decode_json( $resp->decoded_content )
38 1 50       499 );
39 1         12 $session_data->{linkedin}{user_info} = $user;
40             $session->write('oauth', $session_data);
41             }
42 1         5 }
43 1         5  
44             1;