HTTP AUTH and API fixes and clean ups

@rjmackay mind merging this pull request if all is good?