示例#1
0
 function runTest()
 {
     $http_response = null;
     $y = Services_Yadis_Yadis::discover($this->input_url, $http_response, Services_Yadis_Yadis::getHTTPFetcher());
     $this->assertTrue($y !== null);
     // Compare parts of returned Yadis object to expected URLs.
     $this->assertEquals($this->redir_uri, $y->uri);
     if ($this->xrds_uri) {
         $this->assertEquals($this->xrds_uri, $y->xrds_uri);
         // Compare contents of actual HTTP GET with that of Yadis
         // response.
         $f = Services_Yadis_Yadis::getHTTPFetcher();
         $response = $f->get($this->xrds_uri);
         $this->assertEquals($response->body, $y->body);
     } else {
         $this->assertTrue($y->xrds_uri === null);
     }
 }
示例#2
0
function Auth_OpenID_discoverWithYadis($uri, &$fetcher)
{
    // Discover OpenID services for a URI. Tries Yadis and falls back
    // on old-style <link rel='...'> discovery if Yadis fails.
    // 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.
    $openid_services = array();
    $http_response = null;
    $response = Services_Yadis_Yadis::discover($uri, $http_response, $fetcher);
    if ($response) {
        $identity_url = $response->uri;
        $openid_services = $response->xrds->services(array('filter_MatchesAnyOpenIDType'));
    }
    if (!$openid_services) {
        return @Auth_OpenID_discoverWithoutYadis($uri, $fetcher);
    }
    if (!$openid_services) {
        $body = $response->body;
        // Try to parse the response as HTML to get OpenID 1.0/1.1
        // <link rel="...">
        $service = Auth_OpenID_ServiceEndpoint::fromHTML($identity_url, $body);
        if ($service !== null) {
            $openid_services = array($service);
        }
    } else {
        $openid_services = Auth_OpenID_makeOpenIDEndpoints($response->uri, $openid_services);
    }
    return array($identity_url, $openid_services, $http_response);
}
示例#3
0
 public function getOpenIDEndpoint()
 {
     //Try Yadis Protocol discovery first
     $http_response = array();
     $fetcher = Services_Yadis_Yadis::getHTTPFetcher();
     $yadis_object = Services_Yadis_Yadis::discover($this->openid_url_identity, $http_response, $fetcher);
     // Yadis object is returned if discovery is successful
     if ($yadis_object != NULL) {
         $service_list = $yadis_object->services();
         $service_types = $service_list[0]->getTypes();
         $servers = $service_list[0]->getURIs();
         $delegates = $service_list[0]->getElements('openid:Delegate');
     } else {
         $response = $this->makeCURLRequest($this->openid_url_identity);
         list($servers, $delegates) = $this->parseHTML($response);
     }
     // If no servers were discovered by Yadis or by parsing HTML, error out
     if (empty($servers)) {
         $this->errorStore('OPENID_NOSERVERSFOUND');
         return FALSE;
     }
     // If $service_type has at least one non-null character
     if (isset($service_types[0]) && $service_types[0] != "") {
         $this->setServiceType($service_types[0]);
     }
     // If $delegates has at least one non-null character
     if (isset($delegates[0]) && $delegates[0] != "") {
         $this->setIdentity($delegates[0]);
     }
     $this->setOpenIDEndpoint($servers[0]);
     return $servers[0];
 }
示例#4
0
 function GetOpenIDServer()
 {
     //Try Yadis Protocol discovery first
     $http_response = array();
     $fetcher = Services_Yadis_Yadis::getHTTPFetcher();
     $yadis_object = Services_Yadis_Yadis::discover($this->openid_url_identity, $http_response, $fetcher);
     $yadis = 0;
     // Yadis object is returned if discovery is successful
     if ($yadis_object != null) {
         $service_list = $yadis_object->services();
         $types = $service_list[0]->getTypes();
         $servers = $service_list[0]->getURIs();
         $delegates = $service_list[0]->getElements('openid:Delegate');
         $yadis = 1;
     }
     if (count($servers) == 0) {
         $response = $this->CURL_Request($this->openid_url_identity);
         list($servers, $delegates) = $this->HTML2OpenIDServer($response);
     }
     if (count($servers) == 0) {
         $curl = curl_init($this->openid_url_identity);
         // workaround CURLOPT_FOLLOWLOCATION not working on some hosts
         // need to use this elsewhere, OMB remote-subscribe etc XXX
         // curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
         curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
         curl_setopt($curl, CURLOPT_HTTPGET, true);
         $response = curl_redir_exec($curl);
         list($servers, $delegates) = $this->HTML2OpenIDServer($response);
     }
     if (count($servers) == 0) {
         $this->ErrorStore('OPENID_NOSERVERSFOUND', 'response = ' . $response . '<br /><br />openid = ' . $this->openid_url_identity . '<br /><br />yadis object = ' . serialize($yadis_object) . '<br /><br />fetcher = ' . serialize($fetcher) . '<br /><br />service_list = ' . serialize($service_list));
         return false;
     }
     if (empty($servers[0])) {
         if ($yadis) {
             trigger_error('Yadis object was found but getURIs() failed for OpenID: ' . $this->openid_url_identity . '<br /><br />' . $this->error, E_USER_ERROR);
         } else {
             trigger_error('No Yadis object found, CURL_Request failed for OpenID: ' . $this->openid_url_identity . ' and the response was ' . $response . '<br /><br />' . $this->error, E_USER_ERROR);
         }
     }
     if (isset($types[0]) && $types[0] != "") {
         $this->SetServiceType($types[0]);
     }
     if (isset($delegates[0]) && $delegates[0] != "") {
         $this->SetIdentity($delegates[0]);
     }
     $this->SetOpenIDServer($servers[0]);
     return $servers[0];
 }
示例#5
0
 function runTest()
 {
     if ($this->expected === null) {
         $response = array();
         $this->assertTrue(Services_Yadis_Yadis::discover($this->input_url, $response, $this->fetcher) === null);
     } else {
         $response = array();
         $result = Services_Yadis_Yadis::discover($this->input_url, $response, $this->fetcher);
         if ($result === null) {
             $this->fail("Discovery result was null");
             return;
         }
         $this->assertEquals($this->input_url, $result->request_uri);
         $msg = 'Identity URL mismatch: actual = %s, expected = %s';
         $msg = sprintf($msg, $result->uri, $this->expected->uri);
         $this->assertEquals($this->expected->uri, $result->uri, $msg);
         $msg = 'Content mismatch: actual = %s, expected = %s';
         $msg = sprintf($msg, $result->body, $this->expected->body);
         $this->assertEquals($this->expected->body, $result->body, $msg);
         $this->assertEquals($this->expected->xrds_uri, $result->xrds_uri);
         $this->assertEquals($this->expected->content_type, $result->content_type);
     }
 }