Refactor authentication middleware; Allow CLI config overrides.