false], [['requestUser'], 'boolean'], ]; } /** * @return AuthenticateData * @throws \api\modules\authserver\exceptions\IllegalArgumentException * @throws \api\modules\authserver\exceptions\ForbiddenOperationException */ public function refresh(): AuthenticateData { $this->validate(); $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.'); } $token = Yii::$app->tokensFactory->createForMinecraftAccount($account, $this->clientToken); // TODO: This behavior duplicates with the AuthenticationForm. Need to find a way to avoid duplication. /** @var OauthSession|null $minecraftOauthSession */ $minecraftOauthSession = $account->getOauthSessions() ->andWhere(['client_id' => OauthClient::UNAUTHORIZED_MINECRAFT_GAME_LAUNCHER]) ->one(); if ($minecraftOauthSession === null) { $minecraftOauthSession = new OauthSession(); $minecraftOauthSession->account_id = $account->id; $minecraftOauthSession->client_id = OauthClient::UNAUTHORIZED_MINECRAFT_GAME_LAUNCHER; $minecraftOauthSession->scopes = [P::MINECRAFT_SERVER_SESSION]; } $minecraftOauthSession->last_used_at = time(); Assert::true($minecraftOauthSession->save()); return new AuthenticateData($account, (string)$token, $this->clientToken, (bool)$this->requestUser); } }