Files
portal/app/app/Http/Middleware/TgRobotToken.php
T

32 lines
1.1 KiB
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
declare(strict_types=1);
namespace App\Http\Middleware;
use Closure;
use Illuminate\Http\Request;
use Symfony\Component\HttpFoundation\Response;
/**
* Сервис-токен канала «Телеграм-робот кабинета МТС → Портал» (/api/tg-robot/*).
*
* Это НЕ пользовательский вход: робот ходит от своего имени, без tenant-контекста.
* Пустой токен в настройках → канал закрыт (401), чтобы его нельзя было случайно
* открыть без секрета. Тот же порядок, что у CreativeRobotToken.
*/
class TgRobotToken
{
public function handle(Request $request, Closure $next): Response
{
$expected = (string) config('services.tg_robot.token', '');
$given = (string) $request->header('X-Tg-Robot-Token', '');
if ($expected === '' || ! hash_equals($expected, $given)) {
abort(401, 'Неверный сервис-токен телеграм-робота.');
}
return $next($request);
}
}