Skip to content

Commit cec4846

Browse files
author
Greg Bowler
committed
Remove custom admin uri
1 parent 28676c4 commit cec4846

File tree

3 files changed

+13
-65
lines changed

3 files changed

+13
-65
lines changed

src/Authenticator.php

Lines changed: 10 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -38,12 +38,14 @@ public function __construct(
3838
// need to store it to the current session at all?
3939
$session->set(self::SESSION_KEY, new SessionData());
4040
}
41+
/** @var SessionData $sessionData*/
42+
$sessionData = $session->get(self::SESSION_KEY);
4143

4244
$this->clientKey = $clientKey;
4345
$this->currentUriPath = $currentUriPath;
4446
$this->authwaveHost = $authwaveHost;
4547
$this->session = $session;
46-
$this->sessionData = $session->get(self::SESSION_KEY);
48+
$this->sessionData = $sessionData;
4749
$this->redirectHandler = $redirectHandler ?? new RedirectHandler();
4850

4951
$this->completeAuth();
@@ -62,10 +64,7 @@ public function isLoggedIn():bool {
6264
return isset($userData);
6365
}
6466

65-
public function login(
66-
Token $token = null,
67-
string $loginType = self::LOGIN_TYPE_DEFAULT
68-
):void {
67+
public function login(Token $token = null):void {
6968
if($this->isLoggedIn()) {
7069
return;
7170
}
@@ -77,18 +76,15 @@ public function login(
7776
$this->sessionData = new SessionData($token);
7877
$this->session->set(self::SESSION_KEY, $this->sessionData);
7978

80-
$this->redirectHandler->redirect(
81-
$this->getAuthUri($token, $loginType)
82-
);
79+
$this->redirectHandler->redirect($this->getAuthUri($token));
8380
}
8481

85-
public function logout():void {
86-
// TODO: Should the logout redirect the user agent to the redirectPath?
82+
public function logout(string $redirectToPath = "/"):void {
8783
$this->session->remove(self::SESSION_KEY);
88-
}
8984

90-
public function adminLogin(Token $token = null):void {
91-
$this->login($token, self::LOGIN_TYPE_ADMIN);
85+
$uri = (new Uri())
86+
->withPath($redirectToPath);
87+
$this->redirectHandler->redirect($uri);
9288
}
9389

9490
public function getUuid():string {
@@ -106,17 +102,7 @@ public function getField(string $name):?string {
106102
return $userData->getField($name);
107103
}
108104

109-
public function getAuthUri(
110-
Token $token,
111-
string $loginType = self::LOGIN_TYPE_DEFAULT
112-
):AbstractProviderUri {
113-
if($loginType === self::LOGIN_TYPE_ADMIN) {
114-
return new AdminUri(
115-
$this->currentUriPath,
116-
$this->authwaveHost
117-
);
118-
}
119-
105+
public function getAuthUri(Token $token):AbstractProviderUri {
120106
return new AuthUri(
121107
$token,
122108
$this->currentUriPath,

test/phpunit/AuthenticatorTest.php

Lines changed: 1 addition & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -332,22 +332,7 @@ public function testGetAdminUri() {
332332
);
333333
$sut = $auth->getAdminUri();
334334
self::assertEquals(
335-
AdminUri::PATH_ADMIN,
336-
$sut->getPath()
337-
);
338-
}
339-
340-
public function testGetAdminUriCustom() {
341-
$_SESSION = [];
342-
$auth = new Authenticator(
343-
"test-key",
344-
"/example-path",
345-
AuthUri::DEFAULT_BASE_REMOTE_URI
346-
);
347-
$path = "/custom-path";
348-
$sut = $auth->getAdminUri($path);
349-
self::assertEquals(
350-
$path,
335+
"/admin",
351336
$sut->getPath()
352337
);
353338
}

test/phpunit/ProviderUri/AdminUriTest.php

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,33 +6,10 @@
66

77
class AdminUriTest extends TestCase {
88
public function testPathAccount() {
9-
$sut = new AdminUri(
10-
"example.com",
11-
AdminUri::PATH_ADMIN
12-
);
13-
self::assertEquals(
14-
AdminUri::PATH_ADMIN,
15-
$sut->getPath()
16-
);
17-
}
18-
19-
public function testPathSettings() {
20-
$sut = new AdminUri(
21-
"example.com",
22-
AdminUri::PATH_SETTINGS
23-
);
9+
$sut = new AdminUri("example.com");
2410
self::assertEquals(
25-
AdminUri::PATH_SETTINGS,
11+
"/admin",
2612
$sut->getPath()
2713
);
2814
}
29-
30-
public function testPathCustom() {
31-
$path = "/custom/path";
32-
$sut = new AdminUri(
33-
"example.com",
34-
$path
35-
);
36-
self::assertEquals($path, $sut->getPath());
37-
}
3815
}

0 commit comments

Comments
 (0)