There has been much controversy in recent years over so-called "stop and frisk" laws. These allow law enforcement officers to stop people at pat them down if they have "reasonable suspicion" of some sort of criminal activity.
However, can police stop you and ask for identification if you're not operating a vehicle? In nearly half of all U.S. states, that is legal. Connecticut is not one of those states. However, in many of our neighboring states in New England as well as in New York, it is.
These are called "Terry Stops." They're named for a defendant in a U.S. Supreme Court case. Justices ruled that officers can stop people when they have reasonable suspicion that they either have committed a crime, are about to or are in the process of doing so.
These are called "stop and identify" laws. State laws vary, however, regarding whether the person stopped is required to identify him/herself verbally or must produce an identification document such as a driver's license.
If an officer stops you and asks for ID, you may be required by law to provide it. However, you still have the right to remain silent beyond that and politely refuse to answer any further questions.
If the officer is not detaining you, you are free to leave. However, ask the officer (again, politely) if you are being detained before you go.
Of course, you also have the right to ask for an attorney. However, if you're simply being asked for ID, that may not be the best right to immediately invoke.
If things proceed from there and you are told that you're not free to leave or you are arrested, you have every right to ask to speak with an attorney. If you are facing charges, your attorney can work to protect your rights, including determining whether the initial stop and the actions taken during the stop were legal.
Source: ThoughtCo, "Do I Have to Show the Police My ID?," Charles Montaldo, accessed July 07, 2017