Legacy 4.x auth + logout

Provisionally done, to be tested more.