2010-03-20 38 views
1

我正嘗試使用django-socialauth(http://github.com/uswaretech/Django-Socialauth)爲我的django項目驗證用戶身份。Django&google openid認證(openid.ax)與socialauth

這是第一次使用openid,我不得不弄清楚這個開放ID是如何工作的。到現在爲止,我已經或多或少地瞭解了這一點,但幾乎沒有什麼能夠避開我。

驗證過程在請求放入django-socialauth.openid_consumer.views.begin時開始。我可以看到,即將離任的認證請求或多或少是這樣的:

https://www.google.com/accounts/o8/ud?openid.assoc_handle=AOQobUckRThPUj3K1byG280Aze-dnfc9Iu6AEYaBwvHE11G0zy8kY8GZ& 
openid.ax.if_available=fname& 
openid.ax.mode=fetch_request& 
openid.ax.required=email& 
openid.ax.type.email=http://axschema.org/contact/email& 
openid.ax.type.fname=http://example.com/schema/fullname& 
openid.claimed_id=http://specs.openid.net/auth/2.0/identifier_select& 
openid.identity=http://specs.openid.net/auth/2.0/identifier_select& 
openid.mode=checkid_setup&openid.ns=http://specs.openid.net/auth/2.0& 
openid.ns.ax=http://openid.net/srv/ax/1.0& 
openid.ns.sreg=http://openid.net/extensions/sreg/1.1& 
openid.realm=http://localhost/& 
openid.return_to=http://localhost/social/gmail_login/complete/?janrain_nonce=2010-03-20T11%3A19%3A44ZPZCjNc&openid.sreg.optional=postcode,country,nickname,email 

這是很多像第二個示例在這裏: http://code.google.com/apis/accounts/docs/OpenID.html#Samples

的問題是,該請求,我回來,是完全不像從code.google.com相應的例子(看第三個例子在例如響應響應字典我得到的是這樣的:

{ 
'openid.op_endpoint': 'https://www.google.com/accounts/o8/ud', 
'openid.sig': 'QWMa4x4ruMUvSCfLwKV6CZRuo0E=', 
'openid.ext1.type.email': 'http://axschema.org/contact/email', 
'openid.return_to': 'http://localhost/social/gmail_login/complete/?janrain_nonce=2010-03-20T17%3A54%3A06ZHV4cqh', 
'janrain_nonce': '2010-03-20T17:54:06ZHV4cqh', 
'openid.response_nonce': '2010-03-20T17:54:06ZdC5mMu9M_6O4pw', 
'openid.claimed_id': 'https://www.google.com/accounts/o8/id?id=AItOghawkFz0aNzk91vaQWhD-DxRJo6sS09RwM3SE', 
'openid.mode': 'id_res', 
'openid.ns.ext1': 'http://openid.net/srv/ax/1.0', 
'openid.signed': 'op_endpoint,claimed_id,identity,return_to,response_nonce,assoc_handle,ns.ext1,ext1.mode,ext1.type.email,ext1.value.email', 
'openid.ext1.value.email': '[email protected]', 
'openid.assoc_handle': 'AOQobUfssTJ2IxRlxrIvU4Xg8HHQKKTEuqwGxvwwuPR5rNvag0elGlYL', 
'openid.ns': 'http://specs.openid.net/auth/2.0', 
'openid.identity': 'https://www.google.com/accounts/o8/id?id=AItOawkghgfhf1FkvaQWhD-DxRJo6sS09RwMKjASE', 
'openid.ext1.mode': 'fetch_response'} 

的socialauth本身已建成,接受我的電子郵件地址,該W ay:

elif request.openid and request.openid.ax: 
     email = request.openid.ax.get('email') 

顯然這失敗了。

爲什麼我問這一切是,也許我做錯了什麼,我的傳出請求是錯誤的?或者我正確地做了所有事情,並且應該改變社交模塊以新的方式接受信息,然後進行修改?

艾倫

回答

1

嘗試使用完整的屬性URI在ax.get,即ax.get('http://axschema.org/contact/email')

+0

Hehh,我認爲這將是比這更復雜的....你的解決方案几乎是完全正確的。必須這樣做: email = request.openid.ax.get('http://axschema.org/contact/email')[0] 因爲它返回列表 – 2010-03-21 07:02:21