John Riley is John Reese's untraceable cover identity created by The Machine. Along with Harold Whistler, Sameen Gray, and 3 other unrevealed identities, it is one of 6 such covers The Machine created to protect her allies from Samaritan's network. Riley's cover job is a detective with the New York Police Department, partnered with Lionel Fusco. Riley's badge number is 8231.
At the end of season 3, Shaw and Root break into a Samaritan sever facility to place 7 servers that have been altered to ignore 7 cover identities in its hunt for the Machine and her allies. The first 6 servers contain one simple identity that, if compromised, can be targeted upon by Samaritan and Decima. These identities are given to Reese, Finch, Shaw, Daizo, Jason Greenfield and Daniel Casey. Although Root does receive a cover similar to the others to protect herself, her identity is different as that her cover can be compromised and re-established, as well as changed in order to help The Machine combat Decima, several times without arousing suspicion from Samaritan.
Anything history prior to Samaritan coming online did not actually happen and was simply fabricated. Within that fabricated story, Reese leads many to believe that he and Carter were rather close friends and he was undercover when she was murdered and that her death is the reason he has taken certain actions, such as record high number of shooting incidents or assisting an IAD officer, which can be considered reckless behavior. Immediately after starting to pose as Riley, Reese started to work undercover at Narcotics, arresting some serious players in the drug world.
Months into his career as Riley, Reese reopened the unsolved murders of the Patterson family, a case originally investigated by his old friend Detective Joss Carter. Reese ultimately solved the murders, stopping the real killer Gil and saving the life of Chase Patterson, the prime suspect who was exonerated by Reese closing the case. At the same time, Detective Lionel Fusco stated that as Riley, Reese wasn't "exactly employee of the month" and that Reese made a terrible cop. (“Terra Incognita”)
After growing tired of Reese and Finch not telling him the full truth, Fusco decided to sever ties with them. As part of that, Fusco ended his partnership with "Riley" and began seeking a new partner. (“Reassortment”)(“Sotto Voce”)
After "the Voice" resurfaced, Reese, as Riley, led the police effort to locate and disarm the criminal mastermind's bombs, resulting in a SWAT team being caught in a blast. Later, Reese told Fusco the truth about the Machine after Fusco had his back during a shootout in the 8th Precinct and the two reconciled their partnership. (“Sotto Voce”)
Trying to stop a Presidential assassination, Reese uses his badge as John Riley to try to get into a fundraiser. When Logan Pierce arrives, Reese claims that his job is to protect Pierce who gets Reese inside the fundraiser. After the assassination is stopped, Pierce reveals that his team got Reese and his team as an irrelevant number to protect. When Pierce gives Reese the paper with the number, the number is shown to be Detective John Riley. Pierce comments that once he realized Riley was actually Reese, it was easy to determine he was the victim and not the perpetrator, something Pierce claims took the fun out of it. (“Synecdoche”)
Samaritan is able to get Root's cochlear implant and as a consequence learns of the Team's cover identities. In response, Samaritan gives an anonymus tip to the police that John Riley is actually the Man in the Suit, resulting in Reese and Fusco's lieutenant turning on them. They are then apprehended by cops bribed by Samaritan to murder them but are rescued by Finch and snipers hired by Thornhill Corporation. Despite Reese's identity as Riley being exposed along with Fusco's association with him, Fusco is able to retain his job after Samaritan is destroyed. (“return 0”)