Move authentication logic into module to allow shared behavior across site and tests