History of "Keys to the City"

My city is now going to start “giving away the keys to the city.” I think this practice is based on giving keys to the city walls, but I am not sure.

Does anyone know where this practice came from?

The earliest instance I’ve found was when William the Conqueror was given the keys to the city of York. Such keys would be to the city’s gates, and giving them was a sign of submission to a conqueror.