| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package NephiaX::Auth::Twitter; |
|
2
|
1
|
|
|
1
|
|
19853
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
36
|
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
4
|
1
|
|
|
1
|
|
746
|
use Nephia; |
|
|
1
|
|
|
|
|
466460
|
|
|
|
1
|
|
|
|
|
6
|
|
|
5
|
1
|
|
|
1
|
|
6690
|
use Net::Twitter::Lite::WithAPIv1_1; |
|
|
1
|
|
|
|
|
31710
|
|
|
|
1
|
|
|
|
|
34
|
|
|
6
|
1
|
|
|
1
|
|
11
|
use URI; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
20
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Carp; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
352
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = 0.01; |
|
10
|
|
|
|
|
|
|
my $TWITTER; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
app { |
|
13
|
|
|
|
|
|
|
my $c = shift; |
|
14
|
|
|
|
|
|
|
$TWITTER ||= Net::Twitter::Lite::WithAPIv1_1->new(%{$c->{config}}); |
|
15
|
|
|
|
|
|
|
return [303, ['Location' => $TWITTER->get_authentication_url(callback => req->uri->as_string)], []] unless param('oauth_token'); |
|
16
|
|
|
|
|
|
|
my $twitter_id = _verify_token(param('oauth_token'), param('oauth_verifier')) or return [403,[],[$!]]; |
|
17
|
|
|
|
|
|
|
$c->{config}{handler}->($c, $twitter_id); |
|
18
|
|
|
|
|
|
|
}; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub _verify_token { |
|
21
|
0
|
|
|
0
|
|
|
my ($token, $verifier) = @_; |
|
22
|
0
|
|
|
|
|
|
my $twitter_id = eval { $TWITTER->request_access_token( |
|
|
0
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
token => $token, |
|
24
|
|
|
|
|
|
|
token_secret => $TWITTER->{consumer_secret}, |
|
25
|
|
|
|
|
|
|
verifier => $verifier |
|
26
|
|
|
|
|
|
|
) }; |
|
27
|
0
|
0
|
|
|
|
|
if ($@) { |
|
28
|
0
|
|
|
|
|
|
croak "verify failure: $@"; |
|
29
|
0
|
|
|
|
|
|
return; |
|
30
|
|
|
|
|
|
|
} |
|
31
|
0
|
|
|
|
|
|
return $twitter_id; |
|
32
|
|
|
|
|
|
|
} |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
1; |
|
35
|
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=encoding utf-8 |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
=head1 NAME |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
NephiaX::Auth::Twitter - Twitter Authorizer |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
An web application that powered by Nephia. |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
use Plack::Builder; |
|
49
|
|
|
|
|
|
|
use NephiaX::Auth::Twitter; |
|
50
|
|
|
|
|
|
|
builder { |
|
51
|
|
|
|
|
|
|
mount '/auth' => NephiaX::Auth::Twitter->run( |
|
52
|
|
|
|
|
|
|
consumer_key => 'your consumer key', |
|
53
|
|
|
|
|
|
|
consumer_secret => 'your consumer secret', |
|
54
|
|
|
|
|
|
|
handler => sub { |
|
55
|
|
|
|
|
|
|
my ($c, $twitter_id) = @_; |
|
56
|
|
|
|
|
|
|
### You have to imprement logic that stores twitter_id into your db and/or cookie. |
|
57
|
|
|
|
|
|
|
[302, [Location => '/userarea/somepage'], []]; |
|
58
|
|
|
|
|
|
|
}, |
|
59
|
|
|
|
|
|
|
); |
|
60
|
|
|
|
|
|
|
mount '/' => Your::App->run; |
|
61
|
|
|
|
|
|
|
}; |
|
62
|
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
=head1 AUTHOR |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
ytnobody Eytnobody@gmail.comE |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
=head1 LICENSE |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
70
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 SEE ALSO |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
L |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=cut |
|
77
|
|
|
|
|
|
|
|