line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite2::ParamMethod::URIQueryParameter; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
10
|
use strict; |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
65
|
|
4
|
3
|
|
|
3
|
|
9
|
use warnings; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
62
|
|
5
|
|
|
|
|
|
|
|
6
|
3
|
|
|
3
|
|
8
|
use parent 'OAuth::Lite2::ParamMethod'; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
32
|
|
7
|
3
|
|
|
3
|
|
124
|
use HTTP::Request; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
40
|
|
8
|
3
|
|
|
3
|
|
7
|
use HTTP::Headers; |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
50
|
|
9
|
3
|
|
|
3
|
|
9
|
use bytes (); |
|
3
|
|
|
|
|
2
|
|
|
3
|
|
|
|
|
28
|
|
10
|
3
|
|
|
3
|
|
6
|
use Params::Validate; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
115
|
|
11
|
3
|
|
|
3
|
|
9
|
use OAuth::Lite2::Util qw(build_content); |
|
3
|
|
|
|
|
3
|
|
|
3
|
|
|
|
|
1135
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
OAuth::Lite2::ParamMethod::URIQueryParameter - builder/parser for OAuth 2.0 uri-query type of parameter |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 SYNOPSIS |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my $meth = OAuth::Lite2::ParamMethod::URIQueryParameter->new; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
# server side |
22
|
|
|
|
|
|
|
if ($meth->match( $plack_request )) { |
23
|
|
|
|
|
|
|
my ($token, $params) = $meth->parse( $plack_request ); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# client side |
27
|
|
|
|
|
|
|
my $http_req = $meth->request_builder(...); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head1 DESCRIPTION |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
builder/parser for OAuth 2.0 uri-query type of parameter |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 METHODS |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head2 new |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Constructor |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=head2 match( $plack_request ) |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
Returns true if passed L object is matched for the type of this method. |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
if ( $meth->match( $plack_request ) ) { |
44
|
|
|
|
|
|
|
... |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub match { |
50
|
12
|
|
|
12
|
1
|
16
|
my ($self, $req) = @_; |
51
|
|
|
|
|
|
|
return (exists $req->query_parameters->{oauth_token} |
52
|
12
|
|
66
|
|
|
30
|
|| exists $req->query_parameters->{access_token}); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head2 parse( $plack_request ) |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
Parse the L, and returns access token and oauth parameters. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
my ($token, $params) = $meth->parse( $plack_request ); |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub parse { |
64
|
12
|
|
|
12
|
1
|
567
|
my ($self, $req) = @_; |
65
|
12
|
|
|
|
|
22
|
my $params = $req->query_parameters; |
66
|
12
|
|
|
|
|
50
|
my $token = $params->{access_token}; |
67
|
12
|
|
|
|
|
26
|
$params->remove('access_token'); |
68
|
12
|
100
|
|
|
|
230
|
if($params->{oauth_token}){ |
69
|
6
|
|
|
|
|
7
|
$token = $params->{oauth_token}; |
70
|
6
|
|
|
|
|
11
|
$params->remove('oauth_token'); |
71
|
|
|
|
|
|
|
} |
72
|
12
|
|
|
|
|
116
|
return ($token, $params); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=head2 build_request( %params ) |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
Build L object. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
my $req = $meth->build_request( |
80
|
|
|
|
|
|
|
url => $url, |
81
|
|
|
|
|
|
|
method => $http_method, |
82
|
|
|
|
|
|
|
token => $access_token, |
83
|
|
|
|
|
|
|
oauth_params => $oauth_params, |
84
|
|
|
|
|
|
|
params => $params, |
85
|
|
|
|
|
|
|
content => $content, |
86
|
|
|
|
|
|
|
headers => $headers, |
87
|
|
|
|
|
|
|
); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=cut |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub build_request { |
92
|
7
|
|
|
7
|
1
|
9958
|
my $self = shift; |
93
|
7
|
|
|
|
|
172
|
my %args = Params::Validate::validate(@_, { |
94
|
|
|
|
|
|
|
url => 1, |
95
|
|
|
|
|
|
|
method => 1, |
96
|
|
|
|
|
|
|
token => 1, |
97
|
|
|
|
|
|
|
oauth_params => 1, |
98
|
|
|
|
|
|
|
params => { optional => 1 }, |
99
|
|
|
|
|
|
|
content => { optional => 1 }, |
100
|
|
|
|
|
|
|
headers => { optional => 1 }, |
101
|
|
|
|
|
|
|
}); |
102
|
|
|
|
|
|
|
|
103
|
7
|
|
50
|
|
|
47
|
my $oauth_params = $args{oauth_params} || {}; |
104
|
7
|
|
|
|
|
11
|
$oauth_params->{access_token} = $args{token}; |
105
|
|
|
|
|
|
|
|
106
|
7
|
|
100
|
|
|
19
|
my $params = $args{params} || {}; |
107
|
7
|
|
|
|
|
10
|
my $method = uc $args{method}; |
108
|
7
|
|
|
|
|
8
|
my $headers = $args{headers}; |
109
|
7
|
100
|
|
|
|
13
|
if (defined $headers) { |
110
|
1
|
50
|
|
|
|
4
|
if (ref($headers) eq 'ARRAY') { |
111
|
1
|
|
|
|
|
4
|
$headers = HTTP::Headers->new(@$headers); |
112
|
|
|
|
|
|
|
} else { |
113
|
0
|
|
|
|
|
0
|
$headers = $headers->clone; |
114
|
|
|
|
|
|
|
} |
115
|
|
|
|
|
|
|
} else { |
116
|
6
|
|
|
|
|
22
|
$headers = HTTP::Headers->new; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
7
|
100
|
66
|
|
|
79
|
if ($method eq 'GET' || $method eq 'DELETE') { |
120
|
4
|
|
|
|
|
18
|
my $query = build_content({%$params, %$oauth_params}); |
121
|
4
|
|
|
|
|
14
|
my $url = sprintf q{%s?%s}, $args{url}, $query; |
122
|
4
|
|
|
|
|
13
|
my $req = HTTP::Request->new($method, $url, $headers); |
123
|
4
|
|
|
|
|
432
|
return $req; |
124
|
|
|
|
|
|
|
} else { |
125
|
3
|
|
|
|
|
9
|
my $query = build_content($oauth_params); |
126
|
3
|
|
|
|
|
8
|
my $url = sprintf q{%s?%s}, $args{url}, $query; |
127
|
3
|
100
|
|
|
|
9
|
unless ($headers->header("Content-Type")) { |
128
|
2
|
|
|
|
|
45
|
$headers->header("Content-Type", |
129
|
|
|
|
|
|
|
"application/x-www-form-urlencoded"); |
130
|
|
|
|
|
|
|
} |
131
|
3
|
|
|
|
|
66
|
my $content_type = $headers->header("Content-Type"); |
132
|
|
|
|
|
|
|
my $content = ($content_type eq "application/x-www-form-urlencoded") |
133
|
|
|
|
|
|
|
? build_content($params) |
134
|
3
|
100
|
33
|
|
|
53
|
: $args{content} || build_content($params); |
135
|
3
|
|
|
|
|
7
|
$headers->header("Content-Length", bytes::length($content)); |
136
|
3
|
|
|
|
|
81
|
my $req = HTTP::Request->new($method, $url, $headers, $content); |
137
|
3
|
|
|
|
|
298
|
return $req; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head2 is_legacy( $plack_request ) |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns true if passed L object is based draft version 10. |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
if ( $meth->is_legacy( $plack_request ) ) { |
146
|
|
|
|
|
|
|
... |
147
|
|
|
|
|
|
|
} |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
sub is_legacy { |
152
|
12
|
|
|
12
|
1
|
809
|
my ($self, $req) = @_; |
153
|
12
|
|
|
|
|
24
|
return (exists $req->query_parameters->{oauth_token}); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head1 SEE ALSO |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
L |
159
|
|
|
|
|
|
|
L |
160
|
|
|
|
|
|
|
L |
161
|
|
|
|
|
|
|
L |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head1 AUTHOR |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Lyo Kato, Elyo.kato@gmail.comE |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Copyright (C) 2010 by Lyo Kato |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
172
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
173
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=cut |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
1; |