2012-06-21 146 views
2

我正在使用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重定向聲明?不返回帶你回到調用函數。該身份驗證處理程序正在由登錄decorater調用。另外在/ auth/login中next的意義是什麼?next =在大多數例子中。

回答

4

是的,你需要重定向自己。 _on_auth被異步調用,因此return不會帶您進入調用函數:已經完成並且已經離開了!

關於/auth/login?next=xxx,下一個參數被設置爲請求首先被重定向到登錄頁面的起始頁面。它被使用一次_on_auth成功重定向到它。

截至_on_auth末,與重定向:

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

如果'下一= HTTP會發生什麼:// target.com/annoythem'?這不是一個安全的輕微問題嗎?也許'下一個'應該檢查是相對的? –