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
|
|
|
|
2024-12-02 15:40:55 +05:30
|
|
|
final readonly class AuthenticateData {
|
|
|
|
|
|
|
|
public function __construct(
|
|
|
|
private Account $account,
|
|
|
|
private string $accessToken,
|
|
|
|
private string $clientToken,
|
|
|
|
private bool $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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|