python-openid不提供ax或sreg属性

3 投票
1 回答
1380 浏览
提问于 2025-04-16 17:30

我终于成功让python-openid认证用户了,但我却无法创建sreg.SRegResponse或ax.FetchResponse,因为它们返回的结果是None。这是从一个Google Apps账户来的,我正在尝试按照这个链接上的示例进行操作。我听说Google的OpenID系统有点奇怪,可能需要一些调整,比如从Google / Yahoo获取OpenID AX属性

    response = c.complete(request_args, return_to)

    sreg_response = sreg.SRegResponse.fromSuccessResponse(response)
    ax_response = ax.FetchResponse.fromSuccessResponse(response)

虽然响应确实返回的是SUCCESS,但我看到以下错误信息,可能和这个有关:

Generated checkid_setup request to https://www.google.com/accounts/o8/ud with assocication AOQobUdVBCrd-GZRcasn9tD-yOUF0Y8pJLAQrYXODqLxUUjN62G1BXR1
Error attempting to use stored discovery information: <openid.consumer.consumer.TypeURIMismatch: Required type http://specs.openid.net/auth/2.0/signon not found in ['http://specs.openid.net/auth/2.0/server', 'http://openid.net/srv/ax/1.0', 'http://specs.openid.net/extensions/ui/1.0/mode/popup', 'http://specs.openid.net/extensions/ui/1.0/icon', 'http://specs.openid.net/extensions/pape/1.0'] for endpoint <openid.consumer.discover.OpenIDServiceEndpoint server_url='https://www.google.com/accounts/o8/ud' claimed_id=None local_id=None canonicalID=None used_yadis=True >>
Attempting discovery to verify endpoint
Performing discovery on https://www.google.com/accounts/o8/id?id=AItOawkKU4uzJV9Q_FGMECNGsbiXG2caISYMyCw
Received id_res response from https://www.google.com/accounts/o8/ud using association AOQobUdVBCrd-GZRcasn9tD-yOUF0Y8pJLAQrYXODqLxUUjN62G1BXR1

这是我的设置。

           sreg_request = sreg.SRegRequest(optional=['email', 'nickname'],
                                        required=['dob'])
            auth_request.addExtension(sreg_request)

            # Add Attribute Exchange request information.
            ax_request = ax.FetchRequest()
            # XXX - uses myOpenID-compatible schema values, which are
            # not those listed at axschema.org.
            ax_request.add(ax.AttrInfo('http://schema.openid.net/namePerson',
                                       required=True))
            ax_request.add(ax.AttrInfo('http://schema.openid.net/contact/web/default',
                                       required=False, count=ax.UNLIMITED_VALUES))
            auth_request.addExtension(ax_request)

1 个回答

4

我在使用谷歌时遇到了问题,它没有返回schema.openid.net的值用于属性交换。就像你提到的,它返回的是None,最糟糕的是,当我最初写我的OpenID处理程序时,这个功能是可以正常工作的。

但当我在我的实现中切换到axschema的值时,一切都顺利了。比如:

    URLS = {
      'ax_email': 'http://axschema.org/contact/email',
      'ax_first': 'http://axschema.org/namePerson/first',
    }

    ...

    ax_request = ax.FetchRequest()
    ax_request.add(ax.AttrInfo(URLS['ax_email'], required = True))
    ax_request.add(ax.AttrInfo(URLS['ax_first'], required = True))

    auth_request.addExtension(ax_request)

撰写回答