Example #1
0
 function setUp()
 {
     $this->proxy_url = 'http://xri.example.com/';
     $this->fetcher = Services_Yadis_Yadis::getHTTPFetcher();
     $this->proxy = new Services_Yadis_ProxyResolver($fetcher, $this->proxy_url);
     $this->servicetype = 'xri://+i-service*(+forwarding)*($v*1.0)';
     $this->servicetype_enc = 'xri%3A%2F%2F%2Bi-service%2A%28%2Bforwarding%29%2A%28%24v%2A1.0%29';
 }
Example #2
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);
     }
 }
 /**
  * This should be called statically and will build a Yadis
  * instance if the discovery process succeeds.  This implements
  * Yadis discovery as specified in the Yadis specification.
  *
  * @param string $uri The URI on which to perform Yadis discovery.
  *
  * @param array $http_response An array reference where the HTTP
  * response object will be stored (see {@link
  * Services_Yadis_HTTPResponse}.
  *
  * @param Services_Yadis_HTTPFetcher $fetcher An instance of a
  * Services_Yadis_HTTPFetcher subclass.
  *
  * @param array $extra_ns_map An array which maps namespace names
  * to namespace URIs to be used when parsing the Yadis XRDS
  * document.
  *
  * @param integer $timeout An optional fetcher timeout, in seconds.
  *
  * @return mixed $obj Either null or an instance of
  * Services_Yadis_Yadis, depending on whether the discovery
  * succeeded.
  */
 function discover($uri, &$http_response, &$fetcher, $extra_ns_map = null, $timeout = 20)
 {
     if (!$uri) {
         return null;
     }
     $request_uri = $uri;
     $headers = array("Accept: application/xrds+xml");
     if (!$fetcher) {
         $fetcher = Services_Yadis_Yadis::getHTTPFetcher($timeout);
     }
     $response = $fetcher->get($uri, $headers);
     $http_response = $response;
     if (!$response) {
         return null;
     }
     if ($response->status != 200) {
         return null;
     }
     $xrds_uri = $response->final_url;
     $uri = $response->final_url;
     $body = $response->body;
     $xrds_header_uri = Services_Yadis_Yadis::_getHeader($response->headers, array('x-xrds-location', 'x-yadis-location'));
     $content_type = Services_Yadis_Yadis::_getHeader($response->headers, array('content-type'));
     if ($xrds_header_uri) {
         $xrds_uri = $xrds_header_uri;
         $response = $fetcher->get($xrds_uri);
         $http_response = $response;
         if (!$response) {
             return null;
         } else {
             $body = $response->body;
             $headers = $response->headers;
             $content_type = Services_Yadis_Yadis::_getHeader($headers, array('content-type'));
         }
     }
     if (Services_Yadis_Yadis::_getContentType($content_type) != 'application/xrds+xml') {
         // Treat the body as HTML and look for a META tag.
         $parser = new Services_Yadis_ParseHTML();
         $new_uri = $parser->getHTTPEquiv($body);
         $xrds_uri = null;
         if ($new_uri) {
             $response = $fetcher->get($new_uri);
             if ($response->status != 200) {
                 return null;
             }
             $http_response = $response;
             $body = $response->body;
             $xrds_uri = $new_uri;
             $content_type = Services_Yadis_Yadis::_getHeader($response->headers, array('content-type'));
         }
     }
     $xrds = Services_Yadis_XRDS::parseXRDS($body, $extra_ns_map);
     if ($xrds !== null) {
         $y = new Services_Yadis_Yadis();
         $y->request_uri = $request_uri;
         $y->xrds = $xrds;
         $y->uri = $uri;
         $y->xrds_uri = $xrds_uri;
         $y->body = $body;
         $y->content_type = $content_type;
         return $y;
     } else {
         return null;
     }
 }
Example #4
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);
}
Example #5
0
 /**
  * This method initializes a new {@link Auth_OpenID_Consumer}
  * instance to access the library.
  *
  * @param Auth_OpenID_OpenIDStore $store This must be an object
  * that implements the interface in {@link Auth_OpenID_OpenIDStore}.
  * Several concrete implementations are provided, to cover most common use
  * cases.  For stores backed by MySQL, PostgreSQL, or SQLite, see
  * the {@link Auth_OpenID_SQLStore} class and its sublcasses.  For a
  * filesystem-backed store, see the {@link Auth_OpenID_FileStore} module.
  * As a last resort, if it isn't possible for the server to store
  * state at all, an instance of {@link Auth_OpenID_DumbStore} can be used.
  *
  * @param bool $immediate This is an optional boolean value.  It
  * controls whether the library uses immediate mode, as explained
  * in the module description.  The default value is False, which
  * disables immediate mode.
  */
 function Auth_OpenID_GenericConsumer(&$store)
 {
     $this->store =& $store;
     $this->_use_assocs = !(defined('Auth_OpenID_NO_MATH_SUPPORT') || $this->store && $this->store->isDumb());
     $this->fetcher = Services_Yadis_Yadis::getHTTPFetcher();
 }
Example #6
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];
 }
Example #7
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];
 }
Example #8
0
function detect_fetcher($r, &$out)
{
    $out .= $r->h2('HTTP Fetching');
    $result = @(include 'Services/Yadis/Yadis.php');
    if (!$result) {
        $out .= $r->p('Yadis code unavailable; could not test fetcher support.');
        return false;
    }
    if (Services_Yadis_Yadis::curlPresent()) {
        $out .= $r->p('This PHP installation has support for libcurl. Good.');
    } else {
        $out .= $r->p('This PHP installation does not have support for ' . 'libcurl. CURL is not required, but some functionality, ' . 'such as fetching HTTPS URLs, will be missing and ' . ' performance will not be as good.');
        $lnk = $r->link('http://us3.php.net/manual/en/ref.curl.php');
        $out .= $r->p('See ' . $lnk . ' about enabling the libcurl support ' . 'for PHP.');
    }
    $ok = true;
    $fetcher = Services_Yadis_Yadis::getHTTPFetcher();
    $fetch_url = 'http://www.openidenabled.com/resources/php-fetch-test';
    $expected_url = $fetch_url . '.txt';
    $result = $fetcher->get($fetch_url);
    if (isset($result)) {
        $parts = array('An HTTP request was completed.');
        // list ($code, $url, $data) = $result;
        if ($result->status != '200') {
            $ok = false;
            $parts[] = $r->b(sprintf('Got %s instead of the expected HTTP status code ' . '(200).', $result->status));
        }
        $url = $result->final_url;
        if ($url != $expected_url) {
            $ok = false;
            if ($url == $fetch_url) {
                $msg = 'The redirected URL was not returned.';
            } else {
                $msg = 'An unexpected URL was returned: <' . $url . '>.';
            }
            $parts[] = $r->b($msg);
        }
        $data = $result->body;
        if ($data != 'Hello World!') {
            $ok = false;
            $parts[] = $r->b('Unexpected data was returned.');
        }
        $out .= $r->p(implode(' ', $parts));
    } else {
        $ok = false;
        $out .= $r->p('Fetching URL ' . $lnk . ' failed!');
    }
    return $ok;
}
Example #9
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);
     }
 }