diff --git a/src/Authenticator.php b/src/Authenticator.php index 901c821..a6140bc 100644 --- a/src/Authenticator.php +++ b/src/Authenticator.php @@ -9,6 +9,7 @@ class Authenticator { private string $clientKey; private string $clientSecret; private string $redirectPath; + private SessionContainer $session; private SessionData $sessionData; public function __construct( @@ -28,6 +29,7 @@ public function __construct( $this->clientKey = $clientKey; $this->clientSecret = $clientSecret; $this->redirectPath = $redirectPath; + $this->session = $session; $this->sessionData = $session->get(self::SESSION_KEY); if($this->authInProgress()) { @@ -48,6 +50,10 @@ public function isLoggedIn():bool { return isset($userData); } + public function logout():void { + $this->session->remove(self::SESSION_KEY); + } + private function authInProgress():bool { return false; } diff --git a/test/phpunit/AuthenticatorTest.php b/test/phpunit/AuthenticatorTest.php index 7a74458..14c8933 100644 --- a/test/phpunit/AuthenticatorTest.php +++ b/test/phpunit/AuthenticatorTest.php @@ -59,4 +59,19 @@ public function testIsLoggedInTrueWhenSessionDataSet() { ); self::assertTrue($sut->isLoggedIn()); } + + public function testLogoutClearsSession() { + $sessionData = self::createMock(SessionData::class); + $_SESSION = [ + Authenticator::SESSION_KEY => $sessionData + ]; + + $sut = new Authenticator( + "test-key", + "test-secret", + "/" + ); + $sut->logout(); + self::assertEmpty($_SESSION); + } } \ No newline at end of file