2016-08-21 04:51:39 +05:30
|
|
|
<?php
|
2019-12-04 23:40:15 +05:30
|
|
|
declare(strict_types=1);
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
namespace api\modules\authserver\models;
|
|
|
|
|
2019-12-04 23:40:15 +05:30
|
|
|
use common\models\Account;
|
2016-08-21 04:51:39 +05:30
|
|
|
|
2021-03-06 15:07:58 +05:30
|
|
|
final class AuthenticateData {
|
2016-08-21 04:51:39 +05:30
|
|
|
|
2021-03-06 15:07:58 +05:30
|
|
|
private Account $account;
|
2016-08-21 04:51:39 +05:30
|
|
|
|
2021-03-06 15:07:58 +05:30
|
|
|
private string $accessToken;
|
2016-08-21 04:51:39 +05:30
|
|
|
|
2021-03-06 15:07:58 +05:30
|
|
|
private string $clientToken;
|
2019-12-04 23:40:15 +05:30
|
|
|
|
2021-03-06 15:07:58 +05:30
|
|
|
private bool $requestUser;
|
|
|
|
|
|
|
|
public function __construct(Account $account, string $accessToken, string $clientToken, bool $requestUser) {
|
2019-12-04 23:40:15 +05:30
|
|
|
$this->account = $account;
|
|
|
|
$this->accessToken = $accessToken;
|
|
|
|
$this->clientToken = $clientToken;
|
2021-03-06 15:07:58 +05:30
|
|
|
$this->requestUser = $requestUser;
|
2016-08-21 04:51:39 +05:30
|
|
|
}
|
|
|
|
|
2018-04-18 02:17:25 +05:30
|
|
|
public function getResponseData(bool $includeAvailableProfiles = false): array {
|
2021-03-06 15:07:58 +05:30
|
|
|
$uuid = str_replace('-', '', $this->account->uuid);
|
2016-08-21 04:51:39 +05:30
|
|
|
$result = [
|
2019-12-04 23:40:15 +05:30
|
|
|
'accessToken' => $this->accessToken,
|
|
|
|
'clientToken' => $this->clientToken,
|
2016-08-21 04:51:39 +05:30
|
|
|
'selectedProfile' => [
|
2021-03-06 15:07:58 +05:30
|
|
|
// Might contain a lot more fields, but even Mojang returns only those:
|
|
|
|
'id' => $uuid,
|
2019-12-04 23:40:15 +05:30
|
|
|
'name' => $this->account->username,
|
2016-08-21 04:51:39 +05:30
|
|
|
],
|
|
|
|
];
|
|
|
|
|
|
|
|
if ($includeAvailableProfiles) {
|
2019-12-04 23:40:15 +05:30
|
|
|
// The Mojang themselves haven't come up with anything yet with these availableProfiles
|
2016-08-21 04:51:39 +05:30
|
|
|
$availableProfiles[0] = $result['selectedProfile'];
|
|
|
|
$result['availableProfiles'] = $availableProfiles;
|
|
|
|
}
|
|
|
|
|
2021-03-06 15:07:58 +05:30
|
|
|
if ($this->requestUser) {
|
|
|
|
// There are a lot of fields, but even Mojang returns only those:
|
|
|
|
$result['user'] = [
|
|
|
|
'id' => $uuid,
|
|
|
|
'username' => $this->account->username,
|
|
|
|
'properties' => [
|
|
|
|
[
|
|
|
|
'name' => 'preferredLanguage',
|
|
|
|
'value' => $this->account->lang,
|
|
|
|
],
|
|
|
|
],
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2016-08-21 04:51:39 +05:30
|
|
|
return $result;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|