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