File Coverage

blib/lib/Dancer2/Plugin/Auth/OAuth/Provider/Stackexchange.pm
Criterion Covered Total %
statement 18 18 100.0
branch 1 2 50.0
condition n/a
subroutine 5 5 100.0
pod 0 2 0.0
total 24 27 88.8


line stmt bran cond sub pod time code
1              
2             use strict;
3 1     1   835 use parent 'Dancer2::Plugin::Auth::OAuth::Provider';
  1         2  
  1         38  
4 1     1   5  
  1         3  
  1         9  
5             use HTTP::Request::Common;
6 1     1   88  
  1         2  
  1         304  
7             urls => {
8             access_token_url => "https://stackexchange.com/oauth/access_token",
9 3     3 0 50 authorize_url => "https://stackexchange.com/oauth",
10             user_info => "https://api.stackexchange.com/2.2/me",
11             }
12             } }
13              
14             my ($self, $session) = @_;
15              
16             my $session_data = $session->read('oauth');
17 1     1 0 4 my $provider_settings = $self->provider_settings;
18              
19 1         5 my $resp = $self->{ua}->request(
20 1         22 GET $provider_settings->{urls}{user_info}.
21             "?access_token=".$session_data->{stackexchange}{access_token}.
22             "&site=".$provider_settings->{site}.
23             "&key=".$provider_settings->{tokens}{key}
24             );
25              
26             if( $resp->is_success ) {
27 1         11 my $user = $self->_stringify_json_booleans(
28             JSON::MaybeXS::decode_json( $resp->decoded_content )
29 1 50       443 );
30 1         14 $session_data->{stackexchange}{user_info} = $user;
31             $session->write('oauth', $session_data);
32             }
33 1         4 }
34 1         6  
35             1;