Refactor API authorize method