刚开始玩 Tornado 并希望提供多种身份验证方法。目前,我的应用使用 tornado.auth.GoogleMixin 与 Google 的混合 OpenID/oAuth 配合良好,未经身份验证的用户会自动发送到 Google 的身份验证页面。
如果未经身份验证的用户想要使用另一个选项(即本地身份验证或 tornado.auth.TwitterMixin),我如何实现逻辑以在登录处理程序中选择身份验证机制?
我将装饰器“tornado.web.authenticated”添加到所有公开的方法中,这是我的登录处理程序类(几乎直接来自 Tornado 示例),目前正在使用 Google OpenID/oAuth:
class AuthLoginHandler(BaseHandler, 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
## redirect after auth
self.authenticate_redirect()
def _on_auth(self, user):
## auth fail
if not user:
raise tornado.web.HTTPError(500, 'Google auth failed')
## auth success
identity = self.get_argument('openid.identity', None)
## set identity in cookie
self.set_secure_cookie('identity', tornado.escape.json_encode(identity))
self.redirect('/')
感谢任何有关解决方案的建议。谢谢