python-openid不提供ax或sreg属性

我终于能够获得python-openid来对用户进行身份验证,但是由于它们以None的形式返回,因此我无法创建sreg.SRegResponse或ax.FetchResponse.这来自一个Google Apps帐户,我尝试按照https://github.com/openid/python-openid/tree/master/examples/djopenid的示例进行.我听说Google的OpenID系统可能有点时髦,需要进行一些调整,例如Retrieve OpenID AX attributes from Google / Yahoo in Rails

    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)

解决方法:

Google在返回AttributeExchange的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)
上一篇:python-使用Django的openid


下一篇:day87_11_7微信小程序之登录,支付,授权