gpt4 book ai didi

Tornado 认证

转载 作者:行者123 更新时间:2023-12-04 18:18:49 26 4
gpt4 key购买 nike

我正在使用 Tornado 与 twitter 等第三方进行身份验证。

我的登录处理程序看起来像这样

class AuthLoginHandler(BaseHandler, tornado.auth.TwitterMixin, tornado.web.RequestHandler):
@tornado.web.asynchronous
def get(self):
if self.get_argument('oauth_token', None):
self.get_authenticated_user(self.async_callback(self._on_auth))
return
self.authorize_redirect("/auth/login")
return

def _on_auth(self, user):
if not user:
raise tornado.web.HTTPError(500, "Twitter auth failed")
self.set_secure_cookie("user", tornado.escape.json_encode(user))
return

我的问题是,设置安全 cookie 后是否需要在 _on_auth 中使用重定向语句?不返回带您回到调用函数。登录装饰器正在调用此身份验证处理程序。在大多数示例中,/auth/login?next= 中的下一个含义是什么。

最佳答案

是的,您需要重定向自己。 _on_auth被异步调用,所以 return不会带你到调用函数:已经完成了,已经消失了!

关于/auth/login?next=xxx ,下一个参数设置为请求第一次重定向到登录页面的原始页面。使用一次_on_auth成功重定向到它。

_on_auth 结尾, 重定向:

self.redirect(self.get_argument('next', '/'))

关于 Tornado 认证,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11144312/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com