61 lines
2.1 KiB
PHP
61 lines
2.1 KiB
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
use Symfony\Component\HttpFoundation\Response;
|
|
|
|
class BasicAuthMiddleware
|
|
{
|
|
/**
|
|
* Handle an incoming request.
|
|
*
|
|
* @param \Closure(\Illuminate\Http\Request): (\Symfony\Component\HttpFoundation\Response) $next
|
|
*/
|
|
public function handle(Request $request, Closure $next): Response
|
|
{
|
|
// Skip Basic Auth für Livewire-Requests komplett
|
|
// Diese sind bereits durch Laravel Session/CSRF geschützt
|
|
$path = $request->path();
|
|
|
|
if (
|
|
str_starts_with($path, 'livewire/') ||
|
|
str_starts_with($path, 'livewire-') ||
|
|
str_contains($path, '/livewire/') ||
|
|
str_contains($path, '/livewire-') ||
|
|
$request->is('livewire/*') ||
|
|
$request->is('livewire-*') ||
|
|
$request->is('*/livewire/*') ||
|
|
$request->is('*/livewire-*')
|
|
) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Skip Basic Auth für Flux UI Assets (flux.js, flux.min.js, editor.js, etc.)
|
|
if (str_starts_with($path, 'flux/')) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Skip Basic Auth für Display-API, Cabinet-Tablet-API und Short-Links (öffentlicher Zugriff für Display-Seiten)
|
|
// Skip Basic Auth für Display-API, Cabinet-Tablet-API und Short-Links (öffentlicher Zugriff für Display-Seiten)
|
|
if (
|
|
$request->is('api/display/*') || $request->is('api/cabinet-tablet/*') || $request->is('_cabinet/*') ||
|
|
str_contains($request->url(), 'portal.b2in.test') || str_contains($request->url(), 'portal.b2in.eu') ||
|
|
str_contains($request->url(), 'b2in.test') || str_contains($request->url(), 'b2in.eu')
|
|
|
|
) {
|
|
return $next($request);
|
|
}
|
|
|
|
// Credentials from .env file
|
|
$user = config('auth.basic.user');
|
|
$pass = config('auth.basic.password');
|
|
|
|
if ($request->getUser() != $user || $request->getPassword() != $pass) {
|
|
return response('Unauthorized.', 401, ['WWW-Authenticate' => 'Basic']);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|