Deduplicate the code in auth.fcgi and unauth.fcgi