blib/lib/Lemonldap/NG/Portal/Auth/OpenIDConnect.pm

filter: Statementstmt 68.7% 249 / 362 Branchbran 44.8% 78 / 174 Conditioncond 38.0% 19 / 50 MC/DCmcdc 10.0% 3 / 30 Subroutinesub 89.4% 17 / 19 Podpod 0.0% 0 / 11 totaltotal 56.6% 366 / 646 CC 114 SCAR 45.7
CC
114
Cov
59%
extractFormInfo
188.2
backLogout
68.5
frontLogout
61.4
CRAP 96.5
« blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/PasswordGrant.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/RESTServer.pm »
1 package Lemonldap::NG::Portal::Auth::OpenIDConnect;
2  
3 46 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 46 ▶use Mouse;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 46 ▶use MIME::Base64 qw/encode_base64 decode_base64/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 46 ▶use Scalar::Util qw/looks_like_number/;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 46 ▶use Lemonldap::NG::Common::JWT qw(getJWTPayload);
Subroutine BEGIN: called CC=1 SCAR=0.0
8 46 ▶use Lemonldap::NG::Portal::Main::Constants qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
9 PE_OK
10 PE_IDPCHOICE
11 PE_OIDC_AUTH_ERROR
12 PE_SENDRESPONSE
13 PE_REDIRECT
14 46 );
15  
16 46 our $VERSION = '2.23.0';
17  
18 46 extends qw(
19 Lemonldap::NG::Portal::Main::Auth
20 Lemonldap::NG::Portal::Lib::OpenIDConnect
21 );
22  
23 46 with qw(
24 Lemonldap::NG::Portal::Lib::Key
25 );
26  
27 # INTERFACE
28  
29 50 ▶has opList => ( is => 'rw', isa => 'ArrayRef', default => sub { [] } );
Subroutine __ANON__: called CC=1 SCAR=0.0
30 46 has path => ( is => 'rw', default => 'oauth2' );
31 46 has endpointsRe => ( is => 'rw' );
32  
33 46 ▶use constant sessionKind => 'OIDC';
Subroutine BEGIN: called CC=1 SCAR=0.0
34  
35 # INITIALIZATION
36  
37 49 ▶sub init {
Subroutine init: called CC=12 SCAR=26.2
Pod undocumented
38 49 my $self = shift;
39  
40 49 ▶ return 0 unless ( $self->loadOPs and $self->refreshJWKSdata );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->loadOPs and $self->refreshJWKSdata 0 49 49
Condition33%1/3
$self->loadOPs and $self->refreshJWKSdata
!ll&&!rl&&r
0049
MC/DC0%0/2
$self->loadOPs and $self->refreshJWKSdata
$self->loadOPs $self->refreshJWKSdata
Truth table33%1/3
A and B
A= $self->loadOPsB= $self->refreshJWKSdata
ABresult
0X0
100
111
41 49 my @tab = ( sort keys %{ $self->opMetadata } );
42 49 ▶ unless (@tab) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@tab) 0 49 49
43 0 $self->logger->error("No OP configured");
44 0 return 0;
45 }
46 49 my @list = ();
47  
48 49 foreach (@tab) {
49 51 my $name = $_;
50 $name = $self->opOptions->{$_}->{oidcOPMetaDataOptionsDisplayName}
51 51 ▶ if $self->opOptions->{$_}->{oidcOPMetaDataOptionsDisplayName};
Branch: 1 branch
BranchTrueFalseTotal
if $self->opOptions->{$_}{"oidcOPMetaDataOptionsDisplayName"} 1 50 51
52 51 my $icon = $self->opOptions->{$_}->{oidcOPMetaDataOptionsIcon};
53 my $tooltip =
54 51 ▶ $self->opOptions->{$_}->{oidcOPMetaDataOptionsTooltip} || $name;
Condition66%2/3
$self->opOptions->{$_}{'oidcOPMetaDataOptionsTooltip'} || $name
l!l&&r!l&&!r
1500
MC/DC0%0/2
$self->opOptions->{$_}{'oidcOPMetaDataOptionsTooltip'} || $name
$self->opOptions->{$_}{'oidcOPMetaDataOptionsTooltip'} $name
Truth table66%2/3
A || B
A= $self->opOptions->{$_}{'oidcOPMetaDataOptionsTooltip'}B= $name
ABresult
1X1
011
000
55 my $order = $self->opOptions->{$_}->{oidcOPMetaDataOptionsSortNumber}
56 51 ▶ // 999999;
Condition100%2/2
$self->opOptions->{$_}{"oidcOPMetaDataOptionsSortNumber"} // 999999
l!l
249
MC/DC100%1/1
$self->opOptions->{$_}{"oidcOPMetaDataOptionsSortNumber"} // 999999
$self->opOptions->{$_}{"oidcOPMetaDataOptionsSortNumber"}
Truth table100%2/2
A
A= $self->opOptions->{$_}{"oidcOPMetaDataOptionsSortNumber"}
Aresult
11
00
57 51 my $img_src;
58  
59 51 ▶ if ($icon) {
Branch: 1 branch
BranchTrueFalseTotal
if ($icon) 1 50 51
60 1 ▶ $img_src =
Branch: 1 branch
BranchTrueFalseTotal
$icon =~ m[^https?://] ? : 0 1 1
61 ( $icon =~ m#^https?://# )
62 ? $icon
63 : $self->p->staticPrefix . "/common/" . $icon;
64 }
65  
66 51 push @list,
67 {
68 val => $_,
69 name => $name,
70 title => $tooltip,
71 icon => $img_src,
72 order => $order
73 };
74 }
75  
76 my $re = '^/' . $self->path . '/(?:' . join(
77 '|',
78 map {
79 49 my $s = $self->conf->{$_};
80 98 $s =~ s/#PORTAL#\/*//;
81 98 $s
82 } ( qw(
83 oidcServiceMetaDataFrontChannelURI
84 oidcServiceMetaDataBackChannelURI
85 )
86 )
87 ) . ')(?:[\?/].*)?$';
88  
89 49 $self->endpointsRe(qr/$re/);
90  
91 49 $self->addRouteFromConf(
92 'Auth',
93 oidcServiceMetaDataFrontChannelURI => 'frontLogout',
94 oidcServiceMetaDataBackChannelURI => 'backLogout',
95 oidcServiceMetaDataJWKSURI => 'jwks',
96 );
97 49 $self->addRouteFromConf(
98 'Unauth',
99 oidcServiceMetaDataJWKSURI => 'jwks',
100 oidcServiceMetaDataRpLogoutReturnURI => 'rpLogoutReturn',
101 );
102  
103 @list =
104 sort {
105 49 $a->{order} <=> $b->{order}
106 or $a->{name} cmp $b->{name}
107 or $a->{val} cmp $b->{val}
108 2 ▶ } @list;
Condition33%2/6
$Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'order'} <=> $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'order'} || $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'name'} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'name'} || $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'val'} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'val'}
l!l&&r!l&&!r
200
$Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{"order"} or $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{"name"}
l!l&&r!l&&!r
200
MC/DC0%0/3
$Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'order'} <=> $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'order'} || $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'name'} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'name'} || $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'val'} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'val'}
$Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{"order"} $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{"name"} $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'val'} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'val'}
Truth table25%1/4
A or B || C
A= $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{"order"} <=> $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{"order"}B= $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{"name"} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{"name"}C= $Lemonldap::NG::Portal::Auth::OpenIDConnect::a->{'val'} cmp $Lemonldap::NG::Portal::Auth::OpenIDConnect::b->{'val'}
ABCresult
1XX1
01X1
0011
0000
109 49 $self->opList( [@list] );
110 49 return 1;
111 }
112  
113 # RUNNING METHODS
114  
115 135 ▶sub extractFormInfo {
Subroutine extractFormInfo: called CC=51 SCAR=52.4
Pod undocumented
116 135 my ( $self, $req ) = @_;
117 135 ▶ if ( $req->uri =~ $self->endpointsRe ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->uri =~ $self->endpointsRe) 2 133 135
118 2 my $path = $req->path;
119 2 my $tmp = $self->path;
120 2 $path =~ s#^/*\Q$tmp\E/*##o;
121 2 $path =~ s#/.*$##;
122 2 ▶ if ( $path eq $self->conf->{oidcServiceMetaDataBackChannelURI} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($path eq $self->conf->{'oidcServiceMetaDataBackChannelURI'}) { } 1 1 2
elsif ($path eq $self->conf->{'oidcServiceMetaDataFrontChannelURI'}) { } 1 0 1
123 1 $req->response( $self->backLogout($req) );
124 1 return PE_SENDRESPONSE;
125 }
126 elsif ( $path eq $self->conf->{oidcServiceMetaDataFrontChannelURI} ) {
127 1 $req->response( $self->searchAndLogout($req) );
128 1 return PE_SENDRESPONSE;
129 }
130 }
131  
132 # Check callback
133 133 ▶ if ( $self->isCallback($req)
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isCallback($req) and not $req->param("oidc_callback_processed")) 2 131 133
Condition100%3/3
$self->isCallback($req) and not $req->param("oidc_callback_processed")
!ll&&!rl&&r
13012
MC/DC100%2/2
$self->isCallback($req) and not $req->param("oidc_callback_processed")
$self->isCallback($req) not $req->param("oidc_callback_processed")
Truth table100%3/3
A and not(B)
A= $self->isCallback($req)B= not $req->param("oidc_callback_processed")
ABresult
0X0
100
111
134 and not $req->param('oidc_callback_processed') )
135 {
136 # This makes sure we don't go through the callback code when re-posting
137 # a login form
138 2 $self->p->setHiddenFormValue( $req, "oidc_callback_processed", "1", "",
139 0 );
140  
141 2 $self->logger->debug(
142 'OpenIDConnect callback URI detected: ' . $req->uri );
143  
144 # Initialize callback_params with all known OIDC callback parameters
145 2 my $callback_params = {
146 state => scalar( $req->param('state') ),
147 code => scalar( $req->param('code') ),
148 error => scalar( $req->param('error') ),
149 error_description => scalar( $req->param('error_description') ),
150 error_uri => scalar( $req->param('error_uri') ),
151 iss => scalar( $req->param('iss') ),
152 };
153  
154 # Call hook - plugins can modify callback_params
155 2 my $hook_res =
156 $self->p->processHook( $req, 'oidcGotAuthenticationResponse',
157 $callback_params );
158 2 ▶ return $hook_res if ( $hook_res != PE_OK and $hook_res > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $hook_res != 0 and $hook_res > 0 0 2 2
Condition33%1/3
$hook_res != 0 and $hook_res > 0
!ll&&!rl&&r
200
MC/DC0%0/2
$hook_res != 0 and $hook_res > 0
$hook_res != 0 $hook_res > 0
Truth table33%1/3
A and B
A= $hook_res != 0B= $hook_res > 0
ABresult
0X0
100
111
159  
160 # Restore state
161 2 my $state = $callback_params->{state};
162 2 ▶ if ($state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state) 1 1 2
163  
164 # If state is a hashref, hook already extracted it - skip extractState
165 # If state is a scalar, call extractState
166 1 ▶ if ( ref($state) eq 'HASH' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $state eq 'HASH') { } 0 1 1
elsif ($self->extractState($req, $state)) { } 1 0 1
167 0 $self->logger->debug("State already extracted by hook");
168 0 $req->data->{_oidcOPCurrent} = $state->{_oidcOPCurrent};
169 0 $req->data->{_oidcNonce} = $state->{_oidcNonce};
170 0 $req->data->{_url} = $state->{urldc};
171 }
172 elsif ( $self->extractState( $req, $state ) ) {
173 1 $self->logger->debug("State $state extracted");
174 }
175 else {
176 0 $self->userLogger->error("Unable to extract state $state");
177 0 return PE_OIDC_AUTH_ERROR;
178 }
179 }
180  
181 # Get OpenID Provider
182 2 my $op = $req->data->{_oidcOPCurrent};
183  
184 2 ▶ unless ($op) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op) 1 1 2
185 1 $self->userLogger->error("OpenIDConnect Provider not found");
186 1 return PE_OIDC_AUTH_ERROR;
187 }
188  
189 1 $self->logger->debug("Using OpenIDConnect Provider $op");
190  
191 # RFC 9207: Verify iss parameter if present or required
192 1 my $iss = $callback_params->{iss};
193 1 my $expected_iss = $self->opMetadata->{$op}->{conf}->{issuer};
194  
195 1 ▶ if ($iss) {
Branch: 2 branches
BranchTrueFalseTotal
if ($iss) { } 1 0 1
elsif ($self->conf->{'oidcOPMetaDataOptions'}{$op}{'oidcOPMetaDataOptionsRequireIss'}) { } 0 0 0
196 1 ▶ unless ( $iss eq $expected_iss ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($iss eq $expected_iss) 0 1 1
197 0 $self->userLogger->error(
198 "Issuer mismatch: received '$iss', expected '$expected_iss'"
199 );
200 0 return PE_OIDC_AUTH_ERROR;
201 }
202 1 $self->logger->debug("Issuer verification passed");
203 }
204 elsif ( $self->conf->{oidcOPMetaDataOptions}->{$op}
205 ->{oidcOPMetaDataOptionsRequireIss} )
206 {
207 0 $self->userLogger->error(
208 "Missing iss parameter in authorization response (required by config)"
209 );
210 0 return PE_OIDC_AUTH_ERROR;
211 }
212  
213 # Check error
214 1 my $error = $callback_params->{error};
215 1 ▶ if ($error) {
Branch: 1 branch
BranchTrueFalseTotal
if ($error) 0 1 1
216 0 my $error_description = $callback_params->{error_description};
217 0 my $error_uri = $callback_params->{error_uri};
218  
219 0 $self->logger->error("Error returned by $op Provider: $error");
220 0 ▶ $self->logger->error("Error description: $error_description")
Branch: 1 branch
BranchTrueFalseTotal
if $error_description 0 0 0
221 if $error_description;
222 0 ▶ $self->logger->error("Error URI: $error_uri") if $error_uri;
Branch: 1 branch
BranchTrueFalseTotal
if $error_uri 0 0 0
223  
224 0 return PE_OIDC_AUTH_ERROR;
225 }
226  
227 # Get access_token and id_token
228 1 my $code = $callback_params->{code};
229  
230 1 my $content =
231 $self->getAuthorizationCodeAccessToken( $req, $op, $code );
232 1 ▶ return PE_OIDC_AUTH_ERROR unless $content;
Branch: 1 branch
BranchTrueFalseTotal
unless $content 0 1 1
233  
234 1 my $token_response = $self->decodeTokenResponse($content);
235  
236 1 ▶ unless ($token_response) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($token_response) 0 1 1
237 0 $self->logger->error("Could not decode Token Response: $content");
238 0 return PE_OIDC_AUTH_ERROR;
239 }
240  
241 # Check validity of token response
242 1 ▶ unless ( $self->checkTokenResponseValidity($token_response) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->checkTokenResponseValidity($token_response)) { } 1 0 1
243 0 $self->logger->error("Token response is not valid");
244 0 return PE_OIDC_AUTH_ERROR;
245 }
246 else {
247 1 $self->logger->debug("Token response is valid");
248 }
249  
250 # Check if returned scopes match requested scopes (#3585)
251 # Ignore offline_access (often stripped by OP) and ordering differences
252 1 my $reqs = $self->opOptions->{$op}->{oidcOPMetaDataOptionsScope};
253 1 ▶ if ( my $recs = $token_response->{scope} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $recs = $token_response->{"scope"}) 0 1 1
254 0 my %scopes;
255 0 $scopes{$_} += 1 for split( /\s+/, $reqs );
256 0 $scopes{$_} -= 1 for split( /\s+/, $recs );
257 0 delete $scopes{offline_access};
258 0 ▶ if ( grep { $_ } values %scopes ) {
Branch: 1 branch
BranchTrueFalseTotal
if (grep {$_;} values %scopes) 0 0 0
259 0 $self->userLogger->warn( "OP $op returned different scopes"
260 . " than requested: requested='$reqs',"
261 . " received='$recs'" );
262 }
263 }
264  
265 1 my $access_token = $token_response->{access_token};
266 1 my $expires_in = $token_response->{expires_in};
267 1 my $id_token = $self->decryptJwt( $token_response->{id_token} );
268 1 my $refresh_token = $token_response->{refresh_token};
269  
270 1 ▶ undef $expires_in unless looks_like_number($expires_in);
Branch: 1 branch
BranchTrueFalseTotal
unless &looks_like_number($expires_in) 0 1 1
271  
272 1 $self->logger->debug("Access token: $access_token");
273 1 ▶ $self->logger->debug(
Condition50%1/2
$expires_in || '<unknown>'
l!l
10
MC/DC0%0/1
$expires_in || '<unknown>'
$expires_in
Truth table50%1/2
A
A= $expires_in
Aresult
11
00
274 "Access token expires in: " . ( $expires_in || "<unknown>" ) );
275 1 $self->logger->debug("ID token: $id_token");
276 1 ▶ $self->logger->debug(
Condition50%1/2
$refresh_token || '<none>'
l!l
01
MC/DC0%0/1
$refresh_token || '<none>'
$refresh_token
Truth table50%1/2
A
A= $refresh_token
Aresult
11
00
277 "Refresh token: " . ( $refresh_token || "<none>" ) );
278  
279 # Verify JWT signature
280 1 my $id_token_payload_hash;
281 1 ▶ if ( $self->opOptions->{$op}->{oidcOPMetaDataOptionsCheckJWTSignature} )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opOptions->{$op}{'oidcOPMetaDataOptionsCheckJWTSignature'}) { } 1 0 1
282 {
283 1 ▶ unless ( $id_token_payload_hash =
Branch: 1 branch
BranchTrueFalseTotal
unless ($id_token_payload_hash = $self->decodeJWT($id_token, $op)) 0 1 1
284 $self->decodeJWT( $id_token, $op ) )
285 {
286 0 $self->logger->error("JWT signature verification failed");
287 0 $self->logger->error("Failing JWT is: $id_token");
288 0 return PE_OIDC_AUTH_ERROR;
289 }
290 1 $self->logger->debug("JWT signature verified");
291 }
292 else {
293 0 $self->logger->debug("JWT signature check disabled");
294 0 $id_token_payload_hash = getJWTPayload($id_token);
295 }
296  
297 1 ▶ unless ( defined $id_token_payload_hash ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $id_token_payload_hash) 0 1 1
298 0 $self->logger->error(
299 "Could not decode incoming ID token: $id_token");
300 0 return PE_OIDC_AUTH_ERROR;
301 }
302  
303 # Call oidcGotIDToken hook
304 1 my $h = $self->p->processHook( $req, 'oidcGotIDToken',
305 $op, $id_token_payload_hash, );
306 1 ▶ return PE_OIDC_AUTH_ERROR if ( $h != PE_OK );
Branch: 1 branch
BranchTrueFalseTotal
if $h != 0 0 1 1
307  
308 # Check validity of Access Token (optional)
309 1 my $at_hash = $id_token_payload_hash->{at_hash};
310 1 ▶ if ($at_hash) {
Branch: 1 branch
BranchTrueFalseTotal
if ($at_hash) { } 1 0 1
311 1 ▶ unless ( $self->verifyHash( $access_token, $at_hash, $id_token ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->verifyHash($access_token, $at_hash, $id_token)) 0 1 1
312 0 $self->userLogger->error(
313 "Access token hash verification failed");
314 0 return PE_OIDC_AUTH_ERROR;
315 }
316 1 $self->logger->debug("Access token hash verified");
317 }
318 else {
319 0 $self->logger->debug(
320 "No at_hash in ID Token, access token will not be verified");
321 }
322  
323 # Check validity of ID Token
324 1 ▶ unless (
Branch: 1 branch
BranchTrueFalseTotal
if ($self->checkIDTokenValidity($op, $id_token_payload_hash, $req->data->{'_oidcNonce'})) { } 1 0 1
325 $self->checkIDTokenValidity(
326 $op, $id_token_payload_hash, $req->data->{_oidcNonce}
327 )
328 )
329 {
330 0 $self->userLogger->error('ID Token not valid');
331 0 return PE_OIDC_AUTH_ERROR;
332 }
333 else {
334 1 $self->logger->debug('ID Token is valid');
335 }
336  
337 # Get sub from ID token
338 1 my $id_token_sub = $id_token_payload_hash->{sub};
339 1 ▶ if ( !$id_token_sub ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($id_token_sub) 0 1 1
340 0 $self->logger->error("Could not find sub claim in ID Token");
341 0 return PE_OIDC_AUTH_ERROR;
342 }
343 1 my $user_id = $id_token_sub;
344  
345 # Get user identifier, if different from sub
346 my $user_claim = $self->conf->{oidcOPMetaDataOptions}->{$op}
347 1 ->{oidcOPMetaDataOptionsUserAttribute};
348 1 ▶ if ($user_claim) {
Branch: 1 branch
BranchTrueFalseTotal
if ($user_claim) 0 1 1
349 0 $user_id = $id_token_payload_hash->{$user_claim};
350 0 ▶ if ( !$user_id ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($user_id) 0 0 0
351 0 $self->logger->error(
352 "Could not find $user_claim claim in ID Token");
353 0 return PE_OIDC_AUTH_ERROR;
354 }
355 }
356  
357 # Remember ID Token sub
358 1 $req->data->{id_token_sub} = $id_token_sub;
359  
360 # Remember tokens
361 1 $req->data->{access_token} = $access_token;
362 1 ▶ $req->data->{refresh_token} = $refresh_token if $refresh_token;
Branch: 1 branch
BranchTrueFalseTotal
if $refresh_token 0 1 1
363 1 $req->data->{id_token} = $id_token;
364  
365 # Remember sid claim if given
366 $req->data->{op_sid} = $id_token_payload_hash->{sid}
367 1 ▶ if $id_token_payload_hash->{sid};
Branch: 1 branch
BranchTrueFalseTotal
if $id_token_payload_hash->{"sid"} 1 0 1
368  
369 # Remember acr/amr claims
370 $req->data->{id_token_acr} = $id_token_payload_hash->{acr}
371 1 ▶ if $id_token_payload_hash->{acr};
Branch: 1 branch
BranchTrueFalseTotal
if $id_token_payload_hash->{"acr"} 1 0 1
372 $req->data->{id_token_amr} = $id_token_payload_hash->{amr}
373 1 ▶ if $id_token_payload_hash->{amr};
Branch: 1 branch
BranchTrueFalseTotal
if $id_token_payload_hash->{"amr"} 0 1 1
374  
375 # If access token TTL is given save expiration date
376 # (with security margin)
377 1 ▶ if ($expires_in) {
Branch: 1 branch
BranchTrueFalseTotal
if ($expires_in) 1 0 1
378 1 $req->data->{access_token_eol} = time + ( $expires_in * 0.9 );
379 }
380  
381 1 $self->logger->debug( "Found user_id: " . $user_id );
382 1 $req->user($user_id);
383  
384 1 return PE_OK;
385 }
386  
387 # No callback, choose Provider and send authn request
388 131 my $op;
389  
390 131 ▶ unless ( $op = $req->param("idp") ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op = $req->param("idp")) 131 0 131
391 131 $self->logger->debug("Redirecting user to OP list");
392  
393 # Auto select provider if there is only one
394 131 ▶ if ( @{ $self->opList } == 1 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$self->opList;} == 1) { } 130 1 131
395 130 $op = $self->opList->[0]->{val};
396 130 $self->logger->debug("Selecting the only defined OP: $op");
397 }
398  
399 else {
400  
401 # Try to use OP resolution rules
402 1 foreach ( keys %{ $self->opRules } ) {
403 0 ▶ my $cond = $self->opRules->{$_} or next;
Branch: 1 branch
BranchTrueFalseTotal
my $cond = $self->opRules->{$_} or next 0 0 0
404 0 ▶ if ( $cond->( $req, $req->sessionInfo ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$cond($req, $req->sessionInfo)) 0 0 0
405 0 $self->logger->debug("OP $_ selected from resolution rule");
406 0 $op = $_;
407 0 last;
408 }
409 }
410  
411 1 ▶ unless ($op) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($op) 1 0 1
412  
413 # display OP list
414 1 $req->data->{list} = $self->opList;
415 1 $req->data->{login} = 1;
416 1 return PE_IDPCHOICE;
417 }
418 }
419 }
420  
421 # Provider is choosen
422 130 $self->logger->debug("OpenID Provider $op choosen");
423  
424 130 $req->data->{_oidcOPCurrent} = $op;
425  
426 # AuthN Request
427 130 $self->logger->debug("Build OpenIDConnect AuthN Request");
428  
429 130 my $nonce;
430 130 ▶ if ( $self->opOptions->{$op}->{oidcOPMetaDataOptionsUseNonce} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opOptions->{$op}{"oidcOPMetaDataOptionsUseNonce"}) 37 93 130
431 37 $nonce = $self->generateNonce();
432 37 $req->data->{_oidcNonce} = $nonce;
433 }
434  
435 # Save state
436 130 my $state = $self->storeState( $req,
437 qw/urldc checkLogins _oidcOPCurrent _oidcNonce/ );
438  
439 # Authorization Code Flow
440 130 my $authorization_request_uri =
441 $self->buildAuthorizationCodeAuthnRequest( $req, $op, $state, $nonce );
442 130 ▶ unless ($authorization_request_uri) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($authorization_request_uri) 125 5 130
443 125 return PE_OIDC_AUTH_ERROR;
444 }
445  
446 5 $req->urldc($authorization_request_uri);
447  
448 5 $self->logger->debug( "Redirect user to " . $req->{urldc} );
449 5 $req->continue(1);
450 5 $req->steps( [] );
451  
452 5 return PE_OK;
453 }
454  
455 134 ▶sub isCallback {
Subroutine isCallback: called CC=1 SCAR=0.0
Pod undocumented
456 134 my ( $self, $req ) = @_;
457 134 return $req->param( $self->conf->{oidcRPCallbackGetParam} );
458 }
459  
460 1 ▶sub authenticate {
Subroutine authenticate: called CC=1 SCAR=0.0
Pod undocumented
461 1 return PE_OK;
462 }
463  
464 1 ▶sub setAuthSessionInfo {
Subroutine setAuthSessionInfo: called CC=9 SCAR=26.0
Pod undocumented
465 1 my ( $self, $req ) = @_;
466 1 my $op = $req->data->{_oidcOPCurrent};
467  
468 1 $req->{sessionInfo}->{authenticationLevel} = $self->conf->{oidcAuthnLevel};
469  
470 1 $req->{sessionInfo}->{_oidc_OP} = $op;
471 $req->{sessionInfo}->{_oidc_access_token} =
472 1 $req->data->{access_token};
473  
474 1 ▶ if ( $req->data->{refresh_token} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"refresh_token"}) 0 1 1
475 $req->{sessionInfo}->{_oidc_refresh_token} =
476 0 $req->data->{refresh_token};
477 }
478  
479 1 ▶ if ( $req->data->{access_token_eol} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"access_token_eol"}) 1 0 1
480 $req->{sessionInfo}->{_oidc_access_token_eol} =
481 1 $req->data->{access_token_eol};
482 }
483  
484 1 ▶ if ( $req->data->{op_sid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"op_sid"}) 1 0 1
485 1 $req->{sessionInfo}->{_oidc_sid} = $req->data->{op_sid};
486 }
487  
488 1 ▶ if ( $req->data->{id_token_sub} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"id_token_sub"}) 1 0 1
489 1 $req->{sessionInfo}->{_oidc_sub} = $req->data->{id_token_sub};
490 }
491  
492 1 ▶ if ( $req->data->{id_token_acr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"id_token_acr"}) 1 0 1
493 1 $req->{sessionInfo}->{_oidc_acr} = $req->data->{id_token_acr};
494 }
495  
496 1 ▶ if ( $req->data->{id_token_amr} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->data->{"id_token_amr"}) 0 1 1
497 0 ▶ if ( ref( $req->data->{id_token_amr} ) eq "ARRAY" ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $req->data->{'id_token_amr'} eq 'ARRAY') { } 0 0 0
498 $req->{sessionInfo}->{_oidc_amr} =
499 join $self->conf->{multiValuesSeparator},
500 0 sort @{ $req->data->{id_token_amr} };
501 }
502 else {
503 0 $req->{sessionInfo}->{_oidc_amr} = $req->data->{id_token_amr};
504 }
505 }
506  
507 # Keep ID Token in session
508 my $store_IDToken =
509 1 $self->opOptions->{$op}->{oidcOPMetaDataOptionsStoreIDToken};
510 1 ▶ if ($store_IDToken) {
Branch: 1 branch
BranchTrueFalseTotal
if ($store_IDToken) { } 0 1 1
511 0 $self->logger->debug("Store ID Token in session");
512 0 $req->{sessionInfo}->{_oidc_id_token} = $req->data->{id_token};
513 }
514 else {
515 1 $self->logger->debug("ID Token will not be stored in session");
516 }
517  
518 1 return PE_OK;
519 }
520  
521 0 ▶sub authLogout {
Subroutine authLogout: not called CC=5 SCAR=34.0
Pod undocumented
522 0 my ( $self, $req ) = @_;
523  
524 0 ▶ return PE_OK if $req->data->{oidcSkipLogout};
Branch: 1 branch
BranchTrueFalseTotal
if $req->data->{"oidcSkipLogout"} 0 0 0
525  
526 0 my $op = $req->{sessionInfo}->{_oidc_OP};
527  
528 # Find endession endpoint
529 my $endsession_endpoint =
530 0 $self->opMetadata->{$op}->{conf}->{end_session_endpoint};
531  
532 0 my $client_id = $self->opOptions->{$op}->{oidcOPMetaDataOptionsClientID};
533  
534 0 ▶ if ($endsession_endpoint) {
Branch: 1 branch
BranchTrueFalseTotal
if ($endsession_endpoint) { } 0 0 0
535 my $logout_url = $self->p->buildUrl( $req->portal, $self->path,
536 0 $self->conf->{oidcServiceMetaDataRpLogoutReturnURI} );
537  
538 0 my $state;
539 0 ▶ if ( my $next_url = ( $req->{issuerNextUrl} || $req->urldc ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $next_url = $req->{"issuerNextUrl"} || $req->urldc) 0 0 0
Condition0%0/3
$req->{'issuerNextUrl'} || $req->urldc
l!l&&r!l&&!r
000
MC/DC0%0/2
$req->{'issuerNextUrl'} || $req->urldc
$req->{'issuerNextUrl'} $req->urldc
Truth table0%0/3
A || B
A= $req->{'issuerNextUrl'}B= $req->urldc
ABresult
1X1
011
000
540 0 $state = $self->state_ott->createToken( { next_url => $next_url } );
541 }
542  
543 $req->urldc(
544 $self->buildLogoutRequest(
545 $endsession_endpoint, $req->{sessionInfo}->{_oidc_id_token},
546 0 $logout_url, $state, $client_id,
547 )
548 );
549  
550 0 $self->logger->debug(
551 "OpenID Connect logout to $op will be done on " . $req->urldc );
552 }
553 else {
554 0 $self->logger->debug("No end session endpoint found for $op");
555 }
556 0 return PE_OK;
557 }
558  
559 0 ▶sub rpLogoutReturn {
Subroutine rpLogoutReturn: not called CC=3 SCAR=24.8
Pod undocumented
560 0 my ( $self, $req ) = @_;
561  
562 0 my $url = $self->p->buildUrl( $req->portal, { logout => 1 } );
563  
564 0 ▶ if ( my $state = $req->param('state') ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $state = $req->param("state")) 0 0 0
565  
566 0 $state = $self->state_ott->getToken($state);
567 0 ▶ if ($state) {
Branch: 1 branch
BranchTrueFalseTotal
if ($state) { } 0 0 0
568 0 $url = $state->{next_url};
569 }
570 else {
571 0 $self->logger->warn("Post logout state is no longer valid");
572 }
573 }
574  
575 0 $req->urldc($url);
576 0 return $self->p->do( $req, [ [ returnPE => PE_REDIRECT ] ] );
577 }
578  
579 121 ▶sub getDisplayType {
Subroutine getDisplayType: called CC=1 SCAR=0.0
Pod undocumented
580 121 return "logo";
581 }
582  
583 1 ▶sub searchAndLogout {
Subroutine searchAndLogout: called CC=1 SCAR=0.0
Pod undocumented
584 1 my ( $self, $req ) = @_;
585 1 $self->userLogger->info(
586 'Front-channel logout request called without cookie');
587 1 $req->data->{frontLogoutSearch} = 1;
588 1 return $self->frontLogout($req);
589 }
590  
591 1 ▶sub frontLogout {
Subroutine frontLogout: called CC=12 SCAR=41.2
Pod undocumented
592 1 my ( $self, $req ) = @_;
593  
594 # No double disconnect
595 1 $req->data->{oidcSkipLogout} = 1;
596  
597 # Response should be displayed in an iframe
598 1 $req->frame(1);
599  
600 # TODO check iss and sid
601 1 my $iss = $req->param('iss');
602 1 my $sid = $req->param('sid');
603 1 my $badRequest = 0;
604 1 my $logName = 'OIDC FC Logout';
605  
606 1 my $img = $self->conf->{staticPrefix} . '/common/icons/ok.png';
607 1 my $frame = qq'<html><body><img src="$img"></body></html>';
608 1 my $response =
609 $self->p->sendTextResponse( $req, $frame, type => 'text/html' );
610  
611 # LLNG requires sid and iss
612 1 ▶ unless ( $iss and $sid ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($iss and $sid) { } 0 1 1
if (do { $req->data->{'frontLogoutSearch'} }) { } 0 0 0
Condition33%1/3
$iss and $sid
!ll&&!rl&&r
100
MC/DC0%0/2
$iss and $sid
$iss $sid
Truth table33%1/3
A and B
A= $issB= $sid
ABresult
0X0
100
111
613 1 $self->userLogger->error(
614 'OIDC Front-Channel-Logout called without sid and iss');
615 1 $badRequest++;
616 }
617 elsif ( $req->data->{frontLogoutSearch} ) {
618 0 my %store = %{ $self->conf->{globalStorageOptions} };
619 0 $store{backend} = $self->conf->{globalStorage};
620 0 my $oidcSessions =
621 Lemonldap::NG::Common::Apache::Session->searchOn( \%store,
622 '_oidc_sid', $sid );
623 0 my @sessionToDelete = keys %$oidcSessions;
624 0 foreach (@sessionToDelete) {
625  
626 # searchOn() returns sessions indexed by their storage ID, then
627 # it is required to set hashStore to 0
628 0 ▶ if ( my $as = $self->p->getApacheSession( $_, hashStore => 0, ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $as = $self->p->getApacheSession($_, "hashStore", 0)) 0 0 0
629 0 ▶ if ( $self->p->_deleteSession( $req, $as, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->p->_deleteSession($req, $as, 1)) { } 0 0 0
630 0 $self->logger->debug(
631 "$logName: session $_ deleted from global storage");
632 }
633 else {
634 0 $self->logger->error(
635 "$logName: unable to delete session $_");
636 0 $self->logger->error( $as->error );
637 }
638 }
639 }
640 0 return $response;
641 }
642 else {
643 0 ▶ unless ( $req->userData->{_oidc_sid} and $req->userData->{_oidc_OP} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($req->userData->{'_oidc_sid'} and $req->userData->{'_oidc_OP'}) { } 0 0 0
Condition0%0/3
$req->userData->{"_oidc_sid"} and $req->userData->{"_oidc_OP"}
!ll&&!rl&&r
000
MC/DC0%0/2
$req->userData->{"_oidc_sid"} and $req->userData->{"_oidc_OP"}
$req->userData->{"_oidc_sid"} $req->userData->{"_oidc_OP"}
Truth table0%0/3
A and B
A= $req->userData->{"_oidc_sid"}B= $req->userData->{"_oidc_OP"}
ABresult
0X0
100
111
644 0 $self->logger->error(
645 "$logName: key _oidc_sid not stored in session");
646 0 $badRequest++;
647 }
648 else {
649 0 ▶ if ( $sid ne $req->userData->{_oidc_sid} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sid ne $req->userData->{"_oidc_sid"}) 0 0 0
650 0 $self->userLogger->error(
651 'OIDC Front-Channel-Logout: sid mismatch');
652 0 $badRequest++;
653 }
654 }
655 }
656 1 ▶ if ($badRequest) {
Branch: 1 branch
BranchTrueFalseTotal
if ($badRequest) 1 0 1
657 1 return $self->p->sendError( $req, 'Bad OIDC Logout Request', 200 );
658 }
659  
660 # Ignore beforeLogout errors
661 0 $req->steps( $self->p->beforeLogout );
662 0 my $res = $self->p->process($req);
663  
664 0 $req->data->{_continueLogout} = 1;
665 0 $req->response($response);
666 0 ▶ return $self->p->do(
Branch: 1 branch
BranchTrueFalseTotal
$res ? : 0 0 0
667 $req,
668 [
669 'authLogout', 'deleteSession',
670 [ returnPE => ( $res ? $res : PE_SENDRESPONSE ) ]
671 ]
672 );
673 }
674  
675 # Implements https://openid.net/specs/openid-connect-backchannel-1_0.html
676 1 ▶sub backLogout {
Subroutine backLogout: called CC=28 SCAR=42.3
Pod undocumented
677 1 my ( $self, $req ) = @_;
678 1 my $logName = 'OIDC BC Logout';
679  
680 # REQUIRED CHECKS
681  
682 # Back channel requires POST
683 1 ▶ return $self->p->sendError( $req, 'Only POST allowed', 400 )
Branch: 1 branch
BranchTrueFalseTotal
if $req->method ne "POST" 0 1 1
684 if $req->method ne 'POST';
685  
686 # Back channel requires logout_token
687 1 my $content = $req->body_parameters;
688 return $self->p->sendError( $req, 'logout_token not found', 400 )
689 1 ▶ unless $content and $content->{logout_token};
Branch: 1 branch
BranchTrueFalseTotal
unless $content and $content->{"logout_token"} 0 1 1
Condition33%1/3
$content and $content->{"logout_token"}
!ll&&!rl&&r
001
MC/DC0%0/2
$content and $content->{"logout_token"}
$content $content->{"logout_token"}
Truth table33%1/3
A and B
A= $contentB= $content->{"logout_token"}
ABresult
0X0
100
111
690  
691 # Decode token
692 1 my $logoutToken = $self->decryptJwt( $content->{logout_token} );
693 1 ▶ my $payload = getJWTPayload($logoutToken)
Branch: 1 branch
BranchTrueFalseTotal
my $payload = getJWTPayload($logoutToken) or return $self->p->sendError($req, "Could not decode logout token", 400) 1 0 1
694 or
695 return $self->p->sendError( $req, 'Could not decode logout token', 400 );
696  
697 # TODO: validate "alg" header => prohibit "none" value
698  
699 # Required fields
700 1 foreach (qw(iss aud iat exp jti events)) {
701 return $self->p->sendError( $req, "Missing $_", 400 )
702 6 ▶ unless $payload->{$_};
Branch: 1 branch
BranchTrueFalseTotal
unless $payload->{$_} 0 6 6
703 }
704 return $self->p->sendError( $req, 'Missing sub/sid', 400 )
705 1 ▶ unless $payload->{sub} or $payload->{sid};
Branch: 1 branch
BranchTrueFalseTotal
unless $payload->{"sub"} or $payload->{"sid"} 0 1 1
Condition33%1/3
$payload->{"sub"} or $payload->{"sid"}
l!l&&r!l&&!r
100
MC/DC0%0/2
$payload->{"sub"} or $payload->{"sid"}
$payload->{"sub"} $payload->{"sid"}
Truth table33%1/3
A or B
A= $payload->{"sub"}B= $payload->{"sid"}
ABresult
1X1
011
000
706  
707 # Get iss and found related OP
708 1 my $op;
709 1 foreach ( keys %{ $self->opMetadata } ) {
710 1 ▶ if ( $self->opMetadata->{$_}->{conf}->{issuer} eq $payload->{iss} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->opMetadata->{$_}{"conf"}{"issuer"} eq $payload->{"iss"}) 1 0 1
711 1 $op = $_;
712 1 last;
713 }
714 }
715 1 ▶ return $self->p->sendError( $req, 'Issuer not found', 400 ) unless $op;
Branch: 1 branch
BranchTrueFalseTotal
unless $op 0 1 1
716  
717 # Verify signature
718 1 ▶ return $self->p->sendError( $req, 'Bad signature', 400 )
Branch: 1 branch
BranchTrueFalseTotal
unless $self->decodeJWT($logoutToken, $op) 0 1 1
719 unless $self->decodeJWT( $logoutToken, $op );
720  
721 # Verify audience
722 return $self->p->error( $req, 'Bad aud', 400 )
723 1 ▶ unless ref $payload->{aud} eq 'ARRAY';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload->{"aud"} eq "ARRAY" 0 1 1
724 return $self->p->error( $req, 'Client ID not found in audience array', 400 )
725 unless
726 1 grep { $_ eq $self->opOptions->{$op}->{oidcOPMetaDataOptionsClientID} }
727 1 ▶ @{ $payload->{aud} };
Branch: 1 branch
BranchTrueFalseTotal
unless grep {$_ eq $self->opOptions->{$op}{"oidcOPMetaDataOptionsClientID"};} @{$$payload{"aud"};} 0 1 1
728  
729 # Verify iat
730 return $self->p->error( $req, 'Token too old', 400 )
731 unless $payload->{iat} +
732 1 ▶ ( $self->opOptions->{$op}->{oidcOPMetaDataOptionsIDTokenMaxAge} // 30 ) >
Branch: 1 branch
BranchTrueFalseTotal
unless $payload->{"iat"} + ($self->opOptions->{$op}{"oidcOPMetaDataOptionsIDTokenMaxAge"} // 30) > &CORE::GLOBAL::time() 0 1 1
Condition50%1/2
$self->opOptions->{$op}{"oidcOPMetaDataOptionsIDTokenMaxAge"} // 30
l!l
01
MC/DC0%0/1
$self->opOptions->{$op}{"oidcOPMetaDataOptionsIDTokenMaxAge"} // 30
$self->opOptions->{$op}{"oidcOPMetaDataOptionsIDTokenMaxAge"}
Truth table50%1/2
A
A= $self->opOptions->{$op}{"oidcOPMetaDataOptionsIDTokenMaxAge"}
Aresult
11
00
733 time;
734  
735 # Verify events
736 return $self->p->error( $req, 'Bad events', 400 )
737 unless ref $payload->{events} eq 'HASH'
738 and $payload->{events}->{ $self->BACKCHANNEL_EVENTSKEY() }
739 1 ▶ and ref $payload->{events}->{ $self->BACKCHANNEL_EVENTSKEY() } eq 'HASH';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $payload->{"events"} eq "HASH" and $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} and ref $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} eq "HASH" 0 1 1
Condition33%2/6
ref $payload->{"events"} eq "HASH" and $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} and ref $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} eq "HASH"
!ll&&!rl&&r
001
ref $payload->{"events"} eq "HASH" and $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY}
!ll&&!rl&&r
001
MC/DC0%0/3
ref $payload->{"events"} eq "HASH" and $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} and ref $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} eq "HASH"
ref $payload->{"events"} eq "HASH" $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} ref $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} eq "HASH"
Truth table25%1/4
A and B and C
A= ref $payload->{"events"} eq "HASH"B= $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY}C= ref $payload->{"events"}{$self->BACKCHANNEL_EVENTSKEY} eq "HASH"
ABCresult
0XX0
10X0
1100
1111
740  
741 # Verify nonce
742 1 ▶ return $self->p->error( $req, 'Bad request', 400 ) if $payload->{nonce};
Branch: 1 branch
BranchTrueFalseTotal
if $payload->{"nonce"} 0 1 1
743  
744 # Now request is valid, even if session isn't found, response will be 200
745  
746 # Find session
747 1 my $uid = $payload->{sub};
748 1 my $sid = $payload->{sid};
749 1 my %store = %{ $self->conf->{globalStorageOptions} };
750 1 $store{backend} = $self->conf->{globalStorage};
751 1 my @userSessions;
752 1 ▶ if ($sid) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sid) { } 1 0 1
753 1 my $oidcSessions =
754 Lemonldap::NG::Common::Apache::Session->searchOn( \%store,
755 '_oidc_sid', $sid );
756 1 @userSessions = keys %$oidcSessions;
757 }
758 else {
759 0 my $oidcSessions =
760 Lemonldap::NG::Common::Apache::Session->searchOn( \%store,
761 '_oidc_sub', $uid );
762 @userSessions =
763 grep {
764 0 $oidcSessions->{$_}->{_oidc_OP}
765 0 ▶ and $oidcSessions->{$_}->{_oidc_OP} eq $op;
Condition0%0/3
$oidcSessions->{$_}{'_oidc_OP'} && $oidcSessions->{$_}{'_oidc_OP'} eq $op
!ll&&!rl&&r
000
MC/DC0%0/2
$oidcSessions->{$_}{'_oidc_OP'} && $oidcSessions->{$_}{'_oidc_OP'} eq $op
$oidcSessions->{$_}{'_oidc_OP'} $oidcSessions->{$_}{'_oidc_OP'} eq $op
Truth table0%0/3
A && B
A= $oidcSessions->{$_}{'_oidc_OP'}B= $oidcSessions->{$_}{'_oidc_OP'} eq $op
ABresult
0X0
100
111
766 } keys %$oidcSessions;
767 }
768 1 ▶ if (@userSessions) {
Branch: 1 branch
BranchTrueFalseTotal
if (@userSessions) { } 1 0 1
769 1 ▶ if ($#userSessions) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#userSessions) 0 1 1
770 0 $self->logger->warn(
771 "$logName: more than one link found between $uid and $op, cleanong all"
772 );
773 }
774 1 foreach (@userSessions) {
775  
776 # searchOn() returns sessions indexed by their storage ID, then
777 # it is required to set hashStore to 0
778 1 ▶ if ( my $as = $self->p->getApacheSession( $_, hashStore => 0 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $as = $self->p->getApacheSession($_, 'hashStore', 0)) { } 1 0 1
779 1 ▶ if ( $self->p->_deleteSession( $req, $as, 1 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->p->_deleteSession($req, $as, 1)) { } 1 0 1
780 1 $self->logger->debug(
781 "$logName: session $_ deleted from global storage");
782 }
783 else {
784 0 $self->logger->error(
785 "$logName: unable to delete session $_");
786 0 $self->logger->error( $as->error );
787 }
788 }
789 else {
790 0 $self->logger->info(
791 "$logName: session $_ for user $uid already deleted");
792 }
793 }
794 }
795 else {
796 0 $self->logger->warn("$logName: no session found for $uid");
797 }
798  
799 1 return $self->p->sendBinaryResponse( $req, '' );
800 }
801  
802 46 1;
« blib/lib/Lemonldap/NG/Portal/Plugins/OIDC/PasswordGrant.pm ↑ Summary blib/lib/Lemonldap/NG/Portal/Plugins/RESTServer.pm »