2011-03-21 65 views
0

我正在嘗試使用Tornado的聯合登錄庫來驗證用戶身份並獲取對他們的日曆,聯繫人和郵件的訪問權限。但是,當我收到「mydomain.dyndns.info要求您的Google帳戶中的某些信息」消息時,列出的唯一要點是「電子郵件地址」。隨後,當我在批准請求後檢查返回的用戶對象時,用戶對象沒有「access_token」屬性。Google聯合OAuth/OpenID與Tornado:爲什麼忽略我的範圍?

下面的代碼:

def get(self): 
    scope_list = ['https://mail.google.com/','http://www.google.com/m8/feeds/','http://www.google.com/calendar/feeds/'] 
    ... 
    self.authorize_redirect(scope_list, callback_uri=self._switch_command('auth_callback'), ax_attrs=["name","email"]) 
def _on_auth(self, user): 
    print 'in on auth' 
    if user: 
     self.set_the_user(user['email']) 
     session.set_data('usertoken_' + user['email'], user['access_token']) 
    self.redirect('/') 

這個吐出URI是:

https://www.google.com/accounts/o8/ud 
?openid.ns=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0 
&openid.claimed_id=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select 
&openid.identity=http%3A%2F%2Fspecs.openid.net%2Fauth%2F2.0%2Fidentifier_select 
&openid.return_to=http%3A%2F%2Fmydomain.dyndns.info%3A333%2Fauth%2Fauth_callback%3Fperms%3Dgmail%26perms%3Dcontacts%26perms%3Dcalendar 
&openid.realm=http%3A%2F%2Fmydomain.dyndns.info%3A333%2F 
&openid.mode=checkid_setup 
&openid.ns.oauth=http%3A%2F%2Fspecs.openid.net%2Fextensions%2Foauth%2F1.0 
&openid.oauth.consumer=mydomain.dyndns.info 
&openid.oauth.scope=https%3A%2F%2Fmail.google.com%2F+http%3A%2F%2Fwww.google.com%2Fm8%2Ffeeds%2F+http%3A%2F%2Fwww.google.com%2Fcalendar%2Ffeeds%2F 
&openid.ns.ax=http%3A%2F%2Fopenid.net%2Fsrv%2Fax%2F1.0 
&openid.ax.type.fullname=http%3A%2F%2Faxschema.org%2FnamePerson 
&openid.ax.type.lastname=http%3A%2F%2Faxschema.org%2FnamePerson%2Flast 
&openid.ax.type.firstname=http%3A%2F%2Faxschema.org%2FnamePerson%2Ffirst 
&openid.ax.mode=fetch_request 
&openid.ax.type.email=http%3A%2F%2Faxschema.org%2Fcontact%2Femail 
&openid.ax.required=firstname%2Cfullname%2Clastname%2Cemail 

思路:1,也許這已經是與我在本地運行的事實機器在dyndns貨代後面? 2. Tornado的文檔中提到「使用Google進行身份驗證或代表用戶訪問Google資源時,不需要進行應用程序註冊」 - 但是這可能不再是真的?

如果有人有想法,我會非常感激 - 這會讓我有點慌張!

回答

0

想通了。您必須設置應用程序屬性google_consumer_key和google_consumer_secret。 https://www.google.com/accounts/ManageDomains

application = tornado.web.Application(urlhandlers, cookie_secret=cookie_secret, google_consumer_key=google_consumer_key, google_consumer_secret=google_consumer_secret) 

您可以通過去讓他們在這裏