Refactoring of OAuth logic