示例#1
0
/**
 * Perform discovery on a claimed ID to determine the OpenID provider endpoint.
 *
 * @param $claimed_id The OpenID URL to perform discovery on.
 *
 * @return Array of services discovered (including OpenID version, endpoint
 * URI, etc).
 */
function openid_discovery($claimed_id)
{
    $services = array();
    $xrds_url = $claimed_id;
    if (_openid_is_xri($claimed_id)) {
        $xrds_url = 'http://xri.net/' . $claimed_id;
    }
    $url = @parse_url($xrds_url);
    if ($url['scheme'] == 'http' || $url['scheme'] == 'https') {
        // For regular URLs, try Yadis resolution first, then HTML-based discovery
        $headers = array('Accept' => 'application/xrds+xml');
        //TODO
        $result = openid_http_request($xrds_url, $headers);
        if (!isset($result->error)) {
            if (isset($result->headers['Content-Type']) && preg_match("/application\\/xrds\\+xml/", $result->headers['Content-Type'])) {
                // Parse XML document to find URL
                $services = xrds_parse($result->data);
            } else {
                $xrds_url = NULL;
                if (isset($result->headers['X-XRDS-Location'])) {
                    $xrds_url = $result->headers['X-XRDS-Location'];
                } else {
                    // Look for meta http-equiv link in HTML head
                    $xrds_url = _openid_meta_httpequiv('X-XRDS-Location', $result->data);
                }
                if (!empty($xrds_url)) {
                    $headers = array('Accept' => 'application/xrds+xml');
                    //TODO
                    $xrds_result = openid_http_request($xrds_url, $headers);
                    if (!isset($xrds_result->error)) {
                        $services = xrds_parse($xrds_result->data);
                    }
                }
            }
            // Check for HTML delegation
            if (count($services) == 0) {
                // Look for 2.0 links
                $uri = _openid_link_href('openid2.provider', $result->data);
                $delegate = _openid_link_href('openid2.local_id', $result->data);
                $version = 2;
                // 1.0 links
                if (empty($uri)) {
                    $uri = _openid_link_href('openid.server', $result->data);
                    $delegate = _openid_link_href('openid.delegate', $result->data);
                    $version = 1;
                }
                if (!empty($uri)) {
                    $services[] = array('uri' => $uri, 'delegate' => $delegate, 'version' => $version);
                }
            }
        }
    }
    return $services;
}
示例#2
0
 function descovery($claimed_id)
 {
     $services = array();
     $xrds_url = $claimed_id;
     $url = parse_url($xrds_url);
     print_r($url);
     if ($url['scheme'] == 'http' || $url['scheme'] == 'https') {
         //$headers = array('Accept' => 'Application/xrds+xml');
         $headers = array();
         $result = $this->http_request($xrds_url, $headers);
         echo "\r\n\r\nResult: \r\n";
         print_r($result);
         echo "\r\n\r\nEnd\r\n";
         if (!isset($result->error)) {
             if (isset($result->headers['Content-Type']) && preg_match("/application\\/xrds\\+xml/", $result->headers['Content-Type'])) {
                 // Parse XML document to find URL
                 // $service = xrds_parse($result->data);
             } else {
                 $xrds_url = null;
                 if (isset($result->headers['X-XRDS-Location'])) {
                     $xrds_url = $result->headers['X-XRDS-Location'];
                 } else {
                     // Look for meta http-equiv link in HTML head
                     $xrds_url = openid_meta_httpequiv('X-XRDS-Location', $result->data);
                 }
                 if (!empty($xrds_url)) {
                     //$headers = array('Accept' => 'application/xrds+xml');
                     $xrds_result = $this->http_request($xrds_url, $headers);
                     if (!isset($xrds_result->error)) {
                         $services = $this->xrds_parse($xrds_result->data);
                     }
                 }
             }
             if (count($services) == 0) {
                 // Look for 2.0 links
                 $uri = openid_link_href('openid2.provider', $result->data);
                 $delegate = openid_link_href('openid2.local_id', $result->data);
                 $version = 2;
                 // 1.0 Links
                 if (empty($url)) {
                     $uri = _openid_link_href('openid.provider', $result->data);
                     $delegate = openid_link_href('openid.local_id', $result->data);
                     $version = 1;
                 }
                 if (!empty($uri)) {
                     $services[] = array('uri' => $uri, 'delegate' => $delegate, 'version' => $version);
                 }
             }
         }
     }
     return $services;
 }