Refactor basic auth