« blib/lib/OAuth/Lite2/Server/GrantHandler/ClientCredentials.pm
↑ Summary
blib/lib/OAuth/Lite2/Util.pm »
| 1 | package OAuth::Lite2::Client::TokenResponseParser; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Try::Tiny qw/try catch/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use OAuth::Lite2::Formatters; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use OAuth::Lite2::Client::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use OAuth::Lite2::Client::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | sub new { | ||||||||||||||||||||||||||||
| 12 | 10 | ▶ | bless {}, $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | } | ||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||
| 15 | sub parse { | ||||||||||||||||||||||||||||
| 16 | 53 | ▶ | my ($self, $http_res) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=8 SCAR=23.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 53 | my $formatter = | |||||||||||||||||||||||||||
| 19 | OAuth::Lite2::Formatters->get_formatter_by_type( | ||||||||||||||||||||||||||||
| 20 | $http_res->content_type); | ||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 53 | my $token; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 53 | ▶ | if ($http_res->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | 20 | ▶ | OAuth::Lite2::Client::Error::InvalidResponse->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
$http_res->content_type || ''
MC/DC0%0/1
$http_res->content_type || ''
$http_res->content_type
Truth table0%0/2
A
A= $http_res->content_type
| |||||||||||||||||||||||||||||
| 27 | message => sprintf(q{Invalid response content-type: %s}, | ||||||||||||||||||||||||||||
| 28 | $http_res->content_type||'') | ||||||||||||||||||||||||||||
| 29 | ) unless $formatter; | ||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | my $result = try { | ||||||||||||||||||||||||||||
| 32 | 20 | ▶ | return $formatter->parse($http_res->content); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 33 | } catch { | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | OAuth::Lite2::Client::Error::InvalidResponse->throw( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 35 | message => sprintf(q{Invalid response format: %s}, $_), | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | 20 | }; | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | OAuth::Lite2::Client::Error::InvalidResponse->throw( | ||||||||||||||||||||||||||||
| 40 | message => sprintf("Response doesn't include 'access_token'") | ||||||||||||||||||||||||||||
| 41 | 20 | ▶ | ) unless exists $result->{access_token}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 20 | $token = OAuth::Lite2::Client::Token->new($result); | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | } else { | ||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 33 | ▶ | my $errmsg = $http_res->content || $http_res->status_line; | ||||||||||||||||||||||||||
|
Condition33%1/3
$http_res->content || $http_res->status_line
MC/DC0%0/2
$http_res->content || $http_res->status_line
$http_res->content
$http_res->status_line
Truth table33%1/3
A || B
A= $http_res->contentB= $http_res->status_line
| |||||||||||||||||||||||||||||
| 48 | 33 | ▶ | if ($formatter && $http_res->content) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$formatter and $http_res->content
MC/DC0%0/2
$formatter and $http_res->content
$formatter
$http_res->content
Truth table33%1/3
A and B
A= $formatterB= $http_res->content
| |||||||||||||||||||||||||||||
| 49 | try { | ||||||||||||||||||||||||||||
| 50 | 33 | ▶ | my $result = $formatter->parse($http_res->content); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.2
| |||||||||||||||||||||||||||||
| 51 | $errmsg = $result->{error} | ||||||||||||||||||||||||||||
| 52 | 33 | ▶ | if exists $result->{error}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | 33 | ▶ | } catch { return }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | 33 | OAuth::Lite2::Client::Error::InvalidResponse->throw( message => $errmsg ); | |||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||
| 57 | 20 | return $token; | |||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | 7 | 1; | |||||||||||||||||||||||||||