Skip to content

Commit 8c738ae

Browse files
committed
Added sessionindex to SAML2 single logout request to idp
related to #3936
1 parent f64ce71 commit 8c738ae

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

app/Auth/Access/Saml2Service.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ public function logout(User $user): array
6767
$returnRoute,
6868
[],
6969
$user->email,
70-
null,
70+
session()->get('saml2_session_index'),
7171
true,
7272
Constants::NAMEID_EMAIL_ADDRESS
7373
);
@@ -118,6 +118,7 @@ public function processAcsResponse(?string $requestId, string $samlResponse): ?U
118118

119119
$attrs = $toolkit->getAttributes();
120120
$id = $toolkit->getNameId();
121+
session()->put('saml2_session_index', $toolkit->getSessionIndex());
121122

122123
return $this->processLoginCallback($id, $attrs);
123124
}

tests/Auth/Saml2Test.php

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,9 @@ public function test_logout_sls_flow()
193193
$req = $this->post('/saml2/logout');
194194
$redirect = $req->headers->get('location');
195195
$this->assertStringStartsWith('http://saml.local/saml2/idp/SingleLogoutService.php', $redirect);
196+
$sloData = $this->parseSamlDataFromUrl($redirect, 'SAMLRequest');
197+
$this->assertStringContainsString('<samlp:SessionIndex>_4fe7c0d1572d64b27f930aa6f236a6f42e930901cc</samlp:SessionIndex>', $sloData);
198+
196199
$this->withGet(['SAMLResponse' => $this->sloResponseData], $handleLogoutResponse);
197200
}
198201

@@ -379,11 +382,16 @@ protected function getAuthnRequest(): string
379382
{
380383
$req = $this->post('/saml2/login');
381384
$location = $req->headers->get('Location');
382-
$query = explode('?', $location)[1];
385+
return $this->parseSamlDataFromUrl($location, 'SAMLRequest');
386+
}
387+
388+
protected function parseSamlDataFromUrl(string $url, string $paramName): string
389+
{
390+
$query = explode('?', $url)[1];
383391
$params = [];
384392
parse_str($query, $params);
385393

386-
return gzinflate(base64_decode($params['SAMLRequest']));
394+
return gzinflate(base64_decode($params[$paramName]));
387395
}
388396

389397
protected function withGet(array $options, callable $callback)

0 commit comments

Comments
 (0)