mirror of
https://github.com/elyby/accounts.git
synced 2024-11-23 05:33:20 +05:30
#20 Quick implementation of the https://api.minecraftservices.com/minecraft/profile endpoint [deploy dev]
This commit is contained in:
parent
5b8be60867
commit
31febd5606
@ -46,6 +46,7 @@ return [
|
|||||||
'/mojang/profiles/<username>' => 'mojang/api/uuid-by-username',
|
'/mojang/profiles/<username>' => 'mojang/api/uuid-by-username',
|
||||||
'/mojang/profiles/<uuid>/names' => 'mojang/api/usernames-by-uuid',
|
'/mojang/profiles/<uuid>/names' => 'mojang/api/usernames-by-uuid',
|
||||||
'POST /mojang/profiles' => 'mojang/api/uuids-by-usernames',
|
'POST /mojang/profiles' => 'mojang/api/uuids-by-usernames',
|
||||||
|
'GET /mojang/services/minecraft/profile' => 'mojang/services/profile',
|
||||||
|
|
||||||
// authlib-injector
|
// authlib-injector
|
||||||
'/authlib-injector/authserver/<action>' => 'authserver/authentication/<action>',
|
'/authlib-injector/authserver/<action>' => 'authserver/authentication/<action>',
|
||||||
|
87
api/modules/mojang/controllers/ServicesController.php
Normal file
87
api/modules/mojang/controllers/ServicesController.php
Normal file
@ -0,0 +1,87 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace api\modules\mojang\controllers;
|
||||||
|
|
||||||
|
use api\controllers\Controller;
|
||||||
|
use api\rbac\Permissions;
|
||||||
|
use common\components\SkinsSystemApi;
|
||||||
|
use Exception;
|
||||||
|
use Ramsey\Uuid\Uuid;
|
||||||
|
use Yii;
|
||||||
|
use yii\filters\AccessControl;
|
||||||
|
use yii\filters\VerbFilter;
|
||||||
|
use yii\helpers\ArrayHelper;
|
||||||
|
use function Ramsey\Uuid\v3;
|
||||||
|
|
||||||
|
final class ServicesController extends Controller {
|
||||||
|
|
||||||
|
public function behaviors(): array {
|
||||||
|
return ArrayHelper::merge(parent::behaviors(), [
|
||||||
|
'access' => [
|
||||||
|
'class' => AccessControl::class,
|
||||||
|
'rules' => [
|
||||||
|
[
|
||||||
|
'allow' => true,
|
||||||
|
'actions' => ['profile'],
|
||||||
|
'roles' => [Permissions::OBTAIN_ACCOUNT_INFO],
|
||||||
|
'roleParams' => function(): array {
|
||||||
|
$account = Yii::$app->user->identity->getAccount();
|
||||||
|
|
||||||
|
return [
|
||||||
|
'accountId' => $account ? $account->id : -1,
|
||||||
|
];
|
||||||
|
},
|
||||||
|
],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'verbs' => [
|
||||||
|
'class' => VerbFilter::class,
|
||||||
|
'actions' => [
|
||||||
|
'profile' => ['GET'],
|
||||||
|
],
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
public function actionProfile(SkinsSystemApi $skinsSystemApi): array {
|
||||||
|
/** @var \common\models\Account $account at this point null value isn't possible */
|
||||||
|
$account = Yii::$app->user->identity->getAccount();
|
||||||
|
|
||||||
|
try {
|
||||||
|
$textures = $skinsSystemApi->textures($account->username);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
Yii::warning('Cannot get textures from skinsystem.ely.by. Exception message is ' . $e->getMessage());
|
||||||
|
$textures = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
$response = [
|
||||||
|
'id' => str_replace('-', '', $account->uuid),
|
||||||
|
'name' => $account->username,
|
||||||
|
'skins' => [],
|
||||||
|
'capes' => [],
|
||||||
|
];
|
||||||
|
|
||||||
|
if (isset($textures['SKIN'])) {
|
||||||
|
$response['skins'][] = [
|
||||||
|
'id' => v3(Uuid::NAMESPACE_URL, $textures['SKIN']['url']),
|
||||||
|
'state' => 'ACTIVE',
|
||||||
|
'url' => $textures['SKIN']['url'],
|
||||||
|
'variant' => isset($textures['SKIN']['metadata']['model']) ? 'SLIM' : 'CLASSIC',
|
||||||
|
'alias' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isset($textures['CAPE'])) {
|
||||||
|
$response['capes'][] = [
|
||||||
|
'id' => v3(Uuid::NAMESPACE_URL, $textures['CAPE']['url']),
|
||||||
|
'state' => 'ACTIVE',
|
||||||
|
'url' => $textures['CAPE']['url'],
|
||||||
|
'alias' => '',
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
return $response;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
34
api/tests/functional/mojang/ProfileCest.php
Normal file
34
api/tests/functional/mojang/ProfileCest.php
Normal file
@ -0,0 +1,34 @@
|
|||||||
|
<?php
|
||||||
|
declare(strict_types=1);
|
||||||
|
|
||||||
|
namespace api\tests\functional\mojang;
|
||||||
|
|
||||||
|
use api\tests\FunctionalTester;
|
||||||
|
|
||||||
|
class ProfileCest {
|
||||||
|
|
||||||
|
public function getProfile(FunctionalTester $I): void {
|
||||||
|
$I->amAuthenticated();
|
||||||
|
$I->sendGet('/api/mojang/services/minecraft/profile');
|
||||||
|
$I->canSeeResponseCodeIs(200);
|
||||||
|
$I->canSeeResponseIsJson();
|
||||||
|
$I->canSeeResponseContainsJson([
|
||||||
|
'id' => 'df936908b2e1544d96f82977ec213022',
|
||||||
|
'name' => 'Admin',
|
||||||
|
'skins' => [
|
||||||
|
[
|
||||||
|
'id' => '1794a784-2d87-32f0-b233-0b2fd5682444',
|
||||||
|
'state' => 'ACTIVE',
|
||||||
|
'url' => 'http://localhost/skin.png',
|
||||||
|
'variant' => 'CLASSIC',
|
||||||
|
'alias' => '',
|
||||||
|
],
|
||||||
|
],
|
||||||
|
'capes' => [],
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: add cases for unauthenticated user
|
||||||
|
// TODO: add cases for authenticated as a service account user
|
||||||
|
|
||||||
|
}
|
@ -20,7 +20,7 @@ use const common\LATEST_RULES_VERSION;
|
|||||||
/**
|
/**
|
||||||
* Fields:
|
* Fields:
|
||||||
* @property int $id
|
* @property int $id
|
||||||
* @property string $uuid
|
* @property string $uuid UUID with dashes
|
||||||
* @property string $username
|
* @property string $username
|
||||||
* @property string $email
|
* @property string $email
|
||||||
* @property string $password_hash
|
* @property string $password_hash
|
||||||
|
Loading…
Reference in New Issue
Block a user