line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package OAuth::Lite2::Client::TokenResponseParser; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
3
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
20
|
|
4
|
1
|
|
|
1
|
|
3
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
18
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
3
|
use Try::Tiny qw/try catch/; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
37
|
|
7
|
1
|
|
|
1
|
|
39
|
use OAuth::Lite2::Formatters; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
use OAuth::Lite2::Client::Error; |
9
|
|
|
|
|
|
|
use OAuth::Lite2::Client::Token; |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
sub new { |
12
|
|
|
|
|
|
|
bless {}, $_[0]; |
13
|
|
|
|
|
|
|
} |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
sub parse { |
16
|
|
|
|
|
|
|
my ($self, $http_res) = @_; |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
my $formatter = |
19
|
|
|
|
|
|
|
OAuth::Lite2::Formatters->get_formatter_by_type( |
20
|
|
|
|
|
|
|
$http_res->content_type); |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $token; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
if ($http_res->is_success) { |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
OAuth::Lite2::Client::Error::InvalidResponse->throw( |
27
|
|
|
|
|
|
|
message => sprintf(q{Invalid response content-type: %s}, |
28
|
|
|
|
|
|
|
$http_res->content_type||'') |
29
|
|
|
|
|
|
|
) unless $formatter; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
my $result = try { |
32
|
|
|
|
|
|
|
return $formatter->parse($http_res->content); |
33
|
|
|
|
|
|
|
} catch { |
34
|
|
|
|
|
|
|
OAuth::Lite2::Client::Error::InvalidResponse->throw( |
35
|
|
|
|
|
|
|
message => sprintf(q{Invalid response format: %s}, $_), |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
}; |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
OAuth::Lite2::Client::Error::InvalidResponse->throw( |
40
|
|
|
|
|
|
|
message => sprintf("Response doesn't include 'access_token'") |
41
|
|
|
|
|
|
|
) unless exists $result->{access_token}; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$token = OAuth::Lite2::Client::Token->new($result); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
} else { |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
my $errmsg = $http_res->content || $http_res->status_line; |
48
|
|
|
|
|
|
|
if ($formatter && $http_res->content) { |
49
|
|
|
|
|
|
|
try { |
50
|
|
|
|
|
|
|
my $result = $formatter->parse($http_res->content); |
51
|
|
|
|
|
|
|
$errmsg = $result->{error} |
52
|
|
|
|
|
|
|
if exists $result->{error}; |
53
|
|
|
|
|
|
|
} catch { return }; |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
OAuth::Lite2::Client::Error::InvalidResponse->throw( message => $errmsg ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
return $token; |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
1; |