NEW YORK/WASHINGTON (Reuters) - An attempt by U.S. authorities to identify an anonymous critic of President Donald Trump on Twitter has set off alarm bells among Democratic and Republican lawmakers and civil liberties advocates fearful of a crackdown on dissent.

FILE PHOTO - A 3D-printed logo for Twitter is seen in this picture illustration made in Zenica, Bosnia and Herzegovina on January 26, 2016. REUTERS/Dado Ruvic/Illustration/File Photo

Twitter Inc TWTR.N on Friday succeeded in beating back a demand for records about a Twitter account called ALT Immigration (@ALT_uscis), which pokes fun at Trump's immigration policies and appears to be run by one or more federal employees.

The U.S. government withdrew an administrative summons that customs agents had sent the company in March demanding the records.

But the government backed away only after Twitter filed a federal lawsuit accusing it of violating the First Amendment’s protection of free speech. Customs agents could still continue the investigation using some other methods, civil liberties attorneys said.

Although authorities retreated, the case has laid bare the broad power of the U.S. government to demand information from technology companies, sometimes with no oversight from the courts and often with built-in secrecy provisions that prevent the public from knowing what the government is seeking.

The summons that Twitter received came from agents who investigate corruption and misconduct within U.S. Customs and Border Protection (CBP). Even after it was withdrawn, some lawmakers had questions about the agency’s actions.

“CBP must ensure that any properly authorized investigation does not disregard the rights to free speech enshrined in the First Amendment to the U.S. Constitution,” two Republican U.S. senators, Cory Gardner of Colorado and Mike Lee of Utah, wrote in a letter on Friday to Homeland Security Secretary John Kelly.

The senators asked whether the agency would ever ask a private company to divulge private records about a customer based solely on “non-criminal speech.” Senate Democrat Ron Wyden of Oregon called for an investigation of whether customs agents had violated a law by retaliating against an internal critic.

The Department of Homeland Security plans to respond directly to the senators, an official said on Friday.

FORMIDABLE RANGE

There are two primary ways the U.S. government can obtain information from internet companies without a judge’s approval using a law known as the Electronic Communications Privacy Act, according to experts in privacy law.

Agencies with enforcement power, such as the Internal Revenue Service, can issue administrative subpoenas demanding user records. Prosecutors can also ask grand juries investigating a crime to issue a subpoena.

An aggressive agency, for example, might demand information about a Twitter account that used an agency logo on the grounds that it is deceptive, said Georgetown University law professor Paul Ohm.

Similarly, a prosecutor could ask a grand jury to issue a subpoena based on the idea that a federal employee, suspected of criticizing the administration anonymously, was misusing government resources.

“It doesn’t take a brilliant legal mind to think of hypotheticals,” Ohm said. Further, such subpoenas are usually kept secret, making them more difficult to challenge.

Some other government tools, such as a national security letter, are intended to be used for narrow purposes related to counter-terrorism investigations. But they do not require judicial approval either, instead relying on internal safeguards. Challenging such demands is difficult and often requires deep pockets, attorneys familiar with such orders said.

“It’s important to keep in mind how formidable the government’s range of investigatory powers is,” said Andrew Crocker, a staff attorney with the Electronic Frontier Foundation, which advocates for digital rights.

In the case of ALT Immigration, Twitter said it was not bound to keep the summons a secret, and the company informed the account holder of the government demand. That person then found legal representation with the American Civil Liberties Union (ACLU).

Esha Bhandari, the ACLU staff attorney representing the dissident, said she thinks the speed with which the government withdrew its summons - less than a day after Twitter sued - means the customs agents will cease investigating, but she cannot be sure.

“It’s impossible to predict, of course, but I’m hopeful that this really is a recognition that people have the ability to speak online including in ways that are critical of the government,” Bhandari said.

The Department of Homeland Security has not said what its plans are for the investigation.

After Trump’s inauguration in January, anonymous Twitter feeds that borrowed the names and logos of more than a dozen U.S. government agencies appeared to challenge the president’s views on climate change and other issues. They called themselves “alt” accounts.

Twitter has declined to say if it has received any other government demands to reveal such anti-Trump critics.