OAuth2 logic refactoring.