validateLegacyToken($value); } try { $token = Yii::$app->tokens->parse($value); } catch (Exception $e) { throw new ForbiddenOperationException('Invalid token.'); } if (!Yii::$app->tokens->verify($token)) { throw new ForbiddenOperationException('Invalid token.'); } if ($this->verifyExpiration && !$token->validate(new ValidationData(Carbon::now()->getTimestamp()))) { throw new ForbiddenOperationException('Token expired.'); } return null; } /** * @param string $value * * @return array|null * @throws ForbiddenOperationException */ private function validateLegacyToken(string $value): ?array { /** @var MinecraftAccessKey|null $result */ $result = MinecraftAccessKey::findOne(['access_token' => $value]); if ($result === null) { throw new ForbiddenOperationException('Invalid token.'); } if ($this->verifyExpiration && $result->isExpired()) { throw new ForbiddenOperationException('Token expired.'); } return null; } }