diff --git a/src/Authenticator.php b/src/Authenticator.php index ce5e71c..bfaeb69 100644 --- a/src/Authenticator.php +++ b/src/Authenticator.php @@ -3,6 +3,7 @@ use Authwave\ProviderUri\AdminUri; use Authwave\ProviderUri\AuthUri; +use Authwave\ProviderUri\LogoutUri; use Gt\Http\Uri; use Gt\Session\SessionContainer; use Psr\Http\Message\UriInterface; @@ -79,6 +80,7 @@ public function login(Token $token = null):void { public function logout():void { // TODO: Should the logout redirect the user agent to the redirectPath? $this->session->remove(self::SESSION_KEY); + $this->redirectHandler->redirect($this->getLogoutUri()); } public function getUuid():string { @@ -109,6 +111,10 @@ public function getAdminUri( ); } + public function getLogoutUri():UriInterface { + return new LogoutUri($this->authwaveHost); + } + private function completeAuth():void { $responseCipher = $this->getResponseCipher(); diff --git a/src/ProviderUri/LogoutUri.php b/src/ProviderUri/LogoutUri.php new file mode 100644 index 0000000..debff7a --- /dev/null +++ b/src/ProviderUri/LogoutUri.php @@ -0,0 +1,12 @@ +normaliseBaseUri($baseRemoteUri); + parent::__construct($baseRemoteUri); + $this->path = self::PATH_LOGOUT; + } +} \ No newline at end of file diff --git a/test/phpunit/AuthenticatorTest.php b/test/phpunit/AuthenticatorTest.php index d20ad70..e0a6f19 100644 --- a/test/phpunit/AuthenticatorTest.php +++ b/test/phpunit/AuthenticatorTest.php @@ -6,6 +6,7 @@ use Authwave\NotLoggedInException; use Authwave\ProviderUri\AdminUri; use Authwave\ProviderUri\AuthUri; +use Authwave\ProviderUri\LogoutUri; use Authwave\RedirectHandler; use Authwave\SessionData; use Authwave\SessionNotStartedException; @@ -72,10 +73,21 @@ public function testLogoutClearsSession() { Authenticator::SESSION_KEY => $sessionData ]; + $redirectHandler = self::createMock(RedirectHandler::class); + $redirectHandler->expects(self::once()) + ->method("redirect") + ->with(self::callback(fn(UriInterface $uri) => + $uri->getHost() === AuthUri::DEFAULT_BASE_REMOTE_URI + && $uri->getPath() === LogoutUri::PATH_LOGOUT + )); + $sut = new Authenticator( "example-app-id", "test-key", - "/" + "/", + AuthUri::DEFAULT_BASE_REMOTE_URI, + null, + $redirectHandler ); $sut->logout(); self::assertEmpty($_SESSION);