Refactor login and configuration to general lib.