line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite::Token; |
2
|
|
|
|
|
|
|
|
3
|
6
|
|
|
6
|
|
2096
|
use strict; |
|
6
|
|
|
|
|
14
|
|
|
6
|
|
|
|
|
205
|
|
4
|
6
|
|
|
6
|
|
30
|
use warnings; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
204
|
|
5
|
|
|
|
|
|
|
|
6
|
6
|
|
|
6
|
|
32
|
use base 'Class::Accessor::Fast'; |
|
6
|
|
|
|
|
12
|
|
|
6
|
|
|
|
|
1704
|
|
7
|
|
|
|
|
|
|
|
8
|
6
|
|
|
|
|
2951
|
use OAuth::Lite::Util qw( |
9
|
|
|
|
|
|
|
encode_param |
10
|
|
|
|
|
|
|
decode_param |
11
|
|
|
|
|
|
|
gen_random_key |
12
|
6
|
|
|
6
|
|
8729
|
); |
|
6
|
|
|
|
|
106
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/token secret callback_confirmed/); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 NAME |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
OAuth::Lite::Token - token class |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $token = OAuth::Lite::Token->new( |
23
|
|
|
|
|
|
|
token => 'foo', |
24
|
|
|
|
|
|
|
secret => 'bar', |
25
|
|
|
|
|
|
|
); |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# or |
28
|
|
|
|
|
|
|
my $token = OAuth::Lite::Token->new; |
29
|
|
|
|
|
|
|
$tokne->token('foo'); |
30
|
|
|
|
|
|
|
$secret->secret('bar'); |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# and you also can make token which two params are filled in with random values. |
33
|
|
|
|
|
|
|
my $token = OAuth::Lite::Token->new_random; |
34
|
|
|
|
|
|
|
say $token->token; |
35
|
|
|
|
|
|
|
say $token->secret; |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
my $encoded = $token->as_encoded; |
38
|
|
|
|
|
|
|
say $encoded; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
my $new_token = OAuth::Lite::Token->from_encoded($encoded); |
41
|
|
|
|
|
|
|
say $new_token->token; |
42
|
|
|
|
|
|
|
say $new_token->secret; |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 DESCRIPTION |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Token class. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 METHODS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=head2 new |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head3 parameters |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=over 4 |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=item token |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item secret |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=back |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=cut |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub new { |
65
|
16
|
|
|
16
|
1
|
1393
|
my ($class, %args) = @_; |
66
|
16
|
|
|
|
|
87
|
bless { |
67
|
|
|
|
|
|
|
token => undef, |
68
|
|
|
|
|
|
|
secret => undef, |
69
|
|
|
|
|
|
|
callback_confirmed => 0, |
70
|
|
|
|
|
|
|
%args |
71
|
|
|
|
|
|
|
}, $class; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head2 new_random |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
Generate new object. and automatically filled token and secret value with random key. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $t = OAuth::Lite::Token->new_random; |
79
|
|
|
|
|
|
|
say $t->token; |
80
|
|
|
|
|
|
|
say $t->secret; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=cut |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub new_random { |
85
|
1
|
|
|
1
|
1
|
91
|
my $class = shift; |
86
|
1
|
|
|
|
|
6
|
my $token = $class->new;; |
87
|
1
|
|
|
|
|
5
|
$token->token(gen_random_key()); |
88
|
1
|
|
|
|
|
23
|
$token->secret(gen_random_key()); |
89
|
1
|
|
|
|
|
9
|
$token; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 token($token_value) |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
Getter/Setter for token value. |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
$token->token('foo'); |
97
|
|
|
|
|
|
|
say $token->token; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 secret($token_secret) |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Getter/Setter for secret value. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
$token->secret('bar'); |
104
|
|
|
|
|
|
|
say $token->secret; |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 from_encoded($encoded) |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
Generate token from encoded line (that service provider provides as response of request token.). |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $line = "oauth_token=foo&oauth_token_secret=bar"; |
111
|
|
|
|
|
|
|
my $token = OAuth::Lite::Token->from_encoded($encoded); |
112
|
|
|
|
|
|
|
say $token->token; |
113
|
|
|
|
|
|
|
say $token->secret; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
=cut |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub from_encoded { |
118
|
5
|
|
|
5
|
1
|
1634
|
my ($class, $encoded) = @_; |
119
|
|
|
|
|
|
|
|
120
|
5
|
|
|
|
|
17
|
$encoded =~ s/\r\n$//; |
121
|
5
|
|
|
|
|
13
|
$encoded =~ s/\n$//; |
122
|
|
|
|
|
|
|
|
123
|
5
|
|
|
|
|
12
|
my $token = $class->new; |
124
|
5
|
|
|
|
|
18
|
for my $pair (split /&/, $encoded) { |
125
|
12
|
|
|
|
|
253
|
my ($key, $val) = split /=/, $pair; |
126
|
12
|
100
|
|
|
|
35
|
if ($key eq 'oauth_token') { |
|
|
100
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
127
|
5
|
|
|
|
|
16
|
$token->token(decode_param($val)); |
128
|
|
|
|
|
|
|
} elsif ($key eq 'oauth_token_secret') { |
129
|
5
|
|
|
|
|
14
|
$token->secret(decode_param($val)); |
130
|
|
|
|
|
|
|
} elsif ($key eq 'oauth_callback_confirmed') { |
131
|
2
|
|
|
|
|
5
|
my $p = decode_param($val); |
132
|
2
|
100
|
66
|
|
|
22
|
if ($p && $p eq 'true') { |
133
|
1
|
|
|
|
|
19
|
$token->callback_confirmed(1); |
134
|
|
|
|
|
|
|
} |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
5
|
|
|
|
|
142
|
return $token; |
138
|
|
|
|
|
|
|
} |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=head2 as_encoded |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
Returns encoded line from token object. |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
my $token = OAuth::Lite::Token->new( |
145
|
|
|
|
|
|
|
token => 'foo', |
146
|
|
|
|
|
|
|
secret => 'bar', |
147
|
|
|
|
|
|
|
); |
148
|
|
|
|
|
|
|
say $token->as_encoded; #oauth_token=foo&oauth_token_secret=bar |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=cut |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
sub as_encoded { |
153
|
2
|
|
|
2
|
1
|
980
|
my $self = shift; |
154
|
2
|
|
50
|
|
|
52
|
my $token = $self->token || ''; |
155
|
2
|
|
50
|
|
|
46
|
my $secret = $self->secret || ''; |
156
|
2
|
|
|
|
|
17
|
my $encoded = sprintf(q{oauth_token=%s&oauth_token_secret=%s}, |
157
|
|
|
|
|
|
|
encode_param($token), |
158
|
|
|
|
|
|
|
encode_param($secret)); |
159
|
|
|
|
|
|
|
|
160
|
2
|
100
|
|
|
|
94
|
$encoded .= q{&oauth_callback_confirmed=true} if $self->callback_confirmed; |
161
|
2
|
|
|
|
|
20
|
return $encoded; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 AUTHOR |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Lyo Kato, C |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
171
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
172
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=cut |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
1; |