Rework handling of OAuth and fix e2e tests.