| 1 | package OIDC::Lite::Client::TokenResponseParser; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Try::Tiny qw/try catch/; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use OIDC::Lite::Client::Token; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use OAuth::Lite2::Formatters; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use OAuth::Lite2::Client::Error; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | sub new { | ||||||||||||||||||||||||||||
| 11 | 6 | ▶ | bless {}, $_[0]; | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | sub parse { | ||||||||||||||||||||||||||||
| 15 | 26 | ▶ | my ($self, $http_res) = @_; | ||||||||||||||||||||||||||
|
Subroutine
parse: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 26 | my $formatter = | |||||||||||||||||||||||||||
| 18 | OAuth::Lite2::Formatters->get_formatter_by_type( | ||||||||||||||||||||||||||||
| 19 | $http_res->content_type); | ||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||
| 21 | 26 | my $token; | |||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 26 | ▶ | if ($http_res->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 10 | ▶ | OAuth::Lite2::Client::Error::InvalidResponse->throw( | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$http_res->content_type || ''
MC/DC100%1/1
$http_res->content_type || ''
$http_res->content_type
Truth table100%2/2
A
A= $http_res->content_type
| |||||||||||||||||||||||||||||
| 26 | message => sprintf(q{Invalid response content-type: %s}, | ||||||||||||||||||||||||||||
| 27 | $http_res->content_type||'') | ||||||||||||||||||||||||||||
| 28 | ) unless $formatter; | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | my $result = try { | ||||||||||||||||||||||||||||
| 31 | 8 | ▶ | return $formatter->parse($http_res->content); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 32 | } catch { | ||||||||||||||||||||||||||||
| 33 | 1 | ▶ | OAuth::Lite2::Client::Error::InvalidResponse->throw( | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | message => sprintf(q{Invalid response format: %s}, $_), | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | 8 | }; | |||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | OAuth::Lite2::Client::Error::InvalidResponse->throw( | ||||||||||||||||||||||||||||
| 39 | message => sprintf("Response doesn't include 'access_token'") | ||||||||||||||||||||||||||||
| 40 | 7 | ▶ | ) unless exists $result->{access_token}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||
| 42 | 6 | $token = OIDC::Lite::Client::Token->new($result); | |||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | } else { | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | 16 | ▶ | my $errmsg = $http_res->content || $http_res->status_line; | ||||||||||||||||||||||||||
|
Condition100%3/3
$http_res->content || $http_res->status_line
MC/DC100%2/2
$http_res->content || $http_res->status_line
$http_res->content
$http_res->status_line
Truth table100%3/3
A || B
A= $http_res->contentB= $http_res->status_line
| |||||||||||||||||||||||||||||
| 47 | 16 | ▶ | if ($formatter && $http_res->content) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$formatter and $http_res->content
MC/DC100%2/2
$formatter and $http_res->content
$formatter
$http_res->content
Truth table100%3/3
A and B
A= $formatterB= $http_res->content
| |||||||||||||||||||||||||||||
| 48 | try { | ||||||||||||||||||||||||||||
| 49 | 13 | ▶ | my $result = $formatter->parse($http_res->content); | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 50 | $errmsg = $result->{error} | ||||||||||||||||||||||||||||
| 51 | 12 | ▶ | if exists $result->{error}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } catch { | ||||||||||||||||||||||||||||
| 53 | 1 | ▶ | return OAuth::Lite2::Client::Error::InvalidResponse->throw; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 54 | 13 | }; | |||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||
| 56 | 15 | OAuth::Lite2::Client::Error::InvalidResponse->throw( message => $errmsg ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | 6 | return $token; | |||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | =head1 AUTHOR | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | Ryo Ito, E<lt>ritou.06@gmail.comE<gt> | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | Copyright (C) 2012 by Ryo Ito | ||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||
| 70 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||
| 71 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 3 | 1; | |||||||||||||||||||||||||||