Skip to content

Commit eb3745c

Browse files
author
Greg Bowler
committed
Use serialised stdClass object to represent user data
1 parent 5f56e26 commit eb3745c

File tree

6 files changed

+21
-18
lines changed

6 files changed

+21
-18
lines changed

src/Authenticator.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,10 @@ public function logout():void {
8080
$this->redirectHandler->redirect($this->getLogoutUri());
8181
}
8282

83+
public function adminLogin():void {
84+
// TODO: Implement!
85+
}
86+
8387
public function getUuid():string {
8488
$userData = $this->sessionData->getUserData();
8589
return $userData->getUuid();
@@ -99,7 +103,7 @@ public function getAuthUri(Token $token):AuthUri {
99103
}
100104

101105
public function getAdminUri(
102-
string $path = AdminUri::PATH_ACCOUNT
106+
string $path = AdminUri::PATH_ADMIN
103107
):UriInterface {
104108
return new AdminUri(
105109
$this->authwaveHost,

src/ProviderUri/AdminUri.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
namespace Authwave\ProviderUri;
33

44
class AdminUri extends AbstractProviderUri {
5-
const PATH_ACCOUNT = "/account";
5+
const PATH_ADMIN = "/admin";
66
const PATH_SETTINGS = "/settings";
77

88
public function __construct(

src/Token.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@ public function decryptResponseCipher(string $cipher):UserData {
5555
throw new ResponseCipherDecryptionException();
5656
}
5757

58-
$data = unserialize(
58+
$data = @unserialize(
5959
$decrypted
6060
);
6161
if($data === false) {
6262
throw new InvalidUserDataSerializationException();
6363
}
6464

65-
return new UserData($data["uuid"], $data["email"]);
65+
return new UserData($data->{"uuid"}, $data->{"email"});
6666
}
6767
}

test/phpunit/AuthenticatorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -355,7 +355,7 @@ public function testGetAdminUri() {
355355
);
356356
$sut = $auth->getAdminUri();
357357
self::assertEquals(
358-
AdminUri::PATH_ACCOUNT,
358+
AdminUri::PATH_ADMIN,
359359
$sut->getPath()
360360
);
361361
}

test/phpunit/ProviderUri/AdminUriTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ class AdminUriTest extends TestCase {
88
public function testPathAccount() {
99
$sut = new AdminUri(
1010
"example.com",
11-
AdminUri::PATH_ACCOUNT
11+
AdminUri::PATH_ADMIN
1212
);
1313
self::assertEquals(
14-
AdminUri::PATH_ACCOUNT,
14+
AdminUri::PATH_ADMIN,
1515
$sut->getPath()
1616
);
1717
}

test/phpunit/TokenTest.php

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,8 @@ public function testDecryptResponseCipherBadJson() {
6565
}
6666

6767
public function testDecryptResponseCipher() {
68-
$key = uniqid("test-key-");
68+
$clientKey = uniqid("test-key-");
69+
// SecretIv is stored in the client application's session only.
6970
$secretIv = self::createMock(InitVector::class);
7071
$secretIv->method("getBytes")
7172
->willReturn(str_repeat("0", 16));
@@ -75,22 +76,20 @@ public function testDecryptResponseCipher() {
7576

7677
$uuid = "aabb-ccdd-eeff";
7778
$email = "user@example.com";
78-
$json = <<<JSON
79-
{
80-
"uuid": "$uuid",
81-
"email": "$email"
82-
}
83-
JSON;
79+
$serialized = serialize((object)[
80+
"uuid" => $uuid,
81+
"email" => $email,
82+
]);
8483

8584
$cipher = openssl_encrypt(
86-
$json,
85+
$serialized,
8786
Token::ENCRYPTION_METHOD,
88-
implode("|", [$key, $secretIv->getBytes()]),
87+
$clientKey,
8988
0,
90-
$iv->getBytes()
89+
$secretIv->getBytes()
9190
);
9291
$cipher = base64_encode($cipher);
93-
$sut = new Token($key, $secretIv, $iv);
92+
$sut = new Token($clientKey, $secretIv, $iv);
9493
$userData = $sut->decryptResponseCipher($cipher);
9594
self::assertInstanceOf(UserData::class, $userData);
9695
self::assertEquals($uuid, $userData->getUuid());

0 commit comments

Comments
 (0)