Skip to content

Commit 5a66aa6

Browse files
author
Greg Bowler
committed
Implement remote logout for #7
1 parent 3a0a3cf commit 5a66aa6

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

src/Authenticator.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33

44
use Authwave\ProviderUri\AdminUri;
55
use Authwave\ProviderUri\AuthUri;
6+
use Authwave\ProviderUri\LogoutUri;
67
use Gt\Http\Uri;
78
use Gt\Session\SessionContainer;
89
use Psr\Http\Message\UriInterface;
@@ -79,6 +80,7 @@ public function login(Token $token = null):void {
7980
public function logout():void {
8081
// TODO: Should the logout redirect the user agent to the redirectPath?
8182
$this->session->remove(self::SESSION_KEY);
83+
$this->redirectHandler->redirect($this->getLogoutUri());
8284
}
8385

8486
public function getUuid():string {
@@ -109,6 +111,10 @@ public function getAdminUri(
109111
);
110112
}
111113

114+
public function getLogoutUri():UriInterface {
115+
return new LogoutUri($this->authwaveHost);
116+
}
117+
112118
private function completeAuth():void {
113119
$responseCipher = $this->getResponseCipher();
114120

src/ProviderUri/LogoutUri.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
namespace Authwave\ProviderUri;
3+
4+
class LogoutUri extends AbstractProviderUri {
5+
const PATH_LOGOUT = "/logout";
6+
7+
public function __construct(string $baseRemoteUri) {
8+
$baseRemoteUri = $this->normaliseBaseUri($baseRemoteUri);
9+
parent::__construct($baseRemoteUri);
10+
$this->path = self::PATH_LOGOUT;
11+
}
12+
}

test/phpunit/AuthenticatorTest.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,10 +72,15 @@ public function testLogoutClearsSession() {
7272
Authenticator::SESSION_KEY => $sessionData
7373
];
7474

75+
$redirectHandler = self::createMock(RedirectHandler::class);
76+
7577
$sut = new Authenticator(
7678
"example-app-id",
7779
"test-key",
78-
"/"
80+
"/",
81+
AuthUri::DEFAULT_BASE_REMOTE_URI,
82+
null,
83+
$redirectHandler
7984
);
8085
$sut->logout();
8186
self::assertEmpty($_SESSION);

0 commit comments

Comments
 (0)