### 第三方認證
Tornado 的 `auth` 模塊實現了現在很多流行站點的用戶認證方式,包括 Google/Gmail、Facebook、Twitter、Yahoo 以及 FriendFeed。這個模塊可以讓用戶使用 這些站點的賬戶來登陸你自己的應用,然后你就可以在授權的條件下訪問原站點的一些服 務,比如下載用戶的地址薄,在 Twitter 上發推等。
下面的例子使用了 Google 的賬戶認證,Google 賬戶的身份被保存到 cookie 當中,以便 以后的訪問使用:
```
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._on_auth)
return
self.authenticate_redirect()
def _on_auth(self, user):
if not user:
self.authenticate_redirect()
return
# Save the user with, e.g., set_secure_cookie()
```
請查看 `auth` 模塊的代碼文檔以了解更多的細節。