简体   繁体   中英

Tornado google oauth error

I have the next problem with tornado.oauth : when user logs in with Google,Google sends me code to my redirect uri and then I try to get some information about user with the function get_authenticated_user

class GoogleOAuth2CodeHandler(tornado.web.RequestHandler,
                           tornado.auth.GoogleOAuth2Mixin):
    @tornado.gen.coroutine
    def get(self):
        user =yield self.get_authenticated_user(
            redirect_uri='http://localhost:8890/userdata',
            code=self.get_argument("code")
        )
        self.write("hello world!")

but it fails with the next error:

ERROR:tornado.application:Uncaught exception GET
KeyError: 'google_oauth'

Settings:

settings = dict(
        cookie_secret="32oETzKXQAGaYdkL5gEmGeJJFuYh7EQnp2XdTP1o/Vo=",
        login_url="/auth/login",
        redirect_uri="http://localhost:8890/auth",
        google_consumer_key="",
        google_consumer_secret="",
        google_permissions="https://mail.google.com/ https://www.google.com/m8/feeds",
        google_permissions2="https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email"
    ))

consumer_key and consumer_secret are correct authorize_redirect works correctly and I really get correct google code

google_consumer_key and google_consumer_secret are from the OAuth1 Google mixin. For oauth2, you need a google_oauth setting, which should be a dict containing 'key' and 'secret' fields:

  google_oauth={"key": CLIENT_ID, "secret": CLIENT_SECRET},

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM