Define a cleaner authentication API.

This lays the groundwork for correctly handling session timeouts, as
well as abstracting out the mechanism used for login such that the
non-UI code could also be used on iOS.