line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
####################################################################### |
2
|
|
|
|
|
|
|
# ex: set ts=8 sw=4 et |
3
|
|
|
|
|
|
|
######################################################################### |
4
|
|
|
|
|
|
|
package WWW::Facebook::API::Auth; |
5
|
|
|
|
|
|
|
|
6
|
34
|
|
|
34
|
|
175
|
use warnings; |
|
34
|
|
|
|
|
69
|
|
|
34
|
|
|
|
|
1042
|
|
7
|
34
|
|
|
34
|
|
181
|
use strict; |
|
34
|
|
|
|
|
76
|
|
|
34
|
|
|
|
|
946
|
|
8
|
34
|
|
|
34
|
|
172
|
use Carp; |
|
34
|
|
|
|
|
68
|
|
|
34
|
|
|
|
|
2067
|
|
9
|
|
|
|
|
|
|
|
10
|
34
|
|
|
34
|
|
48277
|
use Readonly; |
|
34
|
|
|
|
|
120404
|
|
|
34
|
|
|
|
|
48336
|
|
11
|
|
|
|
|
|
|
Readonly my $DEFAULT_SLEEP => 15; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
sub create_token { |
14
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
15
|
0
|
|
|
|
|
|
my $token; |
16
|
0
|
|
|
|
|
|
my ( $format, $parse ) = ( $self->base->format, $self->base->parse ); |
17
|
|
|
|
|
|
|
|
18
|
0
|
|
|
|
|
|
$self->base->format('JSON'); |
19
|
0
|
|
|
|
|
|
$self->base->parse(0); |
20
|
|
|
|
|
|
|
|
21
|
0
|
|
|
|
|
|
$token = $self->base->call( 'auth.createToken', @_ ); |
22
|
0
|
|
|
|
|
|
$token =~ s/\W//xmsg; |
23
|
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
$self->base->format($format); |
25
|
0
|
|
|
|
|
|
$self->base->parse($parse); |
26
|
|
|
|
|
|
|
|
27
|
0
|
|
|
|
|
|
return $token; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_session { |
31
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $token = shift; |
34
|
0
|
0
|
|
|
|
|
croak q{Token needed for call to get_session} if not defined $token; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
# Mappings between the response fields and the WFA fields |
37
|
0
|
|
|
|
|
|
my %field = qw( |
38
|
|
|
|
|
|
|
session_key session_key |
39
|
|
|
|
|
|
|
expires session_expires |
40
|
|
|
|
|
|
|
uid session_uid |
41
|
|
|
|
|
|
|
secret secret |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
# Desktop apps need to call the https rather than http endpoint |
45
|
0
|
0
|
|
|
|
|
$self->_use_https_uri() if $self->base->desktop; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# Save format and parse settings, and get parsed response from server |
48
|
0
|
|
|
|
|
|
my ( $format, $parse ) = ( $self->base->format, $self->base->parse ); |
49
|
0
|
|
|
|
|
|
$self->base->format('JSON'); |
50
|
0
|
|
|
|
|
|
$self->base->parse(1); |
51
|
0
|
|
|
|
|
|
my $resp = $self->base->call( 'auth.getSession', auth_token => $token ); |
52
|
0
|
|
|
|
|
|
$self->base->format($format); |
53
|
0
|
|
|
|
|
|
$self->base->parse($parse); |
54
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
$self->_use_http_uri() if $self->base->desktop; |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
# Copy values from response to object's hash |
58
|
0
|
|
|
|
|
|
AUTH_RESPONSE: |
59
|
0
|
|
|
|
|
|
for my $key ( keys %{$resp} ) { |
60
|
0
|
0
|
0
|
|
|
|
next AUTH_RESPONSE if $key eq 'secret' && !$self->base->desktop; |
61
|
0
|
0
|
|
|
|
|
carp "Setting $field{$key}: $resp->{$key}" if $self->base->debug; |
62
|
0
|
|
|
|
|
|
$self->base->{ $field{$key} } = $resp->{$key}; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
return; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
sub login { |
69
|
0
|
|
|
0
|
1
|
|
my ( $self, %args ) = @_; |
70
|
|
|
|
|
|
|
|
71
|
0
|
0
|
|
|
|
|
croak q{Cannot use login method with web app} unless $self->base->desktop; |
72
|
|
|
|
|
|
|
|
73
|
0
|
|
|
|
|
|
my $token = $self->create_token; |
74
|
0
|
|
|
|
|
|
my $url = $self->base->get_login_url( auth_token => $token ); |
75
|
0
|
0
|
|
|
|
|
my $browser = |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
76
|
|
|
|
|
|
|
$args{'browser'} |
77
|
|
|
|
|
|
|
? $args{'browser'} |
78
|
|
|
|
|
|
|
: $^O =~ m/darwin/xms ? 'open' ## no critic |
79
|
|
|
|
|
|
|
: $^O =~ m/MSWin/xms ? 'start' ## no critic |
80
|
|
|
|
|
|
|
: q{}; |
81
|
|
|
|
|
|
|
|
82
|
0
|
0
|
|
|
|
|
croak "Don't know how to open browser for system '$^O'" if not $browser; |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
# Open browser have user login to Facebook app |
85
|
0
|
|
|
|
|
|
system qq($browser "$url"); |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
# Give the user time to log in |
88
|
0
|
|
0
|
|
|
|
$args{'sleep'} ||= $DEFAULT_SLEEP; |
89
|
0
|
|
|
|
|
|
sleep $args{'sleep'}; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
return $token; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub expire_session { |
95
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
96
|
0
|
|
|
|
|
|
return $self->base->call('auth.expireSession', |
97
|
|
|
|
|
|
|
session_key => $self->base->session_key, @_); |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub promote_session { |
101
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
102
|
0
|
|
|
|
|
|
return $self->base->call( 'auth.promoteSession', |
103
|
|
|
|
|
|
|
session_key => $self->base->session_key, @_ ); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
sub revoke_authorization { |
107
|
0
|
|
|
0
|
1
|
|
return shift->base->call( 'auth.revokeAuthorization', @_ ); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub revoke_extended_permission { |
111
|
0
|
|
|
0
|
1
|
|
return shift->base->call( 'auth.revokeExtendedPermission', @_ ); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub logout { |
115
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
116
|
0
|
|
|
|
|
|
$self->base->ua->post( 'http://www.facebook.com/logout.php', |
117
|
|
|
|
|
|
|
{ confirm => 1 } ); |
118
|
0
|
|
|
|
|
|
return; |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
0
|
|
|
0
|
|
|
sub _use_http_uri { return shift->_flip_scheme(0); } ## no critic |
122
|
0
|
|
|
0
|
|
|
sub _use_https_uri { return shift->_flip_scheme(1); } ## no critic |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub _flip_scheme { |
125
|
0
|
|
|
0
|
|
|
my $self = shift; |
126
|
0
|
|
|
|
|
|
my $make_https = shift; |
127
|
0
|
0
|
|
|
|
|
my $scheme = $make_https ? 'http' : 'https'; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
( my $uri = $self->base->server_uri() ) =~ s{^[^:]+:}{$scheme:}xms; |
130
|
0
|
|
|
|
|
|
$self->base->server_uri($uri); |
131
|
|
|
|
|
|
|
|
132
|
0
|
|
|
|
|
|
return; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
1; |
136
|
|
|
|
|
|
|
__END__ |