diff --git a/.env.example b/.env.example index 9f57aad..1a65724 100644 --- a/.env.example +++ b/.env.example @@ -63,3 +63,6 @@ AWS_BUCKET= AWS_USE_PATH_STYLE_ENDPOINT=false VITE_APP_NAME="${APP_NAME}" + +BASIC_AUTH_USERNAME=crawlshot +BASIC_AUTH_PASSWORD=shotcrawl diff --git a/app/Http/Middleware/BasicAuthMiddleware.php b/app/Http/Middleware/BasicAuthMiddleware.php new file mode 100644 index 0000000..778134a --- /dev/null +++ b/app/Http/Middleware/BasicAuthMiddleware.php @@ -0,0 +1,40 @@ +header('PHP_AUTH_USER', null) && $request->header('PHP_AUTH_PW', null)) { + $username = $request->header('PHP_AUTH_USER'); + $password = $request->header('PHP_AUTH_PW'); + + if ($username === config('auth.basic_auth.username') && $password === config('auth.basic_auth.password')) { + $authenticationHasPassed = true; + } + } + + if ($authenticationHasPassed === false) { + return response()->make('Invalid credentials.', 401, ['WWW-Authenticate' => 'Basic']); + } + + return $next($request); + } +} diff --git a/app/Providers/HorizonServiceProvider.php b/app/Providers/HorizonServiceProvider.php index 59599dc..7aad59d 100644 --- a/app/Providers/HorizonServiceProvider.php +++ b/app/Providers/HorizonServiceProvider.php @@ -28,9 +28,11 @@ public function boot(): void protected function gate(): void { Gate::define('viewHorizon', function ($user = null) { - return in_array(optional($user)->email, [ - // - ]); + + return true; + // return in_array(optional($user)->email, [ + // // + // ]); }); } } diff --git a/config/auth.php b/config/auth.php index 7d1eb0d..eefcc01 100644 --- a/config/auth.php +++ b/config/auth.php @@ -2,6 +2,21 @@ return [ + /* + |-------------------------------------------------------------------------- + | Basic Auth + |-------------------------------------------------------------------------- + | + | Basic auth credentials for Laravel Horizon. + | + */ + + 'basic_auth' => [ + 'username' => env('BASIC_AUTH_USERNAME'), + 'password' => env('BASIC_AUTH_PASSWORD'), + ], + + /* |-------------------------------------------------------------------------- | Authentication Defaults diff --git a/config/horizon.php b/config/horizon.php index 5101f6f..8a1067d 100644 --- a/config/horizon.php +++ b/config/horizon.php @@ -56,7 +56,7 @@ 'prefix' => env( 'HORIZON_PREFIX', - Str::slug(env('APP_NAME', 'laravel'), '_').'_horizon:' + Str::slug(env('APP_NAME', 'laravel'), '_') . '_horizon:' ), /* @@ -70,7 +70,7 @@ | */ - 'middleware' => ['web'], + 'middleware' => ['web', App\Http\Middleware\BasicAuthMiddleware::class], /* |--------------------------------------------------------------------------