mirror of
https://github.com/elyby/accounts.git
synced 2025-05-31 14:11:46 +05:30
Implemented PHP-CS-Fixer support
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace api\aop;
|
||||
|
||||
use api\aop\aspects;
|
||||
use Doctrine\Common\Annotations\AnnotationReader;
|
||||
use Go\Core\AspectContainer;
|
||||
use Go\Core\AspectKernel as BaseAspectKernel;
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
<?php
|
||||
namespace api\components\OAuth2;
|
||||
|
||||
use api\components\OAuth2\Storage;
|
||||
use League\OAuth2\Server\AuthorizationServer;
|
||||
use League\OAuth2\Server\Storage\AccessTokenInterface;
|
||||
use League\OAuth2\Server\Storage\RefreshTokenInterface;
|
||||
|
||||
@@ -9,11 +9,11 @@ class RefreshTokenEntity extends \League\OAuth2\Server\Entity\RefreshTokenEntity
|
||||
|
||||
private $sessionId;
|
||||
|
||||
public function isExpired() : bool {
|
||||
public function isExpired(): bool {
|
||||
return false;
|
||||
}
|
||||
|
||||
public function getSession() : SessionEntity {
|
||||
public function getSession(): SessionEntity {
|
||||
if ($this->session instanceof SessionEntity) {
|
||||
return $this->session;
|
||||
}
|
||||
@@ -26,18 +26,18 @@ class RefreshTokenEntity extends \League\OAuth2\Server\Entity\RefreshTokenEntity
|
||||
return $sessionStorage->getById($this->sessionId);
|
||||
}
|
||||
|
||||
public function getSessionId() : int {
|
||||
public function getSessionId(): int {
|
||||
return $this->sessionId;
|
||||
}
|
||||
|
||||
public function setSession(OriginalSessionEntity $session) {
|
||||
public function setSession(OriginalSessionEntity $session): self {
|
||||
parent::setSession($session);
|
||||
$this->setSessionId($session->getId());
|
||||
|
||||
return $this;
|
||||
}
|
||||
|
||||
public function setSessionId(int $sessionId) {
|
||||
public function setSessionId(int $sessionId): void {
|
||||
$this->sessionId = $sessionId;
|
||||
}
|
||||
|
||||
|
||||
@@ -133,8 +133,10 @@ class AuthCodeGrant extends AbstractGrant {
|
||||
throw new Exception\InvalidRequestException('client_id');
|
||||
}
|
||||
|
||||
$clientSecret = $this->server->getRequest()->request->get('client_secret',
|
||||
$this->server->getRequest()->getPassword());
|
||||
$clientSecret = $this->server->getRequest()->request->get(
|
||||
'client_secret',
|
||||
$this->server->getRequest()->getPassword()
|
||||
);
|
||||
if ($clientSecret === null && $this->shouldRequireClientSecret()) {
|
||||
throw new Exception\InvalidRequestException('client_secret');
|
||||
}
|
||||
|
||||
@@ -31,7 +31,7 @@ class AccessTokenStorage extends AbstractStorage implements AccessTokenInterface
|
||||
public function getScopes(OriginalAccessTokenEntity $token) {
|
||||
$scopes = $this->scopes($token->getId());
|
||||
$entities = [];
|
||||
foreach($scopes as $scope) {
|
||||
foreach ($scopes as $scope) {
|
||||
if ($this->server->getScopeStorage()->get($scope) !== null) {
|
||||
$entities[] = (new ScopeEntity($this->server))->hydrate(['id' => $scope]);
|
||||
}
|
||||
@@ -59,11 +59,11 @@ class AccessTokenStorage extends AbstractStorage implements AccessTokenInterface
|
||||
$this->scopes($token->getId())->delete();
|
||||
}
|
||||
|
||||
private function key(string $token) : Key {
|
||||
private function key(string $token): Key {
|
||||
return new Key($this->dataTable, $token);
|
||||
}
|
||||
|
||||
private function scopes(string $token) : Set {
|
||||
private function scopes(string $token): Set {
|
||||
return new Set($this->dataTable, $token, 'scopes');
|
||||
}
|
||||
|
||||
|
||||
@@ -61,11 +61,11 @@ class AuthCodeStorage extends AbstractStorage implements AuthCodeInterface {
|
||||
$this->scopes($token->getId())->delete();
|
||||
}
|
||||
|
||||
private function key(string $token) : Key {
|
||||
private function key(string $token): Key {
|
||||
return new Key($this->dataTable, $token);
|
||||
}
|
||||
|
||||
private function scopes(string $token) : Set {
|
||||
private function scopes(string $token): Set {
|
||||
return new Set($this->dataTable, $token, 'scopes');
|
||||
}
|
||||
|
||||
|
||||
@@ -11,8 +11,8 @@ use yii\helpers\StringHelper;
|
||||
|
||||
class ClientStorage extends AbstractStorage implements ClientInterface {
|
||||
|
||||
const REDIRECT_STATIC_PAGE = 'static_page';
|
||||
const REDIRECT_STATIC_PAGE_WITH_CODE = 'static_page_with_code';
|
||||
private const REDIRECT_STATIC_PAGE = 'static_page';
|
||||
private const REDIRECT_STATIC_PAGE_WITH_CODE = 'static_page_with_code';
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
@@ -66,7 +66,7 @@ class ClientStorage extends AbstractStorage implements ClientInterface {
|
||||
return $this->hydrate($model);
|
||||
}
|
||||
|
||||
private function hydrate(OauthClient $model) : ClientEntity {
|
||||
private function hydrate(OauthClient $model): ClientEntity {
|
||||
$entity = new ClientEntity($this->server);
|
||||
$entity->setId($model->id);
|
||||
$entity->setName($model->name);
|
||||
|
||||
@@ -51,12 +51,12 @@ class RefreshTokenStorage extends AbstractStorage implements RefreshTokenInterfa
|
||||
$this->sessionHash($token->getSessionId())->remove($token->getId());
|
||||
}
|
||||
|
||||
public function sessionHash(string $sessionId) : Set {
|
||||
public function sessionHash(string $sessionId): Set {
|
||||
$tableName = Yii::$app->db->getSchema()->getRawTableName(OauthSession::tableName());
|
||||
return new Set($tableName, $sessionId, 'refresh_tokens');
|
||||
}
|
||||
|
||||
private function key(string $token) : Key {
|
||||
private function key(string $token): Key {
|
||||
return new Key($this->dataTable, $token);
|
||||
}
|
||||
|
||||
|
||||
@@ -76,7 +76,7 @@ class SessionStorage extends AbstractStorage implements SessionInterface {
|
||||
$this->getSessionModel($session->getId())->getScopes()->add($scope->getId());
|
||||
}
|
||||
|
||||
private function getSessionModel(string $sessionId) : OauthSession {
|
||||
private function getSessionModel(string $sessionId): OauthSession {
|
||||
$session = OauthSession::findOne($sessionId);
|
||||
if ($session === null) {
|
||||
throw new ErrorException('Cannot find oauth session');
|
||||
|
||||
@@ -214,7 +214,7 @@ class Component extends YiiUserComponent {
|
||||
|
||||
protected function createToken(Account $account): Token {
|
||||
$token = new Token();
|
||||
foreach($this->getClaims($account) as $claim) {
|
||||
foreach ($this->getClaims($account) as $claim) {
|
||||
$token->addClaim($claim);
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,10 @@ class Identity implements IdentityInterface {
|
||||
*/
|
||||
private $_accessToken;
|
||||
|
||||
private function __construct(AccessTokenEntity $accessToken) {
|
||||
$this->_accessToken = $accessToken;
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
* @throws \yii\web\UnauthorizedHttpException
|
||||
@@ -73,10 +77,6 @@ class Identity implements IdentityInterface {
|
||||
throw new NotSupportedException('This method used for cookie auth, except we using Bearer auth');
|
||||
}
|
||||
|
||||
private function __construct(AccessTokenEntity $accessToken) {
|
||||
$this->_accessToken = $accessToken;
|
||||
}
|
||||
|
||||
private function getSession(): OauthSession {
|
||||
return OauthSession::findOne($this->_accessToken->getSessionId());
|
||||
}
|
||||
|
||||
@@ -23,6 +23,11 @@ class JwtIdentity implements IdentityInterface {
|
||||
*/
|
||||
private $token;
|
||||
|
||||
private function __construct(string $rawToken, Token $token) {
|
||||
$this->rawToken = $rawToken;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
public static function findIdentityByAccessToken($rawToken, $type = null): IdentityInterface {
|
||||
/** @var \api\components\User\Component $component */
|
||||
$component = Yii::$app->user;
|
||||
@@ -86,9 +91,4 @@ class JwtIdentity implements IdentityInterface {
|
||||
throw new NotSupportedException('This method used for cookie auth, except we using Bearer auth');
|
||||
}
|
||||
|
||||
private function __construct(string $rawToken, Token $token) {
|
||||
$this->rawToken = $rawToken;
|
||||
$this->token = $token;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ use Emarref\Jwt\Claim\AbstractClaim;
|
||||
|
||||
class ScopesClaim extends AbstractClaim {
|
||||
|
||||
const NAME = 'ely-scopes';
|
||||
public const NAME = 'ely-scopes';
|
||||
|
||||
/**
|
||||
* ScopesClaim constructor.
|
||||
|
||||
@@ -21,7 +21,7 @@ class SubjectPrefixVerifier implements VerifierInterface {
|
||||
$subject = ($subjectClaim === null) ? null : $subjectClaim->getValue();
|
||||
|
||||
if (!StringHelper::startsWith($subject, $this->subjectPrefix)) {
|
||||
throw new InvalidSubjectException;
|
||||
throw new InvalidSubjectException();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -2,8 +2,8 @@
|
||||
namespace api\controllers;
|
||||
|
||||
use api\models\authentication\ConfirmEmailForm;
|
||||
use api\models\authentication\RepeatAccountActivationForm;
|
||||
use api\models\authentication\RegistrationForm;
|
||||
use api\models\authentication\RepeatAccountActivationForm;
|
||||
use common\helpers\Error as E;
|
||||
use Yii;
|
||||
use yii\filters\AccessControl;
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
<?php
|
||||
namespace api\models;
|
||||
|
||||
use common\helpers\Error as E;
|
||||
use api\models\base\ApiForm;
|
||||
use common\helpers\Error as E;
|
||||
use common\models\Account;
|
||||
use Yii;
|
||||
use yii\base\ErrorException;
|
||||
@@ -29,7 +29,7 @@ class FeedbackForm extends ApiForm {
|
||||
];
|
||||
}
|
||||
|
||||
public function sendMessage() : bool {
|
||||
public function sendMessage(): bool {
|
||||
if (!$this->validate()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,9 @@ namespace api\models\authentication;
|
||||
use api\aop\annotations\CollectModelMetrics;
|
||||
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
||||
use api\models\base\ApiForm;
|
||||
use common\helpers\Error as E;
|
||||
use api\traits\AccountFinder;
|
||||
use common\components\UserFriendlyRandomKey;
|
||||
use common\helpers\Error as E;
|
||||
use common\models\Account;
|
||||
use common\models\confirmations\ForgotPassword;
|
||||
use common\models\EmailActivation;
|
||||
|
||||
@@ -3,9 +3,9 @@ namespace api\models\authentication;
|
||||
|
||||
use api\aop\annotations\CollectModelMetrics;
|
||||
use api\models\base\ApiForm;
|
||||
use api\traits\AccountFinder;
|
||||
use api\validators\TotpValidator;
|
||||
use common\helpers\Error as E;
|
||||
use api\traits\AccountFinder;
|
||||
use common\models\Account;
|
||||
use Yii;
|
||||
|
||||
@@ -13,8 +13,11 @@ class LoginForm extends ApiForm {
|
||||
use AccountFinder;
|
||||
|
||||
public $login;
|
||||
|
||||
public $password;
|
||||
|
||||
public $totp;
|
||||
|
||||
public $rememberMe = false;
|
||||
|
||||
public function rules(): array {
|
||||
|
||||
@@ -11,7 +11,7 @@ class LogoutForm extends ApiForm {
|
||||
* @CollectModelMetrics(prefix="authentication.logout")
|
||||
* @return bool
|
||||
*/
|
||||
public function logout() : bool {
|
||||
public function logout(): bool {
|
||||
$component = Yii::$app->user;
|
||||
$session = $component->getActiveSession();
|
||||
if ($session === null) {
|
||||
|
||||
@@ -4,8 +4,8 @@ namespace api\models\authentication;
|
||||
use api\aop\annotations\CollectModelMetrics;
|
||||
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
||||
use api\models\base\ApiForm;
|
||||
use common\helpers\Error as E;
|
||||
use common\components\UserFriendlyRandomKey;
|
||||
use common\helpers\Error as E;
|
||||
use common\models\Account;
|
||||
use common\models\confirmations\RegistrationConfirmation;
|
||||
use common\models\UsernameHistory;
|
||||
@@ -126,7 +126,7 @@ class RegistrationForm extends ApiForm {
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
protected function canContinue(array $errors) : bool {
|
||||
protected function canContinue(array $errors): bool {
|
||||
if (ArrayHelper::getValue($errors, 'username') === E::USERNAME_NOT_AVAILABLE) {
|
||||
$duplicatedUsername = Account::findOne([
|
||||
'username' => $this->username,
|
||||
|
||||
@@ -5,8 +5,8 @@ use api\aop\annotations\CollectModelMetrics;
|
||||
use api\components\ReCaptcha\Validator as ReCaptchaValidator;
|
||||
use api\exceptions\ThisShouldNotHappenException;
|
||||
use api\models\base\ApiForm;
|
||||
use common\helpers\Error as E;
|
||||
use common\components\UserFriendlyRandomKey;
|
||||
use common\helpers\Error as E;
|
||||
use common\models\Account;
|
||||
use common\models\confirmations\RegistrationConfirmation;
|
||||
use common\models\EmailActivation;
|
||||
|
||||
@@ -21,8 +21,6 @@ abstract class BaseAccountAction extends Action {
|
||||
return $this->formatSuccessResult($model);
|
||||
}
|
||||
|
||||
abstract protected function getFormClassName(): string;
|
||||
|
||||
public function getRequestData(): array {
|
||||
return Yii::$app->request->post();
|
||||
}
|
||||
@@ -35,6 +33,8 @@ abstract class BaseAccountAction extends Action {
|
||||
return [];
|
||||
}
|
||||
|
||||
abstract protected function getFormClassName(): string;
|
||||
|
||||
private function formatFailedResult(AccountActionForm $model): array {
|
||||
$response = [
|
||||
'success' => false,
|
||||
|
||||
@@ -6,10 +6,6 @@ use api\modules\accounts\models\ChangeEmailForm;
|
||||
|
||||
class ChangeEmailAction extends BaseAccountAction {
|
||||
|
||||
protected function getFormClassName(): string {
|
||||
return ChangeEmailForm::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param ChangeEmailForm|AccountActionForm $model
|
||||
* @return array
|
||||
@@ -20,4 +16,8 @@ class ChangeEmailAction extends BaseAccountAction {
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFormClassName(): string {
|
||||
return ChangeEmailForm::class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -7,10 +7,6 @@ use common\helpers\Error as E;
|
||||
|
||||
class EmailVerificationAction extends BaseAccountAction {
|
||||
|
||||
protected function getFormClassName(): string {
|
||||
return SendEmailVerificationForm::class;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param SendEmailVerificationForm|AccountActionForm $model
|
||||
* @return array
|
||||
@@ -29,4 +25,8 @@ class EmailVerificationAction extends BaseAccountAction {
|
||||
];
|
||||
}
|
||||
|
||||
protected function getFormClassName(): string {
|
||||
return SendEmailVerificationForm::class;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ class ChangeEmailForm extends AccountActionForm {
|
||||
}
|
||||
|
||||
public function createTask(int $accountId, string $newEmail, string $oldEmail): void {
|
||||
$model = new EmailChanged;
|
||||
$model = new EmailChanged();
|
||||
$model->accountId = $accountId;
|
||||
$model->oldEmail = $oldEmail;
|
||||
$model->newEmail = $newEmail;
|
||||
|
||||
@@ -6,6 +6,8 @@ use OTPHP\TOTP;
|
||||
|
||||
trait TotpHelper {
|
||||
|
||||
abstract public function getAccount(): Account;
|
||||
|
||||
protected function getTotp(): TOTP {
|
||||
$account = $this->getAccount();
|
||||
$totp = TOTP::create($account->otp_secret);
|
||||
@@ -15,6 +17,4 @@ trait TotpHelper {
|
||||
return $totp;
|
||||
}
|
||||
|
||||
abstract public function getAccount(): Account;
|
||||
|
||||
}
|
||||
|
||||
@@ -17,10 +17,10 @@ class AuthenticationController extends Controller {
|
||||
public function verbs() {
|
||||
return [
|
||||
'authenticate' => ['POST'],
|
||||
'refresh' => ['POST'],
|
||||
'validate' => ['POST'],
|
||||
'signout' => ['POST'],
|
||||
'invalidate' => ['POST'],
|
||||
'refresh' => ['POST'],
|
||||
'validate' => ['POST'],
|
||||
'signout' => ['POST'],
|
||||
'invalidate' => ['POST'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@ class AuthenticateData {
|
||||
$this->minecraftAccessKey = $minecraftAccessKey;
|
||||
}
|
||||
|
||||
public function getMinecraftAccessKey() : MinecraftAccessKey {
|
||||
public function getMinecraftAccessKey(): MinecraftAccessKey {
|
||||
return $this->minecraftAccessKey;
|
||||
}
|
||||
|
||||
public function getResponseData(bool $includeAvailableProfiles = false) : array {
|
||||
public function getResponseData(bool $includeAvailableProfiles = false): array {
|
||||
$accessKey = $this->minecraftAccessKey;
|
||||
$account = $accessKey->account;
|
||||
|
||||
|
||||
@@ -14,7 +14,9 @@ use common\models\MinecraftAccessKey;
|
||||
class AuthenticationForm extends ApiForm {
|
||||
|
||||
public $username;
|
||||
|
||||
public $password;
|
||||
|
||||
public $clientToken;
|
||||
|
||||
public function rules() {
|
||||
@@ -41,13 +43,15 @@ class AuthenticationForm extends ApiForm {
|
||||
if (isset($errors['totp'])) {
|
||||
Authserver::error("User with login = '{$this->username}' protected by two factor auth.");
|
||||
throw new ForbiddenOperationException('Account protected with two factor auth.');
|
||||
} elseif (isset($errors['login'])) {
|
||||
}
|
||||
|
||||
if (isset($errors['login'])) {
|
||||
if ($errors['login'] === E::ACCOUNT_BANNED) {
|
||||
Authserver::error("User with login = '{$this->username}' is banned");
|
||||
throw new ForbiddenOperationException('This account has been suspended.');
|
||||
} else {
|
||||
Authserver::error("Cannot find user by login = '{$this->username}'");
|
||||
}
|
||||
|
||||
Authserver::error("Cannot find user by login = '{$this->username}'");
|
||||
} elseif (isset($errors['password'])) {
|
||||
Authserver::error("User with login = '{$this->username}' passed wrong password.");
|
||||
}
|
||||
@@ -72,7 +76,7 @@ class AuthenticationForm extends ApiForm {
|
||||
return $dataModel;
|
||||
}
|
||||
|
||||
protected function createMinecraftAccessToken(Account $account) : MinecraftAccessKey {
|
||||
protected function createMinecraftAccessToken(Account $account): MinecraftAccessKey {
|
||||
/** @var MinecraftAccessKey|null $accessTokenModel */
|
||||
$accessTokenModel = MinecraftAccessKey::findOne([
|
||||
'account_id' => $account->id,
|
||||
@@ -92,7 +96,7 @@ class AuthenticationForm extends ApiForm {
|
||||
return $accessTokenModel;
|
||||
}
|
||||
|
||||
protected function createLoginForm() : LoginForm {
|
||||
protected function createLoginForm(): LoginForm {
|
||||
return new LoginForm();
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@ use common\models\MinecraftAccessKey;
|
||||
class InvalidateForm extends ApiForm {
|
||||
|
||||
public $accessToken;
|
||||
|
||||
public $clientToken;
|
||||
|
||||
public function rules() {
|
||||
@@ -20,7 +21,7 @@ class InvalidateForm extends ApiForm {
|
||||
* @return bool
|
||||
* @throws \api\modules\authserver\exceptions\AuthserverException
|
||||
*/
|
||||
public function invalidateToken() : bool {
|
||||
public function invalidateToken(): bool {
|
||||
$this->validate();
|
||||
|
||||
$token = MinecraftAccessKey::findOne([
|
||||
|
||||
@@ -10,6 +10,7 @@ use common\models\MinecraftAccessKey;
|
||||
class RefreshTokenForm extends ApiForm {
|
||||
|
||||
public $accessToken;
|
||||
|
||||
public $clientToken;
|
||||
|
||||
public function rules() {
|
||||
|
||||
@@ -12,6 +12,7 @@ use Yii;
|
||||
class SignoutForm extends ApiForm {
|
||||
|
||||
public $username;
|
||||
|
||||
public $password;
|
||||
|
||||
public function rules() {
|
||||
@@ -20,7 +21,7 @@ class SignoutForm extends ApiForm {
|
||||
];
|
||||
}
|
||||
|
||||
public function signout() : bool {
|
||||
public function signout(): bool {
|
||||
$this->validate();
|
||||
|
||||
$loginForm = new LoginForm();
|
||||
|
||||
@@ -16,7 +16,7 @@ class ValidateForm extends ApiForm {
|
||||
];
|
||||
}
|
||||
|
||||
public function validateToken() : bool {
|
||||
public function validateToken(): bool {
|
||||
$this->validate();
|
||||
|
||||
/** @var MinecraftAccessKey|null $result */
|
||||
|
||||
@@ -54,7 +54,7 @@ class ApiController extends Controller {
|
||||
public function actionUsernamesByUuid($uuid) {
|
||||
try {
|
||||
$uuid = Uuid::fromString($uuid)->toString();
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
return $this->illegalArgumentResponse('Invalid uuid format.');
|
||||
}
|
||||
|
||||
@@ -69,7 +69,7 @@ class ApiController extends Controller {
|
||||
->all();
|
||||
|
||||
$data = [];
|
||||
foreach($usernameHistory as $record) {
|
||||
foreach ($usernameHistory as $record) {
|
||||
$data[] = [
|
||||
'name' => $record->username,
|
||||
'changedToAt' => $record->applied_in * 1000,
|
||||
@@ -94,7 +94,7 @@ class ApiController extends Controller {
|
||||
return $this->illegalArgumentResponse('Not more that 100 profile name per call is allowed.');
|
||||
}
|
||||
|
||||
foreach($usernames as $username) {
|
||||
foreach ($usernames as $username) {
|
||||
if (empty($username) || is_array($username)) {
|
||||
return $this->illegalArgumentResponse('profileName can not be null, empty or array key.');
|
||||
}
|
||||
@@ -108,7 +108,7 @@ class ApiController extends Controller {
|
||||
->all();
|
||||
|
||||
$responseData = [];
|
||||
foreach($accounts as $account) {
|
||||
foreach ($accounts as $account) {
|
||||
$responseData[] = [
|
||||
'id' => str_replace('-', '', $account->uuid),
|
||||
'name' => $account->username,
|
||||
|
||||
@@ -38,7 +38,7 @@ class AuthorizationController extends Controller {
|
||||
return [
|
||||
'validate' => ['GET'],
|
||||
'complete' => ['POST'],
|
||||
'token' => ['POST'],
|
||||
'token' => ['POST'],
|
||||
];
|
||||
}
|
||||
|
||||
|
||||
@@ -4,4 +4,5 @@ declare(strict_types=1);
|
||||
namespace api\modules\oauth\exceptions;
|
||||
|
||||
interface OauthException {
|
||||
|
||||
}
|
||||
|
||||
@@ -16,7 +16,7 @@ class ApplicationType extends BaseOauthClientType {
|
||||
public function rules(): array {
|
||||
return ArrayHelper::merge(parent::rules(), [
|
||||
['redirectUri', 'required', 'message' => E::REDIRECT_URI_REQUIRED],
|
||||
['redirectUri', 'url', 'validSchemes' => ['[\w]+'], 'message' => E::REDIRECT_URI_INVALID],
|
||||
['redirectUri', 'url', 'validSchemes' => ['[\w]+'], 'message' => E::REDIRECT_URI_INVALID],
|
||||
['description', 'string'],
|
||||
]);
|
||||
}
|
||||
|
||||
@@ -98,7 +98,7 @@ class SessionController extends Controller {
|
||||
public function actionProfile($uuid) {
|
||||
try {
|
||||
$uuid = Uuid::fromString($uuid)->toString();
|
||||
} catch(\InvalidArgumentException $e) {
|
||||
} catch (\InvalidArgumentException $e) {
|
||||
throw new IllegalArgumentException('Invalid uuid format.');
|
||||
}
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
<?php
|
||||
namespace api\modules\session\exceptions;
|
||||
|
||||
class ForbiddenOperationException extends SessionServerException {
|
||||
class ForbiddenOperationException extends SessionServerException {
|
||||
|
||||
public function __construct($message, $code = 0, \Exception $previous = null) {
|
||||
parent::__construct($status = 401, $message, $code, $previous);
|
||||
|
||||
@@ -10,6 +10,7 @@ use yii\web\TooManyRequestsHttpException;
|
||||
class RateLimiter extends \yii\filters\RateLimiter {
|
||||
|
||||
public $limit = 180;
|
||||
|
||||
public $limitTime = 3600; // 1h
|
||||
|
||||
public $authserverDomain;
|
||||
@@ -100,7 +101,7 @@ class RateLimiter extends \yii\filters\RateLimiter {
|
||||
return $this->server;
|
||||
}
|
||||
|
||||
protected function buildKey($ip) : string {
|
||||
protected function buildKey($ip): string {
|
||||
return 'sessionserver:ratelimit:' . $ip;
|
||||
}
|
||||
|
||||
|
||||
@@ -7,9 +7,9 @@ use api\modules\session\models\protocols\JoinInterface;
|
||||
use api\modules\session\Module as Session;
|
||||
use api\modules\session\validators\RequiredValidator;
|
||||
use common\helpers\StringHelper;
|
||||
use common\rbac\Permissions as P;
|
||||
use common\models\Account;
|
||||
use common\models\MinecraftAccessKey;
|
||||
use common\rbac\Permissions as P;
|
||||
use Ramsey\Uuid\Uuid;
|
||||
use Yii;
|
||||
use yii\base\ErrorException;
|
||||
@@ -19,7 +19,9 @@ use yii\web\UnauthorizedHttpException;
|
||||
class JoinForm extends Model {
|
||||
|
||||
public $accessToken;
|
||||
|
||||
public $selectedProfile;
|
||||
|
||||
public $serverId;
|
||||
|
||||
/**
|
||||
|
||||
@@ -6,7 +6,7 @@ use Yii;
|
||||
|
||||
class SessionModel {
|
||||
|
||||
const KEY_TIME = 120; // 2 min
|
||||
private const KEY_TIME = 120; // 2 min
|
||||
|
||||
public $username;
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@ namespace api\modules\session\models\protocols;
|
||||
abstract class BaseHasJoined implements HasJoinedInterface {
|
||||
|
||||
private $username;
|
||||
|
||||
private $serverId;
|
||||
|
||||
public function __construct(string $username, string $serverId) {
|
||||
|
||||
@@ -4,10 +4,13 @@ namespace api\modules\session\models\protocols;
|
||||
class LegacyJoin extends BaseJoin {
|
||||
|
||||
private $user;
|
||||
|
||||
private $sessionId;
|
||||
|
||||
private $serverId;
|
||||
|
||||
private $accessToken;
|
||||
|
||||
private $uuid;
|
||||
|
||||
public function __construct(string $user, string $sessionId, string $serverId) {
|
||||
@@ -18,7 +21,7 @@ class LegacyJoin extends BaseJoin {
|
||||
$this->parseSessionId($this->sessionId);
|
||||
}
|
||||
|
||||
public function getAccessToken() : string {
|
||||
public function getAccessToken(): string {
|
||||
return $this->accessToken;
|
||||
}
|
||||
|
||||
|
||||
@@ -4,7 +4,9 @@ namespace api\modules\session\models\protocols;
|
||||
class ModernJoin extends BaseJoin {
|
||||
|
||||
private $accessToken;
|
||||
|
||||
private $selectedProfile;
|
||||
|
||||
private $serverId;
|
||||
|
||||
public function __construct(string $accessToken, string $selectedProfile, string $serverId) {
|
||||
|
||||
@@ -7,7 +7,7 @@ trait AccountFinder {
|
||||
|
||||
private $account;
|
||||
|
||||
public abstract function getLogin(): string;
|
||||
abstract public function getLogin(): string;
|
||||
|
||||
public function getAccount(): ?Account {
|
||||
if ($this->account === null) {
|
||||
|
||||
Reference in New Issue
Block a user