def discoverYadis(uri): """Discover OpenID services for a URI. Tries Yadis and falls back on old-style <link rel='...'> discovery if Yadis fails. @param uri: normalized identity URL @type uri: six.text_type, six.binary_type is deprecated @return: (claimed_id, services) @rtype: (six.text_type, list(OpenIDServiceEndpoint)) @raises DiscoveryFailure: when discovery fails. """ uri = string_to_text( uri, "Binary values for discoverYadis are deprecated. Use text input instead." ) # Might raise a yadis.discover.DiscoveryFailure if no document # came back for that URI at all. I don't think falling back # to OpenID 1.0 discovery on the same URL will help, so don't # bother to catch it. response = yadisDiscover(uri) yadis_url = response.normalized_uri body = response.response_text try: openid_services = OpenIDServiceEndpoint.fromXRDS(yadis_url, body) except XRDSError: # Does not parse as a Yadis XRDS file openid_services = [] if not openid_services: # Either not an XRDS or there are no OpenID services. if response.isXRDS(): # if we got the Yadis content-type or followed the Yadis # header, re-fetch the document without following the Yadis # header, with no Accept header. return discoverNoYadis(uri) # Try to parse the response as HTML. # <link rel="..."> openid_services = OpenIDServiceEndpoint.fromHTML(yadis_url, body) return (yadis_url, getOPOrUserServices(openid_services))
def discoverYadis(uri): """Discover OpenID services for a URI. Tries Yadis and falls back on old-style <link rel='...'> discovery if Yadis fails. @param uri: normalized identity URL @type uri: str @return: (claimed_id, services) @rtype: (str, list(OpenIDServiceEndpoint)) @raises: DiscoveryFailure """ # Might raise a yadis.discover.DiscoveryFailure if no document # came back for that URI at all. I don't think falling back # to OpenID 1.0 discovery on the same URL will help, so don't # bother to catch it. response = yadisDiscover(uri) yadis_url = response.normalized_uri try: openid_services = extractServices( response.normalized_uri, response.response_text, OpenIDServiceEndpoint) except XRDSError: # Does not parse as a Yadis XRDS file openid_services = [] if not openid_services: # Either not an XRDS or there are no OpenID services. if response.isXRDS(): # if we got the Yadis content-type or followed the Yadis # header, re-fetch the document without following the Yadis # header, with no Accept header. return discoverNoYadis(uri) else: body = response.response_text # Try to parse the response as HTML to get OpenID 1.0/1.1 # <link rel="..."> openid_services = OpenIDServiceEndpoint.fromHTML(yadis_url, body) return (yadis_url, getOPOrUserServices(openid_services))