line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Plack::Middleware::OAuth::Handler::AccessTokenV1; |
2
|
2
|
|
|
2
|
|
11
|
use parent qw(Plack::Middleware::OAuth::Handler); |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
12
|
|
3
|
2
|
|
|
2
|
|
121
|
use warnings; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
50
|
|
4
|
2
|
|
|
2
|
|
10
|
use strict; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
56
|
|
5
|
2
|
|
|
2
|
|
17
|
use URI; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
106
|
|
6
|
2
|
|
|
2
|
|
11
|
use URI::Query; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
40
|
|
7
|
2
|
|
|
2
|
|
10
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
271
|
|
8
|
2
|
|
|
2
|
|
10
|
use Net::OAuth; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
48
|
|
9
|
2
|
|
|
2
|
|
14
|
use DateTime; |
|
2
|
|
|
|
|
11
|
|
|
2
|
|
|
|
|
55
|
|
10
|
2
|
|
|
2
|
|
11
|
use Digest::MD5 qw(md5_hex); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
150
|
|
11
|
2
|
|
|
2
|
|
11
|
use HTTP::Request::Common; |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
131
|
|
12
|
2
|
|
|
2
|
|
942
|
use Plack::Middleware::OAuth::AccessToken; |
|
2
|
|
|
|
|
7
|
|
|
2
|
|
|
|
|
1292
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub build_args { |
16
|
0
|
|
|
0
|
0
|
|
my $self = $_[0]; |
17
|
0
|
|
|
|
|
|
my $config = $self->config; |
18
|
|
|
|
|
|
|
# $config contains: consumer_key consumer_secret request_token_url access_token_url request_method signature_method |
19
|
0
|
|
|
|
|
|
my %args = ( |
20
|
|
|
|
|
|
|
$self->build_v1_common_args, |
21
|
|
|
|
|
|
|
token => $self->param('oauth_token'), |
22
|
|
|
|
|
|
|
token_secret => '', |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
request_url => $config->{access_token_url}, |
25
|
|
|
|
|
|
|
request_method => $config->{access_token_method}, |
26
|
|
|
|
|
|
|
verifier => $self->param('oauth_verifier'), |
27
|
|
|
|
|
|
|
); |
28
|
0
|
|
|
|
|
|
return %args; |
29
|
|
|
|
|
|
|
} |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
sub run { |
32
|
0
|
|
|
0
|
1
|
|
my $self = $_[0]; |
33
|
0
|
|
|
|
|
|
my $provider = $self->provider; |
34
|
0
|
|
|
|
|
|
my $config = $self->config; |
35
|
0
|
|
|
|
|
|
my $env = $self->env; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
# http://app.local:3000/oauth/twitter/callback? |
38
|
|
|
|
|
|
|
# oauth_token= |
39
|
|
|
|
|
|
|
# oauth_verifier= |
40
|
|
|
|
|
|
|
# my $response = Net::OAuth->response( 'user auth' )->from_hash( request->params ); |
41
|
|
|
|
|
|
|
# my $response = Net::OAuth->response( 'user auth' )->from_hash( { |
42
|
|
|
|
|
|
|
# oauth_token => $self->param('oauth_token'), |
43
|
|
|
|
|
|
|
# oauth_verifier => $self->param('oauth_verifier'), |
44
|
|
|
|
|
|
|
# }); |
45
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
my $request = Net::OAuth->request( 'access token' )->new( $self->build_args ); |
47
|
0
|
|
|
|
|
|
$request->sign; |
48
|
|
|
|
|
|
|
|
49
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
50
|
0
|
|
|
|
|
|
my $ua_response = $ua->request( GET $request->to_url ); |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
unless($ua_response->is_success) { |
53
|
0
|
0
|
|
|
|
|
return $self->on_error->( $self, $env, $provider, $config ) if $self->on_error; |
54
|
0
|
|
|
|
|
|
return $self->render( $ua_response->status_line . ' ' . $ua_response->content ); |
55
|
|
|
|
|
|
|
} |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
|
58
|
0
|
|
|
|
|
|
my $response = Net::OAuth->response( 'access token' )->from_post_body( $ua_response->content ); |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
|
my $token = Plack::Middleware::OAuth::AccessToken->new( |
61
|
|
|
|
|
|
|
version => $config->{version}, |
62
|
|
|
|
|
|
|
provider => $provider, |
63
|
|
|
|
|
|
|
params => { |
64
|
|
|
|
|
|
|
access_token => $response->token, |
65
|
|
|
|
|
|
|
access_token_secret => $response->token_secret, |
66
|
|
|
|
|
|
|
extra => $response->extra_params |
67
|
|
|
|
|
|
|
}, |
68
|
|
|
|
|
|
|
); |
69
|
0
|
|
|
|
|
|
$token->register_session( $env ); |
70
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
my $res; |
72
|
0
|
0
|
|
|
|
|
$res = $self->on_success->( $self, $token ) if $self->on_success; |
73
|
0
|
0
|
|
|
|
|
return $res if $res; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
return $self->to_yaml( $token ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
1; |