【问题标题】:Django & google openid authentication (openid.ax) with socialauthDjango & google openid 身份验证 (openid.ax) 与 socialauth
【发布时间】:2010-03-20 17:59:42
【问题描述】:

我正在尝试使用 django-socialauth (http://github.com/uswaretech/Django-Socialauth) 对我的 django 项目的用户进行身份验证。

这是第一次使用 openid,我必须弄清楚这个 open 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': 'my.emailaddress@gmail.com', 
'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 本身已构建为以这种方式接受我的电子邮件地址:

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

显然这失败了。

为什么我要问这一切,也许我做错了什么,我的传出请求是错误的?还是我做的一切都正确,应该更改 socialaouth 模块以以新的方式接受信息,然后提交更改?

艾伦

【问题讨论】:

    标签: django openid django-socialauth


    【解决方案1】:

    尝试在 ax.get 中使用完整的属性 URI,即 ax.get('http://axschema.org/contact/email')

    【讨论】:

    • 呵呵,我认为它会比这更复杂......你的解决方案几乎完全正确。必须这样做: email = request.openid.ax.get('axschema.org/contact/email')[0] 因为它返回了列表
    猜你喜欢
    • 2014-04-30
    • 2012-12-22
    • 1970-01-01
    • 2018-06-25
    • 1970-01-01
    • 2015-03-11
    • 2021-09-07
    • 2010-09-06
    • 2011-12-04
    相关资源
    最近更新 更多