Refactor auth classes and add tests