blib/lib/OIDC/Lite/Server/GrantHandler/AuthorizationCode.pm

filter: Statementstmt 100% 42 / 42 Branchbran 96.6% 29 / 30 Conditioncond 83.3% 10 / 12 MC/DCmcdc 75.0% 6 / 8 Subroutinesub 100% 7 / 7 Podpod 100% 1 / 1 totaltotal 95.0% 95 / 100 CC 20 SCAR 27.5
CC
20
Cov
96%
handle_request
20.0
BEGIN
1.0
BEGIN
1.0
CRAP 15.6
« blib/lib/OIDC/Lite/Server/AuthorizationHandler.pm ↑ Summary blib/lib/Plack/Middleware/Auth/OIDC/ProtectedResource.pm »
1 package OIDC::Lite::Server::GrantHandler::AuthorizationCode;
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 3 ▶use parent 'OAuth::Lite2::Server::GrantHandler';
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use OAuth::Lite2::Server::Error;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use OAuth::Lite2::ParamMethod::AuthHeader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub handle_request {
11 23 ▶ my ($self, $dh) = @_;
Subroutine handle_request: called CC=20 SCAR=30.0
Pod documented
12  
13 23 my $req = $dh->request;
14  
15 23 my $parser = OAuth::Lite2::ParamMethod::AuthHeader->new;
16 23 my $header_credentials = $parser->basic_credentials($req);
17 23 ▶ my $client_id = ($header_credentials->{client_id}) ? $header_credentials->{client_id} : $req->param("client_id");
Branch: 1 branch
BranchTrueFalseTotal
$header_credentials->{'client_id'} ? : 3 20 23
18  
19 23 ▶ my $code = $req->param("code")
Branch: 1 branch
BranchTrueFalseTotal
my $code = $req->param("code") or "OAuth::Lite2::Server::Error::InvalidRequest"->throw("description", "'code' not found") 1 22 23
20 or OAuth::Lite2::Server::Error::InvalidRequest->throw(
21 description => "'code' not found"
22 );
23  
24 22 ▶ my $redirect_uri = $req->param("redirect_uri")
Branch: 1 branch
BranchTrueFalseTotal
my $redirect_uri = $req->param("redirect_uri") or "OAuth::Lite2::Server::Error::InvalidRequest"->throw("description", "'redirect_uri' not found") 2 20 22
25 or OAuth::Lite2::Server::Error::InvalidRequest->throw(
26 description => "'redirect_uri' not found"
27 );
28  
29 20 my $server_state = $req->param("server_state");
30  
31 20 ▶ my $auth_info = $dh->get_auth_info_by_code($code)
Branch: 1 branch
BranchTrueFalseTotal
my $auth_info = $dh->get_auth_info_by_code($code) or "OAuth::Lite2::Server::Error::InvalidGrant"->throw 3 17 20
32 or OAuth::Lite2::Server::Error::InvalidGrant->throw;
33  
34 17 ▶ Carp::croak "OAuth::Lite2::Server::DataHandler::get_auth_info_by_code doesn't return OAuth::Lite2::Model::AuthInfo"
Branch: 1 branch
BranchTrueFalseTotal
unless $auth_info and $auth_info->isa("OIDC::Lite::Model::AuthInfo") 1 16 17
Condition66%2/3
$auth_info and $auth_info->isa("OIDC::Lite::Model::AuthInfo")
!ll&&!rl&&r
0116
MC/DC50%1/2
$auth_info and $auth_info->isa("OIDC::Lite::Model::AuthInfo")
$auth_info $auth_info->isa("OIDC::Lite::Model::AuthInfo")
Truth table66%2/3
A and B
A= $auth_infoB= $auth_info->isa("OIDC::Lite::Model::AuthInfo")
ABresult
0X0
100
111
35 unless ($auth_info
36 && $auth_info->isa("OIDC::Lite::Model::AuthInfo"));
37  
38 16 ▶ OAuth::Lite2::Server::Error::InvalidClient->throw
Branch: 1 branch
BranchTrueFalseTotal
unless $auth_info->client_id eq $client_id 1 15 16
39 unless ($auth_info->client_id eq $client_id);
40  
41 15 ▶ OAuth::Lite2::Server::Error::RedirectURIMismatch->throw
Branch: 1 branch
BranchTrueFalseTotal
unless $auth_info->redirect_uri and $auth_info->redirect_uri eq $redirect_uri 4 11 15
Condition100%3/3
$auth_info->redirect_uri and $auth_info->redirect_uri eq $redirect_uri
!ll&&!rl&&r
1311
MC/DC100%2/2
$auth_info->redirect_uri and $auth_info->redirect_uri eq $redirect_uri
$auth_info->redirect_uri $auth_info->redirect_uri eq $redirect_uri
Truth table100%3/3
A and B
A= $auth_info->redirect_uriB= $auth_info->redirect_uri eq $redirect_uri
ABresult
0X0
100
111
42 unless ( $auth_info->redirect_uri
43 && $auth_info->redirect_uri eq $redirect_uri);
44  
45 11 ▶ if ( $auth_info->server_state ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($auth_info->server_state) { } 6 5 11
46 6 ▶ OAuth::Lite2::Server::Error::InvalidServerState->throw
Branch: 1 branch
BranchTrueFalseTotal
unless $server_state and $server_state eq $auth_info->server_state 4 2 6
Condition100%3/3
$server_state and $server_state eq $auth_info->server_state
!ll&&!rl&&r
222
MC/DC100%2/2
$server_state and $server_state eq $auth_info->server_state
$server_state $server_state eq $auth_info->server_state
Truth table100%3/3
A and B
A= $server_stateB= $server_state eq $auth_info->server_state
ABresult
0X0
100
111
47 unless ( $server_state and $server_state eq $auth_info->server_state );
48 } else {
49 5 ▶ OAuth::Lite2::Server::Error::InvalidServerState->throw if ( $server_state );
Branch: 1 branch
BranchTrueFalseTotal
if $server_state 0 5 5
50 }
51  
52 7 my $access_token = $dh->create_or_update_access_token(
53 auth_info => $auth_info,
54 );
55 7 ▶ Carp::croak "OAuth::Lite2::Server::DataHandler::create_or_update_access_token doesn't return OAuth::Lite2::Model::AccessToken"
Branch: 1 branch
BranchTrueFalseTotal
unless $access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken") 1 6 7
Condition66%2/3
$access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken")
!ll&&!rl&&r
016
MC/DC50%1/2
$access_token and $access_token->isa("OAuth::Lite2::Model::AccessToken")
$access_token $access_token->isa("OAuth::Lite2::Model::AccessToken")
Truth table66%2/3
A and B
A= $access_tokenB= $access_token->isa("OAuth::Lite2::Model::AccessToken")
ABresult
0X0
100
111
56 unless ($access_token
57 && $access_token->isa("OAuth::Lite2::Model::AccessToken"));
58  
59 6 my $res = {
60 token_type => 'Bearer',
61 access_token => $access_token->token,
62 };
63  
64 6 ▶ $res->{expires_in} = $access_token->expires_in
Branch: 1 branch
BranchTrueFalseTotal
if $access_token->expires_in 5 1 6
65 if $access_token->expires_in;
66 6 ▶ $res->{refresh_token} = $auth_info->refresh_token
Branch: 1 branch
BranchTrueFalseTotal
if $auth_info->refresh_token 5 1 6
67 if $auth_info->refresh_token;
68 6 ▶ $res->{scope} = $auth_info->scope
Branch: 1 branch
BranchTrueFalseTotal
if $auth_info->scope 5 1 6
69 if $auth_info->scope;
70  
71 # ID Token
72 6 ▶ $res->{id_token} = $auth_info->id_token
Branch: 1 branch
BranchTrueFalseTotal
if $auth_info->id_token 5 1 6
73 if $auth_info->id_token;
74  
75 6 return $res;
76 }
77  
78 =head1 NAME
79  
80 OIDC::Lite::Server::GrantHandler::AuthorizationCode - handler for 'authorization-code' grant_type request
81  
82 =head1 SYNOPSIS
83  
84 my $handler = OIDC::Lite::Server::GrantHandler::AuthorizationCode->new;
85 my $res = $handler->handle_request( $data_handler );
86  
87 =head1 DESCRIPTION
88  
89 handler for 'authorization-code' grant_type request.
90  
91 =head1 METHODS
92  
93 =head2 handle_request( $req )
94  
95 See L<OAuth::Lite2::Server::GrantHandler> document.
96  
97 =head1 AUTHOR
98  
99 Ryo Ito, E<lt>ritou.06@gmail.comE<gt>
100  
101 =head1 COPYRIGHT AND LICENSE
102  
103 Copyright (C) 2012 by Ryo Ito
104  
105 This library is free software; you can redistribute it and/or modify
106 it under the same terms as Perl itself, either Perl version 5.8.8 or,
107 at your option, any later version of Perl 5 you may have available.
108  
109 =cut
110  
111 3 1;
« blib/lib/OIDC/Lite/Server/AuthorizationHandler.pm ↑ Summary blib/lib/Plack/Middleware/Auth/OIDC/ProtectedResource.pm »