【问题标题】:Google Authentication using Tornado Web Framework(Python)使用 Tornado Web 框架(Python)的谷歌身份验证
【发布时间】:2015-03-28 14:33:23
【问题描述】:

我将 Tornado Web 框架用于其异步回调功能,并尝试在 Tornado 中使用 OAuth 设置 Google 身份验证。

目前,身份验证进入请求我访问数据的权限的步骤,然后出现No Data Received 屏幕,因为它无法与我的应用程序交换访问令牌。

【问题讨论】:

  • 到目前为止做了什么

标签: python tornado


【解决方案1】:

你能用一些代码更新你的问题吗?我可以根据错误或您更新的代码更新我的答案。

如果你想参考一些文档,你可以查看http://tornado.readthedocs.org/en/latest/auth.html

以下是可以帮助您的示例代码。

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'})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2022-01-27
    • 2012-09-20
    • 2020-08-15
    • 2018-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多