我正在使用Tornado Web Framework来实现其异步回拨功能,并尝试在Tornado中使用OAuth设置Google身份验证。
目前,身份验证会转到请求我访问数据的权限的步骤,然后会出现No Data Received
屏幕,因为它无法与我的应用程序交换访问令牌。
答案 0 :(得分:0)
你可以用一些代码更新你的问题吗?我可以根据您更新的错误或代码更新我的答案。
如果您想参考一些文档,可以查看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'})