Refactors "invalid auth" and "auth expired" flow.

Fixes: #3082