header(self::TOKEN_HEADER); // An empty (or literally "0") header is treated as no token at all, // so it can never match, whatever the configured token happens to be. if (! $presented) { return $this->refuse(); } return $presented == config('services.cron_job.auth_token') ? $next($request) : $this->refuse(); } /** * The refusal body is a bare JSON array, not an object — callers of the * webhook match on the status code, so the shape stays as it is. */ private function refuse(): Response { return response()->json(['unauthorized'], Response::HTTP_UNAUTHORIZED); } }