在tornado python中设置openId
嘿大家...我一直在阅读龙卷风文档并遇到 open id mixin 所以我心想“我这边没有可怕的密码系统”然后我研究了如何实现它,我遇到的唯一例子是这个
class GoogleHandler(tornado.web.RequestHandler, tornado.auth.GoogleMixin):
@tornado.web.asynchronous
def get(self):
if self.get_argument("openid.mode", None):
self.get_authenticated_user(self.async_callback(self._on_auth))
return
self.authenticate_redirect()
def _on_auth(self, user):
if not user:
raise tornado.web.HTTPError(500, "Google auth failed")
它没有显示更大的图景,例如路线、应用程序设置等 # 使用例如 set_secure_cookie() 保存用户
所以我的问题是。这如何适应龙卷风站点的大局?
Hey all... I have been reading the tornado doc and came across open id mixin so I thought to myself "Wicked no horrid password system on my side" then I looked into how to implement it, the only example I came across was this
class GoogleHandler(tornado.web.RequestHandler, tornado.auth.GoogleMixin):
@tornado.web.asynchronous
def get(self):
if self.get_argument("openid.mode", None):
self.get_authenticated_user(self.async_callback(self._on_auth))
return
self.authenticate_redirect()
def _on_auth(self, user):
if not user:
raise tornado.web.HTTPError(500, "Google auth failed")
Which doesn't show the bigger picture, like routes, appsettings etc etc
# Save the user with, e.g., set_secure_cookie()
So my question is. How does this fit into the bigger picture that is a tornado site.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
该处理程序不依赖于应用程序的其他部分,您只需将其设置为 url conf 中的“/login/google”之类的内容,然后在网站上的某个位置放置指向该 url 的链接即可。
用户点击它并被重定向到谷歌身份验证页面(如果它已从谷歌注销)或请求授予访问他/她的基本信息权限的页面。如果用户接受 - 浏览器将重定向回此 url 处理程序,并且控制权转到 _on_auth 方法,其中用户对象(如果存在)包含一个包含用户电子邮件、姓名、位置设置和一堆其他内容的字典东西(只需将此变量转储到日志即可查看所有内容)。
此时,您可以对这些数据执行任何您想要的操作,但一般来说,它可能看起来像这样:
This handler does not depend on other parts of application, you just set it on something like '/login/google' in url conf and place a link to this url somewhere on your website.
User clicks on it and gets redirected to google auth page (if it's logged out of google) or to a page asking to grant permission to acces his/her basic info. If user accepts - browser gets redirected back on this url handler and control comes to _on_auth method, where the user object, if present, contains a dict with user's email, name, location settings and a bunch of other stuff (just dump this variable to logs to see all of it).
At this point you can do whatever you want with this data, but in general it can look something like this: