Files
hado/core/app/Http/Middleware/RemoteUser.php
2026-09-04 07:05:50 -03:00

30 lines
913 B
PHP
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<?php
namespace App\Http\Middleware;
use App\Ingest\EventUpserter;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Доверяет X-Remote-User от Caddy forward_auth (сеть изолирована, как в sekai).
* На публичных маршрутах (/api, /a, /hooks) этот middleware не стоит.
*/
class RemoteUser
{
public function __construct(private readonly EventUpserter $users) {}
public function handle(Request $request, Closure $next): Response
{
$login = trim((string) $request->header('X-Remote-User', ''));
if ($login === '') {
return response()->json(['message' => 'Нет X-Remote-User: запрос должен идти через хаб'], 401);
}
$request->attributes->set('user', $this->users->ensureUser($login));
return $next($request);
}
}