diff --git a/src/Service/UsersService.php b/src/Service/UsersService.php index 4547fe8..eb28c8b 100644 --- a/src/Service/UsersService.php +++ b/src/Service/UsersService.php @@ -54,6 +54,11 @@ public function delete(string $realm, string $userId): bool return $this->executeCommand(HttpMethodEnum::DELETE, 'admin/realms/'.$realm.'/users/'.$userId); } + public function logout(string $realm, string $userId): bool + { + return $this->executeCommand(HttpMethodEnum::POST, 'admin/realms/'.$realm.'/users/'.$userId.'/logout'); + } + /** * @return UserSessionCollection|null */ diff --git a/tests/Service/UsersServiceTest.php b/tests/Service/UsersServiceTest.php index 7899bb6..c013a6c 100644 --- a/tests/Service/UsersServiceTest.php +++ b/tests/Service/UsersServiceTest.php @@ -345,6 +345,37 @@ public function testDelete(): void $this->assertTrue($result); } + public function testLogout(): void + { + // given + $realm = 'test-realm'; + $userId = 'user1'; + $responseBody = ''; + $stream = $this->createMock(StreamInterface::class); + $stream->method('getContents')->willReturn($responseBody); + + $response = m::mock(ResponseInterface::class); + $response->shouldReceive('getStatusCode')->andReturn(204); + $response->shouldReceive('getBody')->andReturn($stream); + + $this->httpClient + ->shouldReceive('request') + ->with( + 'POST', + 'admin/realms/'.$realm.'/users/'.$userId.'/logout', + m::type('array') + ) + ->andReturn($response); + + $this->logger->shouldReceive('info')->once(); + + // when + $result = $this->usersService->logout($realm, $userId); + + // then + $this->assertTrue($result); + } + public function testSessions(): void { // given