Refactoring for authorization_code mode support in a better way