diff --git a/app/Api/V1/Controllers/System/CronController.php b/app/Api/V1/Controllers/System/CronController.php index 2acd2803c5..b0ab2e1b34 100644 --- a/app/Api/V1/Controllers/System/CronController.php +++ b/app/Api/V1/Controllers/System/CronController.php @@ -26,6 +26,9 @@ namespace FireflyIII\Api\V1\Controllers\System; use FireflyIII\Api\V1\Controllers\Controller; use FireflyIII\Api\V1\Requests\System\CronRequest; +use FireflyIII\Http\Middleware\Binder; +use FireflyIII\Http\Middleware\Installer; +use FireflyIII\Support\Binder\CLIToken; use FireflyIII\Support\Facades\AppConfiguration; use FireflyIII\Support\Http\Controllers\CronRunner; use Illuminate\Http\JsonResponse; @@ -42,8 +45,9 @@ final class CronController extends Controller * This endpoint is documented at: * https://api-docs.firefly-iii.org/?urls.primaryName=2.0.0%20(v1)#/about/getCron */ - public function cron(CronRequest $request): JsonResponse + public function cron(CronRequest $request, string $cliToken): JsonResponse { + CLIToken::routeBinder($cliToken, $request->route()); $config = $request->getAll(); Log::debug(sprintf('Now in %s', __METHOD__)); diff --git a/app/Api/V1/Requests/System/CronRequest.php b/app/Api/V1/Requests/System/CronRequest.php index a7cd1607bf..9db00f68ed 100644 --- a/app/Api/V1/Requests/System/CronRequest.php +++ b/app/Api/V1/Requests/System/CronRequest.php @@ -68,6 +68,8 @@ class CronRequest extends FormRequest */ public function rules(): array { - return ['force' => 'in:true,false', 'date' => ['nullable', 'date', 'after:1970-01-02', 'before:2038-01-17']]; + return [ + 'force' => 'in:true,false', + 'date' => ['nullable', 'date', 'after:1970-01-02', 'before:2038-01-17']]; } } diff --git a/app/Http/Middleware/Binder.php b/app/Http/Middleware/Binder.php index e8e7e42283..152f6c3f64 100644 --- a/app/Http/Middleware/Binder.php +++ b/app/Http/Middleware/Binder.php @@ -42,12 +42,7 @@ class Binder /** * Binder constructor. */ - public function __construct( - /** - * The authentication factory instance. - */ - protected Auth $auth - ) { + public function __construct(protected Auth $auth) { $this->binders = Domain::getBindables(); } diff --git a/app/Support/Binder/CLIToken.php b/app/Support/Binder/CLIToken.php index 66486aa356..1d81b34c00 100644 --- a/app/Support/Binder/CLIToken.php +++ b/app/Support/Binder/CLIToken.php @@ -26,6 +26,7 @@ namespace FireflyIII\Support\Binder; use FireflyIII\Repositories\User\UserRepositoryInterface; use FireflyIII\Support\Facades\Preferences; +use Illuminate\Auth\AuthenticationException; use Illuminate\Routing\Route; use Illuminate\Support\Facades\Log; use Symfony\Component\HttpKernel\Exception\NotFoundHttpException; @@ -56,6 +57,6 @@ class CLIToken implements BinderInterface } Log::error(sprintf('Recognized no users by access token "%s"', $value)); - throw new NotFoundHttpException(); + throw new AuthenticationException(); } } diff --git a/bootstrap/app.php b/bootstrap/app.php index 08b06bf3b3..3791e2f5d4 100644 --- a/bootstrap/app.php +++ b/bootstrap/app.php @@ -160,8 +160,6 @@ $app = Application::configure(basePath: dirname(__DIR__)) AddQueuedCookiesToResponse::class, Binder::class, ]); - - // $middleware->priority([StartFireflyIIISession::class, ShareErrorsFromSession::class, Authenticate::class, Binder::class, Authorize::class]); }) ->withEvents(discover: [ __DIR__ . '/../app/Listeners', diff --git a/routes/api.php b/routes/api.php index b4f496f8c5..349d2f0235 100644 --- a/routes/api.php +++ b/routes/api.php @@ -22,8 +22,7 @@ declare(strict_types=1); -use FireflyIII\Http\Middleware\AcceptHeaders; -use FireflyIII\Http\Middleware\Binder; +use FireflyIII\Api\V1\Controllers\System\CronController; use Illuminate\Support\Facades\Route; use function Safe\define; @@ -47,10 +46,14 @@ Route::group( 'namespace' => 'FireflyIII\Api\V1\Controllers\System', 'prefix' => 'v1', 'as' => 'api.v1.cron.', - 'middleware' => [Binder::class, AcceptHeaders::class], ], static function (): void { - Route::get('cron/{cliToken}', ['uses' => 'CronController@cron', 'as' => 'index'])->withoutMiddleware(['api']); + Route::get('cron/{cliToken}', ['uses' => 'CronController@cron', 'as' => 'index']) + ->withoutMiddleware(['api']); + Route::get('cron/{cliToken}', + [CronController::class, 'cron'] + )->name('index') + ->withoutMiddleware(['api']); } );