line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
785
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
32
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
21
|
|
3
|
1
|
|
|
1
|
|
4
|
use utf8; |
|
1
|
|
|
|
|
0
|
|
|
1
|
|
|
|
|
5
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Amon2::Auth::Site::Twitter; |
6
|
1
|
|
|
1
|
|
22
|
use Mouse; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
6
|
|
7
|
1
|
|
|
1
|
|
752
|
use Net::Twitter::Lite::WithAPIv1_1; |
|
1
|
|
|
|
|
17234
|
|
|
1
|
|
|
|
|
348
|
|
8
|
|
|
|
|
|
|
|
9
|
0
|
|
|
0
|
0
|
|
sub moniker { 'twitter' } |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
has consumer_key => ( |
12
|
|
|
|
|
|
|
is => 'ro', |
13
|
|
|
|
|
|
|
isa => 'Str', |
14
|
|
|
|
|
|
|
required => 1, |
15
|
|
|
|
|
|
|
); |
16
|
|
|
|
|
|
|
has consumer_secret => ( |
17
|
|
|
|
|
|
|
is => 'ro', |
18
|
|
|
|
|
|
|
isa => 'Str', |
19
|
|
|
|
|
|
|
required => 1, |
20
|
|
|
|
|
|
|
); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
sub _nt { |
23
|
0
|
|
|
0
|
|
|
my ($self) = @_; |
24
|
0
|
|
|
|
|
|
my $nt = Net::Twitter::Lite::WithAPIv1_1->new( |
25
|
|
|
|
|
|
|
consumer_key => $self->consumer_key, |
26
|
|
|
|
|
|
|
consumer_secret => $self->consumer_secret, |
27
|
|
|
|
|
|
|
ssl => 1, |
28
|
|
|
|
|
|
|
); |
29
|
0
|
|
|
|
|
|
return $nt; |
30
|
|
|
|
|
|
|
} |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub auth_uri { |
33
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $callback_uri) = @_; |
34
|
|
|
|
|
|
|
|
35
|
0
|
|
|
|
|
|
my $nt = $self->_nt(); |
36
|
0
|
|
|
|
|
|
my $redirect_uri = $nt->get_authorization_url(callback => $callback_uri); |
37
|
0
|
|
|
|
|
|
$c->session->set( auth_twitter => [ $nt->request_token, $nt->request_token_secret, ] ); |
38
|
0
|
|
|
|
|
|
return $redirect_uri; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
sub callback { |
42
|
0
|
|
|
0
|
0
|
|
my ($self, $c, $callback) = @_; |
43
|
|
|
|
|
|
|
|
44
|
0
|
0
|
|
|
|
|
my $cookie = $c->session->get('auth_twitter') |
45
|
|
|
|
|
|
|
or return $callback->{on_error}->("Session error"); |
46
|
|
|
|
|
|
|
|
47
|
0
|
|
|
|
|
|
my $nt = $self->_nt(); |
48
|
0
|
|
|
|
|
|
$nt->request_token($cookie->[0]); |
49
|
0
|
|
|
|
|
|
$nt->request_token_secret($cookie->[1]); |
50
|
0
|
0
|
|
|
|
|
if (my $denied = $c->req->param('denied')) { |
51
|
0
|
|
|
|
|
|
return $callback->{on_error}->("Access denied"); |
52
|
|
|
|
|
|
|
} |
53
|
0
|
|
|
|
|
|
my $verifier = $c->req->param('oauth_verifier'); |
54
|
0
|
|
|
|
|
|
my ($access_token, $access_token_secret, $user_id, $screen_name) = eval { |
55
|
0
|
|
|
|
|
|
$nt->request_access_token(verifier => $verifier); |
56
|
|
|
|
|
|
|
}; |
57
|
0
|
0
|
|
|
|
|
if ($@) { |
58
|
|
|
|
|
|
|
# Net::Twitter::Lite throws exception like following |
59
|
|
|
|
|
|
|
# GET https://twitter.com/oauth/access_token failed: 401 Unauthorized at /Users/tokuhirom/perl5/perlbrew/perls/perl-5.15.2/lib/site_perl/5.15.2/Net/Twitter/Lite.pm line 237. |
60
|
0
|
|
|
|
|
|
return $callback->{on_error}->($@); |
61
|
|
|
|
|
|
|
} else { |
62
|
0
|
|
|
|
|
|
return $callback->{on_finished}->($access_token, $access_token_secret, $user_id, $screen_name); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
67
|
|
|
|
|
|
|
__END__ |