Refactor the authentication a bit, in anticipation of digest-auth support.