代码之家  ›  专栏  ›  技术社区  ›  Markus Olsson

python openid和Google Apps联合登录时出错

  •  4
  • Markus Olsson  · 技术社区  · 16 年前

    更新

    --- python-openid-2.2.1.orig/openid/consumer/consumer.py
    +++ python-openid-2.2.1/openid/consumer/consumer.py
    @@ -229,6 +229,20 @@
         # Process response in separate function that can be shared by async code.
         return _httpResponseToMessage(resp, server_url)
    
    +def makeKVGet(request_message, server_url):
    +    """Make a Direct Request to an OpenID Provider and return the
    +    result as a Message object.
    +
    +    @raises openid.fetchers.HTTPFetchingError: if an error is
    +        encountered in making the HTTP post.
    +
    +    @rtype: L{openid.message.Message}
    +    """
    +    # XXX: TESTME
    +    resp = fetchers.fetch(request_message.toURL(server_url))
    +
    +    # Process response in separate function that can be shared by async code.
    +    return _httpResponseToMessage(resp, server_url)
    
     def _httpResponseToMessage(response, server_url):
         """Adapt a POST response to a Message.
    @@ -682,6 +696,7 @@
             return True
    
         _makeKVPost = staticmethod(makeKVPost)
    +    _makeKVGet = staticmethod(makeKVGet)
    
         def _checkSetupNeeded(self, message):
             """Check an id_res message to see if it is a
    @@ -1258,7 +1273,7 @@
                 endpoint, assoc_type, session_type)
    
             try:
    -            response = self._makeKVPost(args, endpoint.server_url)
    +            response = self._makeKVGet(args, endpoint.server_url)
             except fetchers.HTTPFetchingError, why:
                 oidutil.log('openid.associate request failed: %s' % (why[0],))
                 return None
    
    

    保留旧问题的上下文

    trac-authopenid 插件工作,但没有运气。

    我们在工作中使用Google Apps Premier,所以我正在尝试让openid auth使用它。就谷歌而言,我想我已经设置了所有必需的东西(XRD等),并且我已经让它与apache2配合得很好+ mod-auth-openid

    但我似乎无法让它与trac authopenid一起工作。我被重定向(通过一个表单帖子,而不是像往常一样重定向)到谷歌,在那里我可以登录,但当我返回插件时,插件只是声明验证失败。

    如果我打开调试日志,我会得到这个(我已经用example.com替换了我们的域名)

    2010-01-27 12:21:15,811 Trac[authopenid] DEBUG: beginning OpenID authentication.
    2010-01-27 12:21:16,866 Trac[authopenid] DEBUG: kvToSeq warning: Line 1 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n
    2010-01-27 12:21:16,866 Trac[authopenid] DEBUG: kvToSeq warning: Line 2 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n
    2010-01-27 12:21:16,866 Trac[authopenid] DEBUG: kvToSeq warning: Line 3 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n
        ... snipped, repeats until line 9...
    2010-01-27 12:21:16,867 Trac[authopenid] DEBUG: openid.associate request failed: bad status code from server https://www.google.com/a/example.com/o8/ud?be=
    2010-01-27 12:21:16,868 Trac[authopenid] DEBUG: _get_trust_root href: /trac
    2010-01-27 12:21:16,868 Trac[authopenid] DEBUG: _get_trust_root abs_href: https://developer.example.com/trac
    2010-01-27 12:21:16,868 Trac[authopenid] DEBUG: _get_trust_root href: /trac
    2010-01-27 12:21:16,868 Trac[authopenid] DEBUG: _get_trust_root abs_href: https://developer.example.com/trac
    2010-01-27 12:21:16,869 Trac[authopenid] DEBUG: Generated checkid_setup request to https://www.google.com/a/example.com/o8/ud?be=o8 using stateless mode.
    2010-01-27 12:21:18,068 Trac[main] DEBUG: Dispatching <Request "GET u'/openidprocess'">
    2010-01-27 12:21:18,075 Trac[session] DEBUG: Retrieving session for ID '25a842642693232301aad341'
    2010-01-27 12:21:18,078 Trac[authopenid] DEBUG: Error attempting to use stored discovery information: <openid.consumer.consumer.TypeURIMismatch: Required ty
    2010-01-27 12:21:18,078 Trac[authopenid] DEBUG: Attempting discovery to verify endpoint
    2010-01-27 12:21:18,078 Trac[authopenid] DEBUG: Performing discovery on http://example.com/openid?id=113663311178245814720
    2010-01-27 12:21:18,121 Trac[authopenid] DEBUG: Received id_res response from https://www.google.com/a/example.com/o8/ud?be=o8 using association AOQobUefon
    2010-01-27 12:21:18,121 Trac[authopenid] DEBUG: Using OpenID check_authentication
    2010-01-27 12:21:18,121 Trac[authopenid] DEBUG: op_endpoint
    2010-01-27 12:21:18,121 Trac[authopenid] DEBUG: claimed_id
    2010-01-27 12:21:18,121 Trac[authopenid] DEBUG: identity
    2010-01-27 12:21:18,122 Trac[authopenid] DEBUG: return_to
    2010-01-27 12:21:18,122 Trac[authopenid] DEBUG: response_nonce
    2010-01-27 12:21:18,122 Trac[authopenid] DEBUG: assoc_handle
    2010-01-27 12:21:18,576 Trac[authopenid] DEBUG: kvToSeq warning: Line 1 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n
    2010-01-27 12:21:18,577 Trac[authopenid] DEBUG: kvToSeq warning: Line 2 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n
    2010-01-27 12:21:18,577 Trac[authopenid] DEBUG: kvToSeq warning: Line 3 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n
        ... snipped, repeats until line 9...
    2010-01-27 12:21:18,578 Trac[authopenid] DEBUG: check_authentication failed: bad status code from server https://www.google.com/a/example.com/o8/ud?be=o8: 501
    

    我试着直接针对 python-openid

    from openid.store.memstore import MemoryStore
    from openid.consumer import consumer
    
    session = { 'id' : 'foobar' }
    store = MemoryStore()
    consumer = consumer.Consumer(session, store)
    consumer.begin('https://www.google.com/accounts/o8/site-xrds?hd=example.com')
    

    它始终输出

    kvToSeq warning: Line 1 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Not Implemented</H1>\n<H2>Error 501</H2>\n</BODY>\n</HTML>\n'
    kvToSeq warning: Line 2 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Not Implemented</H1>\n<H2>Error 501</H2>\n</BODY>\n</HTML>\n'
    kvToSeq warning: Line 3 does not contain a colon: '<HTML>\n<HEAD>\n<TITLE>Not Implemented</TITLE>\n</HEAD>\n<BODY BGCOLOR="#FFFFFF" TEXT="#000000">\n<H1>Not Implemented</H1>\n<H2>Error 501</H2>\n</BODY>\n</HTML>\n'
    ... snip ...
    openid.associate request failed: bad status code from server https://www.google.com/a/example.com/o8/ud?be=o8: 501
    

    一些版本号:

    Python 2.6.2
    trac-authopenid 0.1.6
    python-openid 2.2.1
    

    我完全不知所措,我真的需要一些帮助。

    2 回复  |  直到 16 年前
        1
  •  2
  •   keturn    16 年前

    可以我没有应用程序帐户,因此无法测试登录,但我可以使用python openid 2.2.4成功地与应用程序域关联。下面是一个用于发出关联请求的小调试工具: http://gist.github.com/288560

    你的补丁不应该有固定的东西; associate requests are always POSTs

    我正要问你关于这个问题 openid.store

    我想我留给你的唯一一件事就是建议你向谷歌应用客户支持部门咨询。

        2
  •  0
  •   Jacob Wan    15 年前

    您提到您正在使用Python 2.6.2 使用python openid。自述文件的“需求”部分 仅列出Python 2.3、2.4或2.5。很高兴听到你成功了。