summaryrefslogtreecommitdiffstats
path: root/Auth/OpenID
diff options
context:
space:
mode:
authortailor <cygnus@janrain.com>2006-05-08 20:28:23 +0000
committertailor <cygnus@janrain.com>2006-05-08 20:28:23 +0000
commit4db77595677049b2d4772bc430ec875a5a5f8658 (patch)
treed941fb2315a081f914de37cc320145b7552c4fba /Auth/OpenID
parent7a7293ab95d51daccd2b1c5809ffa8392bf0e802 (diff)
downloadphp-openid-4db77595677049b2d4772bc430ec875a5a5f8658.zip
php-openid-4db77595677049b2d4772bc430ec875a5a5f8658.tar.gz
php-openid-4db77595677049b2d4772bc430ec875a5a5f8658.tar.bz2
[project @ Added discovery unit tests and fixed other bugs.]
Diffstat (limited to 'Auth/OpenID')
-rw-r--r--Auth/OpenID/Discover.php28
-rw-r--r--Auth/OpenID/HTTPFetcher.php11
-rw-r--r--Auth/OpenID/ParanoidHTTPFetcher.php6
-rw-r--r--Auth/OpenID/PlainHTTPFetcher.php5
4 files changed, 34 insertions, 16 deletions
diff --git a/Auth/OpenID/Discover.php b/Auth/OpenID/Discover.php
index 5fd2aa0..1b5aaaa 100644
--- a/Auth/OpenID/Discover.php
+++ b/Auth/OpenID/Discover.php
@@ -120,7 +120,7 @@ function filter_MatchesAnyOpenIDType(&$service)
return false;
}
-function Auth_OpenID_discoverWithYadis($uri)
+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.
@@ -131,15 +131,19 @@ function Auth_OpenID_discoverWithYadis($uri)
// to catch it.
$openid_services = array();
- $response = @Services_Yadis_Yadis::discover($uri);
+ $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'));
- } else {
+ }
+
+ if (!$openid_services) {
return @Auth_OpenID_discoverWithoutYadis($uri,
- Auth_OpenID::getHTTPFetcher());
+ $fetcher);
}
if (!$openid_services) {
@@ -179,38 +183,38 @@ function Auth_OpenID_discoverWithYadis($uri)
$openid_services = $s;
}
- return array($identity_url, $openid_services);
+ return array($identity_url, $openid_services, $http_response);
}
function Auth_OpenID_discoverWithoutYadis($uri, &$fetcher)
{
$http_resp = @$fetcher->get($uri);
- list($code, $url, $body) = $http_resp;
- if ($code != 200) {
- return null;
+ if ($http_resp->status != 200) {
+ return array(null, array(), $http_resp);
}
- $identity_url = $url;
+ $identity_url = $http_resp->final_url;
// Try to parse the response as HTML to get OpenID 1.0/1.1 <link
// rel="...">
$endpoint =& new Auth_OpenID_ServiceEndpoint();
- $service = $endpoint->fromHTML($identity_url, $body);
+ $service = $endpoint->fromHTML($identity_url, $http_resp->body);
if ($service === null) {
$openid_services = array();
} else {
$openid_services = array($service);
}
- return array($identity_url, $openid_services);
+ return array($identity_url, $openid_services, $http_resp);
}
function Auth_OpenID_discover($uri, &$fetcher)
{
global $_yadis_available;
+
if ($_yadis_available) {
- return @Auth_OpenID_discoverWithYadis($uri);
+ return @Auth_OpenID_discoverWithYadis($uri, $fetcher);
} else {
return @Auth_OpenID_discoverWithoutYadis($uri, $fetcher);
}
diff --git a/Auth/OpenID/HTTPFetcher.php b/Auth/OpenID/HTTPFetcher.php
index fb6d1ab..f84e9ab 100644
--- a/Auth/OpenID/HTTPFetcher.php
+++ b/Auth/OpenID/HTTPFetcher.php
@@ -18,6 +18,17 @@
require_once "Auth/OpenID/Parse.php";
require_once "Auth/OpenID.php";
+class Auth_OpenID_HTTPResponse {
+ function Auth_OpenID_HTTPResponse($final_url = null, $status = null,
+ $headers = null, $body = null)
+ {
+ $this->final_url = $final_url;
+ $this->status = $status;
+ $this->headers = $headers;
+ $this->body = $body;
+ }
+}
+
/**
* This is the status code beginAuth returns when it is unable to
* fetch the OpenID URL the user entered.
diff --git a/Auth/OpenID/ParanoidHTTPFetcher.php b/Auth/OpenID/ParanoidHTTPFetcher.php
index c84457b..c4e11cb 100644
--- a/Auth/OpenID/ParanoidHTTPFetcher.php
+++ b/Auth/OpenID/ParanoidHTTPFetcher.php
@@ -111,7 +111,8 @@ class Auth_OpenID_ParanoidHTTPFetcher extends Auth_OpenID_HTTPFetcher {
} else {
$redir = false;
curl_close($c);
- return array($code, $url, $body);
+ return new Services_Yadis_HTTPResponse($url, $code,
+ $headers, $body);
}
$off = $stop - time();
@@ -155,7 +156,8 @@ class Auth_OpenID_ParanoidHTTPFetcher extends Auth_OpenID_HTTPFetcher {
$body = $this->data;
curl_close($c);
- return array($code, $url, $body);
+ return new Auth_OpenID_HTTPResponse($url, $code,
+ $this->headers, $body);
}
}
diff --git a/Auth/OpenID/PlainHTTPFetcher.php b/Auth/OpenID/PlainHTTPFetcher.php
index afb5ace..9dd3600 100644
--- a/Auth/OpenID/PlainHTTPFetcher.php
+++ b/Auth/OpenID/PlainHTTPFetcher.php
@@ -118,7 +118,7 @@ class Auth_OpenID_PlainHTTPFetcher extends Auth_OpenID_HTTPFetcher {
$off = $stop - time();
}
- return array($code, $url, $body);
+ return new Auth_OpenID_HTTPResponse($url, $code, $headers, $body);
}
function post($url, $body)
@@ -203,7 +203,8 @@ class Auth_OpenID_PlainHTTPFetcher extends Auth_OpenID_HTTPFetcher {
$http_code = explode(" ", $headers[0]);
$code = $http_code[1];
- return array($code, $url, $response_body);
+ return new Auth_OpenID_HTTPResponse($url, $code,
+ $headers, $response_body);
}
}