BasicAuth for multiple apps with different usernames and passwords

Refactored code to have the same structure as the TLS Authentication
code