Allow configuration of which user to sign in
Extract authentication code to separate helper

This is now generic enough to use anywhere.