Add /super/settings endpoints and API middleware that returns generic 503 while keeping unlock routes whitelisted. Co-authored-by: Cursor <cursoragent@cursor.com>
35 lines
930 B
PHP
35 lines
930 B
PHP
<?php
|
|
|
|
namespace App\Http\Middleware;
|
|
|
|
use Closure;
|
|
use Illuminate\Http\Request;
|
|
|
|
/**
|
|
* Bearer token must match SUPERADMIN_REMOTE_TOKEN (same as SuperAdmin Tenant.remoteApiToken).
|
|
*/
|
|
class EnsureSuperAdminRemoteToken
|
|
{
|
|
public function handle(Request $request, Closure $next)
|
|
{
|
|
$expected = trim((string) config('services.superadmin.remote_token', ''));
|
|
if ($expected === '') {
|
|
return response()->json([
|
|
'message' => 'SUPERADMIN_REMOTE_TOKEN is not configured',
|
|
], 503);
|
|
}
|
|
|
|
$auth = (string) $request->header('Authorization', '');
|
|
$token = '';
|
|
if (preg_match('/^\s*Bearer\s+(.+)\s*$/i', $auth, $m)) {
|
|
$token = trim($m[1]);
|
|
}
|
|
|
|
if ($token === '' || ! hash_equals($expected, $token)) {
|
|
return response()->json(['message' => 'Unauthorized'], 401);
|
|
}
|
|
|
|
return $next($request);
|
|
}
|
|
}
|