Python 龙卷风谷歌+;Oauth错误代码400

Python 龙卷风谷歌+;Oauth错误代码400,python,angularjs,nginx,tornado,google-oauth,Python,Angularjs,Nginx,Tornado,Google Oauth,我在使用tornado框架的Google+OAuth中遇到了问题。我使用AngularJS作为前端,PythonTornado作为nginx服务器的后端。我从AngularJS向Google+API发送HTTP请求,我的tornado API被重定向到Google登录。成功登录后,它会重定向回我的应用程序。在重定向时,我认为它会自动刷新,也就是说,有两个来自谷歌的重定向调用 请参阅tornado OAuth2有两个HTTP重定向调用 这是我的代码: class GoogleOAuth2Logi

我在使用tornado框架的Google+OAuth中遇到了问题。我使用AngularJS作为前端,PythonTornado作为nginx服务器的后端。我从AngularJS向Google+API发送HTTP请求,我的tornado API被重定向到Google登录。成功登录后,它会重定向回我的应用程序。在重定向时,我认为它会自动刷新,也就是说,有两个来自谷歌的重定向调用

请参阅tornado OAuth2有两个HTTP重定向调用

这是我的代码:

class GoogleOAuth2LoginHandler(tornado.web.RequestHandler, tornado.auth.GoogleOAuth2Mixin):
    @tornado.gen.coroutine
        def get(self):
            if self.get_argument('code', False):
                user = yield self.get_authenticated_user(
                    redirect_uri='http://your.site.com/auth/google',
                    code=self.get_argument('code')
                )
                # Save the user with e.g. set_secure_cookie
            else:
                yield self.authorize_redirect(
                    redirect_uri='http://your.site.com/auth/google',
                    client_id=self.settings['google_oauth']['key'],
                    scope=['profile', 'email'],
                    response_type='code',
                    extra_params={'approval_prompt': 'auto'}
错误:

class GoogleOAuth2LoginHandler(tornado.web.RequestHandler, tornado.auth.GoogleOAuth2Mixin):
    @tornado.gen.coroutine
        def get(self):
            if self.get_argument('code', False):
                user = yield self.get_authenticated_user(
                    redirect_uri='http://your.site.com/auth/google',
                    code=self.get_argument('code')
                )
                # Save the user with e.g. set_secure_cookie
            else:
                yield self.authorize_redirect(
                    redirect_uri='http://your.site.com/auth/google',
                    client_id=self.settings['google_oauth']['key'],
                    scope=['profile', 'email'],
                    response_type='code',
                    extra_params={'approval_prompt': 'auto'}
谷歌认证错误:HTTPResponse(_body=None,buffer=,code=400,effective_url='',error=HTTPError('HTTP 400:Bad Request',),headers={'X-Consumed-Content-Encoding':'gzip','Alternate Protocol':'443:quic,p=1','X-Xss-Protection':'1;mode=block','X-Content-Type-Options':'nosniff','Transfer-Encoding':'chunked','Set-Cookie':'NID=76=iaY_jJFPzvLg3 H3EQUFMT4FECTBELKK9_BGJJJJJJJJJU-MWSBNLXEDQSRTMPYAZSRJ3MDGTDNZSWNSW5U FJIF8GCUAEGOGNGXGI5PCF0VEWUKIO;google=F599ORS域.com;Path=/;Expires=Sat,2016年8月13日10:17:46格林威治标准时间;HttpOnly“,”Expires“:”Fri,2016年2月12日10:17:46格林威治标准时间“,”Server“:”GSE“,”Connection“,”close“,”Cache Control“:”private,max age=0“,”Date“:”Fri,2016年2月12日10:17:46格林威治标准时间“,”P3p“:”CP=”这不是P3p政策!有关更多信息,请参阅“,”Alt Svc“:”quic=“:443”;ma=604800;v=“30,29,28,26,25”','Content Type':'application/json;charset=utf-8','X-Frame-Options':'SAMEORIGIN'},reason='Bad Request',Request=,Request_time=0.4158029556274414,time_info={})


我们在完全相同的配置(Tornado+nginx+angularjs)中遇到了相同的问题。我刚刚在没有Tornado的情况下重写了OAuth身份验证部分,问题得到了解决。您可以使用Tornado的AsyncHttpClient,但我使用了aiohttp,因为我在asyncio中托管了Tornado。 以下是新代码,注释部分是旧代码

from backend.helpers.async_oauth2.client import Client

        oauth_client = Client(app_settings.security.google.client_id, app_settings.security.google.client_secret,
                              app_settings.security.google.redirect_uri, "https://accounts.google.com/o/oauth2/auth"
                              , "https://accounts.google.com/o/oauth2/token")

        access = await oauth_client.get_token(code, grant_type="authorization_code")

        # access = await self.get_authenticated_user(
        #     redirect_uri=app_settings.security.google.redirect_uri,
        #     code=code)

        # user = await self.oauth2_request(
        #     "https://www.googleapis.com/oauth2/v1/userinfo",
        #     access_token=str(access["access_token"]))

        user = await oauth_client.http_get(
            "https://www.googleapis.com/oauth2/v1/userinfo?{}".format(
                url_parse.urlencode({'access_token':str(access["access_token"])})))

请帮帮我。。