. */ declare(strict_types=1); namespace FireflyIII\Support\Binder; use FireflyIII\Exceptions\FireflyException; use FireflyIII\Repositories\User\UserRepositoryInterface; use Illuminate\Routing\Route; use Log; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; /** * Class CLIToken */ class CLIToken implements BinderInterface { /** * @param string $value * @param Route $route * * @return mixed * @throws FireflyException */ public static function routeBinder(string $value, Route $route) { /** @var UserRepositoryInterface $repository */ $repository = app(UserRepositoryInterface::class); $users = $repository->all(); // check for static token if ($value === config('firefly.static_cron_token') && 32 === strlen((string) config('firefly.static_cron_token'))) { return $value; } foreach ($users as $user) { $accessToken = app('preferences')->getForUser($user, 'access_token'); if (null !== $accessToken && $accessToken->data === $value) { Log::info(sprintf('Recognized user #%d (%s) from his acccess token.', $user->id, $user->email)); return $value; } } Log::error(sprintf('Recognized no users by access token "%s"', $value)); throw new NotFoundHttpException(); } }