Refactoring the oAuth logic