line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
1
|
|
|
1
|
|
670
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
35
|
|
2
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
45
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
## no critic (ProhibitMultiplePackages, RequireFilenameMatchesPackage) |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
OAuthomatic::Types - few helper types to make code more readable and less error-prone |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 DESCRIPTION |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
Types below are defined to make code a bit more readable and less error prone. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 OAuthomatic::Types::StructCleaner |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
Role composed into types defined below. Handles some construction |
19
|
|
|
|
|
|
|
conventions. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=over 4 |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=item * |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Any empty or undef'ed values are dropped as if they were not specified at all. |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=item * |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
If args C<data> and C<remap> are given, constructor can translate |
30
|
|
|
|
|
|
|
field names, for example: |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
Something->new(data=>{aaa=>'x', bbb=>'y'}, |
33
|
|
|
|
|
|
|
remap=>{aaa=>'token', 'bbb'=>'secret'); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
is equivalent to: |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
Something->new(token=>'x', secret=>'y'); |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=back |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
{ |
44
|
|
|
|
|
|
|
package OAuthomatic::Types::StructCleaner; |
45
|
1
|
|
|
1
|
|
167
|
use Moose::Role; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
use Carp; |
47
|
|
|
|
|
|
|
use namespace::sweep; |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
around BUILDARGS => sub { |
50
|
|
|
|
|
|
|
my $orig = shift; |
51
|
|
|
|
|
|
|
my $class = shift; |
52
|
|
|
|
|
|
|
my $ret = $class->$orig(@_); |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
# Drop empty values (FIXME: this is close to MooseX::UndefTolerant) |
55
|
|
|
|
|
|
|
foreach my $key (keys %$ret) { |
56
|
|
|
|
|
|
|
my $val = $ret->{$key}; |
57
|
|
|
|
|
|
|
unless(defined($val) && $val =~ /./x) { |
58
|
|
|
|
|
|
|
delete $ret->{$key}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Remap names |
63
|
|
|
|
|
|
|
if(exists $ret->{remap}) { |
64
|
|
|
|
|
|
|
my $remap = $ret->{remap}; |
65
|
|
|
|
|
|
|
my $data = $ret->{data} or |
66
|
|
|
|
|
|
|
OAuthomatic::Error::Generic->throw( |
67
|
|
|
|
|
|
|
ident => "Bad call", |
68
|
|
|
|
|
|
|
extra => "No data given in spite remap is specified"); |
69
|
|
|
|
|
|
|
delete $ret->{remap}; |
70
|
|
|
|
|
|
|
delete $ret->{data}; |
71
|
|
|
|
|
|
|
foreach my $mapped (keys %$remap) { |
72
|
|
|
|
|
|
|
my $mapped_to = $remap->{$mapped}; |
73
|
|
|
|
|
|
|
my $value = $data->{$mapped} |
74
|
|
|
|
|
|
|
or OAuthomatic::Error::Generic->throw( |
75
|
|
|
|
|
|
|
ident => "Missing parameter", |
76
|
|
|
|
|
|
|
extra => "Missing $mapped (while constructing $class). Known keys: ") . join(", ", keys %$data) . "\n"; |
77
|
|
|
|
|
|
|
# delete $data->{$mapped}; # if checking for superfluous |
78
|
|
|
|
|
|
|
$ret->{$mapped_to} = $value; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
} |
81
|
|
|
|
|
|
|
return $ret; |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
}; |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
=head1 OAuthomatic::Types::ClientCred |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
Client (application) credentials. Fixed key and secret allocated manually |
88
|
|
|
|
|
|
|
using server web interface (usually after filling some form with various |
89
|
|
|
|
|
|
|
details) which identify the application. |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
=item key |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Client key - the application identifier. |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=item secret |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Client secret - confidential value used to sign requests, to prove key |
102
|
|
|
|
|
|
|
is valid. |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=back |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
{ |
109
|
|
|
|
|
|
|
package OAuthomatic::Types::ClientCred; |
110
|
|
|
|
|
|
|
use Moose; |
111
|
|
|
|
|
|
|
with 'OAuthomatic::Types::StructCleaner'; |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
has 'key' => (is => 'ro', isa => 'Str', required => 1); |
114
|
|
|
|
|
|
|
has 'secret' => (is => 'ro', isa => 'Str', required => 1); |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub as_hash { |
117
|
|
|
|
|
|
|
my ($self, $prefix) = @_; |
118
|
|
|
|
|
|
|
return ( |
119
|
|
|
|
|
|
|
$prefix . '_key' => $self->key, |
120
|
|
|
|
|
|
|
$prefix . '_secret' => $self->secret, |
121
|
|
|
|
|
|
|
); |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
sub equal { |
125
|
|
|
|
|
|
|
my ($class, $left, $right) = @_; |
126
|
|
|
|
|
|
|
if(defined($left)) { |
127
|
|
|
|
|
|
|
if(defined($right)) { |
128
|
|
|
|
|
|
|
return ($left->key eq $right->key) |
129
|
|
|
|
|
|
|
&& ($left->secret eq $right->secret); |
130
|
|
|
|
|
|
|
} else { |
131
|
|
|
|
|
|
|
return 0; |
132
|
|
|
|
|
|
|
} |
133
|
|
|
|
|
|
|
} else { |
134
|
|
|
|
|
|
|
return ! defined($right); |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
}; |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
# Common implementation for two classes below |
140
|
|
|
|
|
|
|
{ |
141
|
|
|
|
|
|
|
package OAuthomatic::Types::GenericTokenCred; |
142
|
|
|
|
|
|
|
use Moose; |
143
|
|
|
|
|
|
|
with 'OAuthomatic::Types::StructCleaner'; |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
has 'token' => (is => 'ro', isa => 'Str', required => 1); |
146
|
|
|
|
|
|
|
has 'secret' => (is => 'ro', isa => 'Str', required => 1); |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
sub as_hash { |
149
|
|
|
|
|
|
|
my $self = shift; |
150
|
|
|
|
|
|
|
return ( |
151
|
|
|
|
|
|
|
token => $self->token, |
152
|
|
|
|
|
|
|
token_secret => $self->secret, |
153
|
|
|
|
|
|
|
); |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub equal { |
157
|
|
|
|
|
|
|
my ($class, $left, $right) = @_; |
158
|
|
|
|
|
|
|
if(defined($left)) { |
159
|
|
|
|
|
|
|
if(defined($right)) { |
160
|
|
|
|
|
|
|
return ($left->token eq $right->token) |
161
|
|
|
|
|
|
|
&& ($left->secret eq $right->secret); |
162
|
|
|
|
|
|
|
} else { |
163
|
|
|
|
|
|
|
return 0; |
164
|
|
|
|
|
|
|
} |
165
|
|
|
|
|
|
|
} else { |
166
|
|
|
|
|
|
|
return ! defined($right); |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
} |
169
|
|
|
|
|
|
|
}; |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head1 OAuthomatic::Types::TemporaryCred |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
Temporary (request) credentials. Used during process of allocating |
174
|
|
|
|
|
|
|
token credentials. |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=head2 ATTRIBUTES |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=over 4 |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=item token |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
Actual token - identifier quoted in requests. |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item secret |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
Associated secret - confidential value used to sign requests, to prove they |
187
|
|
|
|
|
|
|
are valid. |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=item authorize_page |
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
Full URL of the page end user should use to spend this temporary credential |
192
|
|
|
|
|
|
|
and generate access token. Already contains the token. |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
=back |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=cut |
197
|
|
|
|
|
|
|
{ |
198
|
|
|
|
|
|
|
package OAuthomatic::Types::TemporaryCred; |
199
|
|
|
|
|
|
|
use Moose; |
200
|
|
|
|
|
|
|
extends 'OAuthomatic::Types::GenericTokenCred'; |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
# This is rw and not required as we append it after initial object creation |
203
|
|
|
|
|
|
|
has 'authorize_page' => (is => 'rw', isa => 'URI', required => 0); |
204
|
|
|
|
|
|
|
}; |
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=head1 OAuthomatic::Types::TokenCred |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
Token (access) credentials. Those are used to sign actual API calls. |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=cut |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
{ |
214
|
|
|
|
|
|
|
package OAuthomatic::Types::TokenCred; |
215
|
|
|
|
|
|
|
use Moose; |
216
|
|
|
|
|
|
|
extends 'OAuthomatic::Types::GenericTokenCred'; |
217
|
|
|
|
|
|
|
}; |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=head1 OAuthomatic::Types::Verifier |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
Verifier info, returned from authorization. |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=cut |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
{ |
226
|
|
|
|
|
|
|
package OAuthomatic::Types::Verifier; |
227
|
|
|
|
|
|
|
use Moose; |
228
|
|
|
|
|
|
|
with 'OAuthomatic::Types::StructCleaner'; |
229
|
|
|
|
|
|
|
|
230
|
|
|
|
|
|
|
has 'token' => (is => 'ro', isa => 'Str', required => 1); |
231
|
|
|
|
|
|
|
has 'verifier' => (is => 'ro', isa => 'Str', required => 1); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
sub equal { |
234
|
|
|
|
|
|
|
my ($class, $left, $right) = @_; |
235
|
|
|
|
|
|
|
if(defined($left)) { |
236
|
|
|
|
|
|
|
if(defined($right)) { |
237
|
|
|
|
|
|
|
return ($left->token eq $right->token) |
238
|
|
|
|
|
|
|
&& ($left->verifier eq $right->verifier); |
239
|
|
|
|
|
|
|
} else { |
240
|
|
|
|
|
|
|
return 0; |
241
|
|
|
|
|
|
|
} |
242
|
|
|
|
|
|
|
} else { |
243
|
|
|
|
|
|
|
return ! defined($right); |
244
|
|
|
|
|
|
|
} |
245
|
|
|
|
|
|
|
} |
246
|
|
|
|
|
|
|
}; |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
1; |