| 1 | package OIDC::Lite::Server::AuthorizationHandler; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 2 | ▶ | use Params::Validate; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use OAuth::Lite2::Server::Error; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 2 | my @DEFINED_DISPLAY_PARAMS = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | page | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | popup | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | touch | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | wap | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 2 | my @DEFINED_PROMPT_PARAMS = qw( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | none | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | login | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | consent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | select_account | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 40 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 40 | my %args = Params::Validate::validate(@_, { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | data_handler => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | response_types => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | }); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | my $self = bless { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | data_handler => $args{data_handler}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | response_types => $args{response_types}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 40 | }, $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 40 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | sub handle_request { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 27 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
handle_request: called CC=34 SCAR=35.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 27 | my $dh = $self->{data_handler}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 27 | my $req = $self->{data_handler}->request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # response_type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 27 | my $allowed_response_type = $self->{response_types}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 27 | ▶ | my $response_type = $req->param("response_type") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | or OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | description => "'response_type' not found" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 26 | my @response_type_for_sort = split(/\s/, $response_type); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 26 | @response_type_for_sort = sort @response_type_for_sort; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 26 | $response_type = join(' ', @response_type_for_sort); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 26 | my %allowed_response_type_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 26 | $allowed_response_type_hash{$_}++ foreach @$allowed_response_type; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | description => "'response_type' not allowed" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 26 | ▶ | ) unless (exists $allowed_response_type_hash{$response_type}); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | # client_id | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 25 | ▶ | my $client_id = $req->param("client_id") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | or OAuth::Lite2::Server::Error::InvalidClient->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | description => "'client_id' not found" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | 24 | ▶ | OAuth::Lite2::Server::Error::InvalidClient->throw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | unless ($dh->validate_client_by_id($client_id)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 23 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | description => "'response_type' not allowed for this 'client_id'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | ) unless ($dh->validate_client_for_authorization($client_id, $response_type)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | # redirect_uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 22 | ▶ | my $redirect_uri = $req->param("redirect_uri") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | or OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | description => "'redirect_uri' not found" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 21 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | description => "'redirect_uri' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | ) unless ($dh->validate_redirect_uri($client_id, $redirect_uri)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # sever_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | # validate server_state for CSRF Protection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 20 | my $server_state = $req->param("server_state"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 20 | ▶ | if ( $server_state ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 1 | ▶ | OAuth::Lite2::Server::Error::InvalidServerState->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | description => "'server_state' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | ) unless $dh->validate_server_state($server_state, $client_id); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | # scope | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 19 | my $scope = $req->param("scope"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 19 | ▶ | OAuth::Lite2::Server::Error::InvalidScope->throw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | unless ($dh->validate_scope($client_id, $scope)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | # scope and server_state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | 18 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$server_state or not $dh->require_server_state($scope)
MC/DC50%1/2
$server_state or not $dh->require_server_state($scope)
$server_state
not $dh->require_server_state($scope)
Truth table66%2/3
A or not(B)
A= $server_stateB= not $dh->require_server_state($scope)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | description => "This scope requires 'server_state'" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | ) unless ($server_state || !$dh->require_server_state($scope)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | ## optional parameters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # nonce | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 17 | my $nonce = $req->param("nonce"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 17 | ▶ | if ( $response_type ne "token" && $response_type ne "code" && $response_type ne "code token") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$response_type ne "token" and $response_type ne "code" and $response_type ne "code token"
$response_type ne "token" and $response_type ne "code"
MC/DC100%3/3
$response_type ne "token" and $response_type ne "code" and $response_type ne "code token"
$response_type ne "token"
$response_type ne "code"
$response_type ne "code token"
Truth table100%4/4
A and B and C
A= $response_type ne "token"B= $response_type ne "code"C= $response_type ne "code token"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 2 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | description => "nonce_required" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | ) unless $nonce; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | # display | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 16 | my $display = $req->param("display"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 16 | ▶ | if ( $display ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 3 | my %defined_display_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 3 | $defined_display_hash{$_}++ foreach @DEFINED_DISPLAY_PARAMS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | description => "'display' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | ) unless ( exists $defined_display_hash{$display} && $dh->validate_display($display)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $defined_display_hash{$display} and $dh->validate_display($display)
MC/DC100%2/2
exists $defined_display_hash{$display} and $dh->validate_display($display)
exists $defined_display_hash{$display}
$dh->validate_display($display)
Truth table100%3/3
A and B
A= exists $defined_display_hash{$display}B= $dh->validate_display($display)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # prompt | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 14 | my $prompt = $req->param("prompt"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 14 | ▶ | if ( $prompt ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 3 | my %defined_prompt_hash; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 3 | $defined_prompt_hash{$_}++ foreach @DEFINED_PROMPT_PARAMS; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | description => "'prompt' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | ) unless ( exists $defined_prompt_hash{$prompt} && $dh->validate_prompt($prompt)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
exists $defined_prompt_hash{$prompt} and $dh->validate_prompt($prompt)
MC/DC100%2/2
exists $defined_prompt_hash{$prompt} and $dh->validate_prompt($prompt)
exists $defined_prompt_hash{$prompt}
$dh->validate_prompt($prompt)
Truth table100%3/3
A and B
A= exists $defined_prompt_hash{$prompt}B= $dh->validate_prompt($prompt)
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | # max_age | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 12 | ▶ | description => "'max_age' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | ) unless ($dh->validate_max_age($req->parameters())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | # ui_locales | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | 11 | my $ui_locales = $req->param("ui_locales"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 11 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | description => "'ui_locales' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ) unless ($dh->validate_ui_locales($ui_locales)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | # claims_locales | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 10 | my $claims_locales = $req->param("claims_locales"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 10 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | description => "'claims_locales' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | ) unless ($dh->validate_claims_locales($claims_locales)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | # id_token_hint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 9 | my $id_token_hint = $req->param("id_token_hint"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 9 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | description => "'id_token_hint' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | ) unless ($dh->validate_id_token_hint($req->parameters)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # login_hint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 8 | my $login_hint = $req->param("login_hint"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 8 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | description => "'login_hint' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ) unless ($dh->validate_login_hint($req->parameters)); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # acr_values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 7 | my $acr_values = $req->param("acr_values"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | 7 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | description => "'acr_values' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | ) unless ($dh->validate_acr_values($req->parameters())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 6 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | description => "'request' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | ) unless ($dh->validate_request($req->parameters())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | # request_uri | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 5 | ▶ | OAuth::Lite2::Server::Error::InvalidRequest->throw( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | description => "'request_uri' is invalid" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ) unless ($dh->validate_request_uri($req->parameters())); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | sub allow { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 9 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
allow: called CC=17 SCAR=28.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | 9 | my $dh = $self->{data_handler}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | 9 | my $req = $self->{data_handler}->request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 9 | my @response_type_for_sort = split(/\s/, $req->param("response_type")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 9 | @response_type_for_sort = sort @response_type_for_sort; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 9 | my $response_type = join(' ', @response_type_for_sort); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 9 | my $client_id = $req->param("client_id"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 9 | my $user_id = $dh->get_user_id_for_authorization(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 9 | my $scope = $req->param("scope"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # create id_token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | 9 | my $id_token = $dh->create_id_token(); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | # create authInfo | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 9 | my $auth_info = $dh->create_or_update_auth_info( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | client_id => $client_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | user_id => $user_id, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | scope => $scope, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | id_token => $id_token->get_token_string(), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | # create Access Token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 9 | my $access_token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 9 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$response_type eq "token" or $response_type eq "code token" or $response_type eq "id_token token" or $response_type eq "code id_token token"
$response_type eq "token" or $response_type eq "code token" or $response_type eq "id_token token"
$response_type eq "token" or $response_type eq "code token"
MC/DC100%4/4
$response_type eq "token" or $response_type eq "code token" or $response_type eq "id_token token" or $response_type eq "code id_token token"
$response_type eq "token"
$response_type eq "code token"
$response_type eq "id_token token"
$response_type eq "code id_token token"
Truth table100%5/5
A or B or C or D
A= $response_type eq "token"B= $response_type eq "code token"C= $response_type eq "id_token token"D= $response_type eq "code id_token token"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | $response_type eq 'token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | $response_type eq 'code token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | $response_type eq 'id_token token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | $response_type eq 'code id_token token') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 5 | $access_token = $dh->create_or_update_access_token( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | auth_info => $auth_info, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 9 | my $params = {}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | # state | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | 9 | ▶ | $params->{state} = $req->param("state") if($req->param("state")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | # access token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 9 | ▶ | if($access_token){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | 5 | $id_token->access_token_hash($access_token->token); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 5 | $params->{access_token} = $access_token->token; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | 5 | $params->{token_type} = q{Bearer}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 5 | ▶ | $params->{expires_in} = $access_token->expires_in if($access_token->expires_in); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | # authorization code | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 9 | ▶ | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$response_type eq "code" or $response_type eq "code token" or $response_type eq "code id_token" or $response_type eq "code id_token token"
$response_type eq "code" or $response_type eq "code token" or $response_type eq "code id_token"
$response_type eq "code" or $response_type eq "code token"
MC/DC100%4/4
$response_type eq "code" or $response_type eq "code token" or $response_type eq "code id_token" or $response_type eq "code id_token token"
$response_type eq "code"
$response_type eq "code token"
$response_type eq "code id_token"
$response_type eq "code id_token token"
Truth table100%5/5
A or B or C or D
A= $response_type eq "code"B= $response_type eq "code token"C= $response_type eq "code id_token"D= $response_type eq "code id_token token"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | $response_type eq 'code' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | $response_type eq 'code token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | $response_type eq 'code id_token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | $response_type eq 'code id_token token') | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 5 | $params->{code} = $auth_info->code; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 5 | $id_token->code_hash($auth_info->code); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | # id_token | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | 9 | ▶ | $params->{id_token} = $id_token->get_token_string() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
$response_type eq "id_token" or $response_type eq "code id_token" or $response_type eq "id_token token" or $response_type eq "code id_token token"
$response_type eq "id_token" or $response_type eq "code id_token" or $response_type eq "id_token token"
$response_type eq "id_token" or $response_type eq "code id_token"
MC/DC100%4/4
$response_type eq "id_token" or $response_type eq "code id_token" or $response_type eq "id_token token" or $response_type eq "code id_token token"
$response_type eq "id_token"
$response_type eq "code id_token"
$response_type eq "id_token token"
$response_type eq "code id_token token"
Truth table100%5/5
A or B or C or D
A= $response_type eq "id_token"B= $response_type eq "code id_token"C= $response_type eq "id_token token"D= $response_type eq "code id_token token"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | if ( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | $response_type eq 'id_token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | $response_type eq 'code id_token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | $response_type eq 'id_token token' || | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | $response_type eq 'code id_token token' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | # build response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | 9 | my $res = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | redirect_uri => $req->param("redirect_uri"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | # set data to query or fragment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 9 | ▶ | if($response_type eq 'code'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 2 | $res->{query} = $params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 7 | $res->{fragment} = $params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 9 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | sub deny { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 4 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
deny: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | 4 | my $dh = $self->{data_handler}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 4 | my $req = $self->{data_handler}->request; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | my @response_type_for_sort = split(/\s/, $req->param("response_type")); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | 4 | @response_type_for_sort = sort @response_type_for_sort; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 4 | my $response_type = join(' ', @response_type_for_sort); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | my $params = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | error => q{access_denied}, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | 4 | ▶ | $params->{state} = $req->param("state") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | if($req->param("state")); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 4 | my $res = { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | redirect_uri => $req->param("redirect_uri"), | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | # build response | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | 4 | ▶ | if($response_type eq 'code'){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 2 | $res->{query} = $params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 2 | $res->{fragment} = $params; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 4 | return $res; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | OIDC::Lite::Server::AuthorizationHandler - handler for OpenID Connect Authorization request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # At Authorization Endpoint | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | my $handler = OIDC::Lite::Server::AuthorizationHandler->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | $handler->handle_request(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | # after user agreement | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | my $res; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | if($allowed){ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | $res = $handler->allow(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | }else{ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | $res = $handler->deny(); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | ... | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | handler for OpenID Connect authorization request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | =head2 handle_request( $req ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | Processes authorization request. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | If there is error, L<OAuth::Lite2::Server::Error> object is thrown. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | =head2 allow( $req ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | Returns authorization response params. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | =head2 deny( $req ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | Returns authorization error response params. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | Ryo Ito, E<lt>ritou.06@gmail.comE<gt> | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | =head1 COPYRIGHT AND LICENSE | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | Copyright (C) 2012 by Ryo Ito | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | it under the same terms as Perl itself, either Perl version 5.8.8 or, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | at your option, any later version of Perl 5 you may have available. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 2 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||