Yup, he did. In a 1996 candidate survey, when Obama was running for the State Senate seat that launched his political career, here's what he had to say:

I favor legalizing same-sex marriages, and would fight efforts to prohibit such marriages.