 -- A man with a felony record in South Carolina purchased a gun from an undercover FBI agent with the intention of carrying out an attack in "the spirit of Dylann Roof," authorities said Thursday.

Benjamin McDowell, 29, who had allegedly become affiliated with white supremacist gangs during his time in prison, purchased a .40 caliber Glock handgun and ammunition, according to an affidavit filed by FBI agent Grant Lowe.

According to the complaint, McDowell was arrested in Myrtle Beach, South Carolina shortly after purchasing the weapon and charged as a felon in possession of a firearm.

The agent said that McDowell had made unspecified threats, once telling Lowe that he might shoot at a gathering of black people.

Authorities began investigating McDowell in December after he threatened a local synagogue on Facebook. Several days later, he again posted to Facebook, complaining that white supremacists were often unwilling to act on their convictions.

"All they wanne (sic) do is stay loaded on drugs the Jews put here to destroy white man and they feast on the drugs. they should be Feasting on the enemy that stole their Heritage and their bloodline and trying to run us off of this Earth," McDowell wrote. "if you ain't got the heart to fight for Yahweh like dylann roof did, you need to shut the f--- up."

On or about Jan. 6, 2017, according to the complaint, McDowell had requested an "iron," a code word for a gun, over Facebook Instant Messenger.

Court records show that since 2008, McDowell's criminal record included charges for assault and burglary. It also said local authorities had kept tabs on him prior to December because of the alleged white supremacist connections he had made in prison.

Dylann Roof was sentence to death last month for the 2015 massacre of 9 black worshipers at Emanuel AME Church in Charleston, South Carolina.