diff --git a/README.md b/README.md index 925912a..618728b 100644 --- a/README.md +++ b/README.md @@ -37,6 +37,7 @@ $CONFIG = [ 'client-id' => 'fc9b5c78-ec73-47bf-befc-59d4fe780f6f', 'client-secret' => 'e3e5b04a-3c3c-4f4d-b16c-2a6e9fdd3cd1', 'loginButtonName' => 'OpenId Connect', + 'post_logout_redirect_uri' => '...', 'provider-params' => [ 'authorization_endpoint' => '...', 'token_endpoint' => '...', diff --git a/lib/SessionVerifier.php b/lib/SessionVerifier.php index a427a8e..814e895 100644 --- a/lib/SessionVerifier.php +++ b/lib/SessionVerifier.php @@ -145,7 +145,9 @@ public function afterLogout($accessToken, $idToken): void { $this->session->remove('oca.openid-connect.refresh-token'); $this->session->remove('oca.openid-connect.id-token'); $this->logger->debug('OIDC Logout: ending session ' . $accessToken . ' id: ' . $idToken); - $this->client->signOut($idToken, null); + $openIdConfig = $this->client->getOpenIdConfig(); + $redirectUri = $openIdConfig['post_logout_redirect_uri'] ?? null; + $this->client->signOut($idToken, $redirectUri); } catch (OpenIDConnectClientException $ex) { $this->logger->logException($ex); } diff --git a/tests/unit/SessionVerifierTest.php b/tests/unit/SessionVerifierTest.php index 9e64742..f264efb 100644 --- a/tests/unit/SessionVerifierTest.php +++ b/tests/unit/SessionVerifierTest.php @@ -22,23 +22,15 @@ namespace OCA\OpenIdConnect\Tests\Unit; -use http\Exception; use OC\HintException; use OCA\OpenIdConnect\Client; -use OCA\OpenIdConnect\EventHandler; use OCA\OpenIdConnect\Logger; use OCA\OpenIdConnect\SessionVerifier; use OCP\ICache; use OCP\ICacheFactory; -use OCP\IRequest; use OCP\ISession; -use OCP\IUser; use OCP\IUserSession; -use OCP\SabrePluginEvent; use PHPUnit\Framework\MockObject\MockObject; -use Sabre\DAV\Auth\Plugin; -use Sabre\DAV\Server; -use Symfony\Component\EventDispatcher\Event; use Symfony\Component\EventDispatcher\EventDispatcherInterface; use Test\TestCase; @@ -209,4 +201,27 @@ public function testValidFreshAccessTokenWithIntrospection(): void { $this->sessionVerifier->verifySession(); } + + public function provideOpenIdConfig() { + return [ + [null, null], + [[], null], + [['post_logout_redirect_uri' => null], null], + [['post_logout_redirect_uri' => 'http://localhost'], 'http://localhost'], + ]; + } + + /** + * @dataProvider provideOpenIdConfig + * @param string[]|null $openIdConfig + * @param string $expectedLogoutRedirectUri + */ + public function testLogoutRedirect($openIdConfig, $expectedLogoutRedirectUri) { + $this->client->method('getOpenIdConfig') + ->willReturn($openIdConfig); + $this->client->expects($this->once()) + ->method('signOut') + ->with($this->anything(), $expectedLogoutRedirectUri); + $this->sessionVerifier->afterLogout('dummy', 'dummy'); + } }