line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
64145
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
28
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
37
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
OAuth2::Google::Plus::UserInfo |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 DESCRIPTION |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
implements acallback to https://www.googleapis.com/oauth2/v2/userinfo, retrieving |
11
|
|
|
|
|
|
|
the users google-id, email and verification status. |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSYS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use OAuth2::Google::Plus::UserInfo; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $info = OAuth2::Google::Plus::UserInfo->new( access_token => $access_token ); |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
if( $info->is_success ) { |
20
|
|
|
|
|
|
|
my $email = $info->email; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
# ... |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
{ |
28
|
|
|
|
|
|
|
package OAuth2::Google::Plus::UserInfo; |
29
|
1
|
|
|
1
|
|
2571
|
use Moo; |
|
1
|
|
|
|
|
17480
|
|
|
1
|
|
|
|
|
7
|
|
30
|
1
|
|
|
1
|
|
3478
|
use MooX::late; |
|
1
|
|
|
|
|
50798
|
|
|
1
|
|
|
|
|
7
|
|
31
|
|
|
|
|
|
|
|
32
|
1
|
|
|
1
|
|
5297
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
70653
|
|
|
1
|
|
|
|
|
42
|
|
33
|
1
|
|
|
1
|
|
1320
|
use JSON qw|decode_json|; |
|
1
|
|
|
|
|
11800
|
|
|
1
|
|
|
|
|
6
|
|
34
|
1
|
|
|
1
|
|
959
|
use Carp::Assert; |
|
1
|
|
|
|
|
1075
|
|
|
1
|
|
|
|
|
6
|
|
35
|
1
|
|
|
1
|
|
113
|
use URI; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
354
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
has access_token => ( |
38
|
|
|
|
|
|
|
is => 'ro', |
39
|
|
|
|
|
|
|
isa => 'Str', |
40
|
|
|
|
|
|
|
required => 1, |
41
|
|
|
|
|
|
|
); |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
has _user_info => ( |
44
|
|
|
|
|
|
|
is => 'ro', |
45
|
|
|
|
|
|
|
isa => 'HashRef', |
46
|
|
|
|
|
|
|
lazy_build => 1, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has response => ( |
50
|
|
|
|
|
|
|
is => 'ro', |
51
|
|
|
|
|
|
|
writer => '_set_response', |
52
|
|
|
|
|
|
|
); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
has _endpoint => ( |
55
|
|
|
|
|
|
|
is => 'ro', |
56
|
|
|
|
|
|
|
default => sub { |
57
|
|
|
|
|
|
|
return 'https://www.googleapis.com/oauth2/v2/userinfo'; |
58
|
|
|
|
|
|
|
}, |
59
|
|
|
|
|
|
|
); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
sub _build__user_info { |
62
|
2
|
|
|
2
|
|
689
|
my ( $self ) = @_; |
63
|
|
|
|
|
|
|
|
64
|
2
|
|
|
|
|
23
|
my $ua = LWP::UserAgent->new; |
65
|
2
|
|
|
|
|
13768
|
$ua->default_header( Authorization => 'OAuth ' . $self->access_token ); |
66
|
|
|
|
|
|
|
|
67
|
2
|
|
|
|
|
123
|
my $response = $ua->get( $self->_endpoint ); |
68
|
2
|
|
|
|
|
45195
|
$self->_set_response( $response ); |
69
|
|
|
|
|
|
|
|
70
|
2
|
100
|
|
|
|
11
|
if( $response->is_success ){ |
71
|
1
|
|
|
|
|
24
|
my $json = decode_json( $response->content ); |
72
|
1
|
|
|
|
|
106
|
return $json; |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
1
|
|
|
|
|
62
|
return {}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub is_success { |
79
|
2
|
|
|
2
|
0
|
2106
|
my ( $self ) = @_; |
80
|
2
|
|
|
|
|
59
|
return defined( $self->_user_info->{id} ); |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub email { |
84
|
2
|
|
|
2
|
0
|
4535
|
my ( $self ) = @_; |
85
|
2
|
|
|
|
|
29
|
return $self->_user_info->{email}; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub id { |
89
|
2
|
|
|
2
|
0
|
1599
|
my ( $self ) = @_; |
90
|
2
|
|
|
|
|
60
|
return $self->_user_info->{id}; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
sub verified_email { |
94
|
2
|
|
|
2
|
0
|
1029
|
my ( $self ) = @_; |
95
|
2
|
|
|
|
|
54
|
return $self->_user_info->{verified_email}; |
96
|
|
|
|
|
|
|
} |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |