Fixed port of cgi version of oauth2