I wasn't working for me if logout() was run.  I believe is logout() is run..
- the page refreshes.
- tryBasicAuthLogin() is run before the user is prompted by the basic authentication login.
- The user is never prompted for basic authentication so the browser will forever send the  old headers which keep getting used by tryBasicAuthLogin()

I user will either..
- forever be logged in as a matching OC user to their browser's basic authentication user+pass
- forever not be able to login as a different user