refactor oauths callback and add tests