false], ]; } /** * @return AuthenticateData * @throws \api\modules\authserver\exceptions\IllegalArgumentException * @throws \api\modules\authserver\exceptions\ForbiddenOperationException */ public function refresh(): AuthenticateData { $this->validate(); $account = null; if (mb_strlen($this->accessToken) === 36) { /** @var MinecraftAccessKey $token */ $token = MinecraftAccessKey::findOne([ 'access_token' => $this->accessToken, 'client_token' => $this->clientToken, ]); if ($token !== null) { $account = $token->account; } } else { $token = Yii::$app->tokens->parse($this->accessToken); $tokenReader = new TokenReader($token); if ($tokenReader->getMinecraftClientToken() !== $this->clientToken) { throw new ForbiddenOperationException('Invalid token.'); } $account = Account::findOne(['id' => $tokenReader->getAccountId()]); } if ($account === null) { throw new ForbiddenOperationException('Invalid token.'); } if ($account->status === Account::STATUS_BANNED) { throw new ForbiddenOperationException('This account has been suspended.'); } $token = Yii::$app->tokensFactory->createForMinecraftAccount($account, $this->clientToken); return new AuthenticateData($account, (string)$token, $this->clientToken); } }