Rewriten authentication flow