Oauth

This function has a LOT of stuff going on in it. Can it be DRYed up?

Please put it in a class.