French lawmakers have overwhelmingly approved a new legislation that would grant the state sweeping powers to spy on its citizens despite criticism from rights groups that the bill is too ambiguous and intrusive.

The law has been in the works for some time but gained additional support after a killing spree in January that left 17 dead and saw the capital, Paris, gripped with fear for three days.

France is still on high alert as it has received repeated threats from armed groups abroad.

The bill was passed on Tuesday by 438 votes to 86 in the lower house National Assembly, with broad support from both main parties. Only the far-left and greens were strongly opposed.

It will go before the upper house Senate later this month.

Al Jazeera's Neave Barker, reporting from Paris, said that the legislation would "very likely be passed in the Senate where it will only undergo a single reading".

Amnesty International has also protested against the legislation, warning it will take France "a step closer to a surveillance state".

"This bill is too vague, too far-reaching and leaves too many unanswered questions. Parliament should ensure that measures meant to protect people from terror should not violate their basic rights," said Amnesty's Europe director Gauri van Gulik.

Not a 'Patriot Act'

The new law will allow authorities to spy on the digital and mobile communications of anyone linked to a "terrorist" inquiry without prior authorisation from a judge, and forces internet service providers and phone companies to give up data upon request.

Intelligence services will have the right to place cameras and recording devices in private dwellings and install "keylogger" devices that record every key stroke on a targeted computer in real time.

The authorities will be able to keep recordings for a month, and metadata for five years.

Prime Minister Manuel Valls has fiercely defended the bill, saying that to compare it to the mass surveillance "Patriot Act" introduced in the United States after the 9/11 attacks was a "lie".

He has pointed out that the previous law on wiretapping dates back to 1991, "when there were no mobile phones or internet," which makes the new bill crucial in the face of threats of violence.

France decided to shake up its spy laws after the January 7-9 attacks on the Paris offices of the Charlie Hebdo magazine and a Jewish supermarket that sent shockwaves around the world.

After an Algerian was recently arrested purely by chance before carrying out an attack on a church, Valls warned the country has never "had to face this kind of terrorism in our history".

'Mass surveillance'

Perhaps the most controversial of the bill's proposals are so-called "black boxes" - or complex algorithms - that internet providers will be forced to install to flag up a pattern of suspicious behaviour online such as what keywords someone types, what sites they consult and who they contact and when.

A poll published last month showed that nearly two-thirds of French people were in favour of restricting freedoms in the name of fighting "extremism".

Only 32 percent of those surveyed in the CSA poll for the Atlantico news website said they were opposed to freedoms being reduced, although this proportion rose significantly among young people.

However, the national digital council, an independent advisory body, has come out against the proposed legislation.

The group said it was akin to "mass surveillance" which has "been shown to be extremely inefficient in the United States".