summaryrefslogtreecommitdiffstats
path: root/Auth/OpenID
diff options
context:
space:
mode:
authorJosh Hoyt <josh@janrain.com>2006-02-11 01:37:41 +0000
committerJosh Hoyt <josh@janrain.com>2006-02-11 01:37:41 +0000
commitc80142d507320ddf67cd1fccebf6e4d37dda512d (patch)
tree7a9b7f1f68258af7cb1a76bd279500545505769e /Auth/OpenID
parent9d3850e9077fad084f6cc09b76ca6ce92f072ecc (diff)
downloadphp-openid-c80142d507320ddf67cd1fccebf6e4d37dda512d.zip
php-openid-c80142d507320ddf67cd1fccebf6e4d37dda512d.tar.gz
php-openid-c80142d507320ddf67cd1fccebf6e4d37dda512d.tar.bz2
[project @ Move the HTTPFetcher base class to its own module]
Diffstat (limited to 'Auth/OpenID')
-rw-r--r--Auth/OpenID/Consumer/Fetchers.php91
-rw-r--r--Auth/OpenID/HTTPFetcher.php112
-rw-r--r--Auth/OpenID/Server.php48
-rw-r--r--Auth/OpenID/ServerRequest.php1
-rw-r--r--Auth/OpenID/Util.php60
5 files changed, 183 insertions, 129 deletions
diff --git a/Auth/OpenID/Consumer/Fetchers.php b/Auth/OpenID/Consumer/Fetchers.php
index e9da502..661cc50 100644
--- a/Auth/OpenID/Consumer/Fetchers.php
+++ b/Auth/OpenID/Consumer/Fetchers.php
@@ -1,8 +1,7 @@
<?php
-
/**
- * This module contains the HTTP fetcher interface and several
- * implementations.
+ * This module contains HTTP fetcher implementations
+ * XXX pear fixes needed
*
* PHP versions 4 and 5
*
@@ -15,6 +14,11 @@
*/
/**
+ * Interface import
+ */
+require_once "Auth/OpenID/HTTPFetcher.php";
+
+/**
* Specify a socket timeout setting, in seconds.
*/
$_Auth_OpenID_socket_timeout = 20;
@@ -30,87 +34,14 @@ function Auth_OpenID_URLHasAllowedScheme($url)
}
/**
- * This class is the interface for HTTP fetchers the OpenID consumer
- * library uses. This interface is only important if you need to
- * write a new fetcher for some reason.
- *
- * @access private
- * @package OpenID
- */
-class Auth_OpenID_HTTPFetcher {
-
- /**
- * Return whether a URL should be allowed. Override this method to
- * conform to your local policy.
- *
- * By default, will attempt to fetch any http or https URL.
- */
- function allowedURL($url)
- {
- return Auth_OpenID_URLHasAllowedScheme($url);
- }
-
- /**
- * This performs an HTTP get, following redirects along the way.
- *
- * @return array $tuple This returns a three-tuple on success.
- * The first value is the http return code. The second value is
- * the final url that was fetched, after following any redirects.
- * The third value is the data that was retrieved from the site.
- * If the fetch didn't succeed, return null.
- */
- function get($url)
- {
- trigger_error("not implemented", E_USER_ERROR);
- }
-
- /**
- * This performs an HTTP post. If it makes sense, it will follow
- * redirects along the way.
- *
- * @return array $tuple This returns a three-tuple on success.
- * The first value is the http return code. The second value is
- * the final url that was fetched, after following any redirects.
- * The third value is the data that was retrieved from the site.
- * If the fetch didn't succeed, return null.
- */
- function post($url, $body)
- {
- trigger_error("not implemented", E_USER_ERROR);
- }
-
- function findIdentityInfo($identity_url)
- {
- $url = Auth_OpenID_normalizeURL($identity_url);
- $ret = @$this->get($url);
- if ($ret === null) {
- return array(Auth_OpenID_HTTP_FAILURE, null);
- }
-
- list($http_code, $consumer_id, $data) = $ret;
- if ($http_code != 200) {
- return array(Auth_OpenID_HTTP_FAILURE, $http_code);
- }
-
- $link_attrs = Auth_OpenID_parseLinkAttrs($data);
- $server = Auth_OpenID_findFirstHref($link_attrs, 'openid.server');
- $delegate = Auth_OpenID_findFirstHref($link_attrs, 'openid.delegate');
-
- if ($server === null) {
- return array(Auth_OpenID_PARSE_ERROR, null);
- } else {
- $server_id = $delegate ? $delegate : $consumer_id;
- $urls = array($consumer_id, $server_id, $server);
- return array(Auth_OpenID_SUCCESS, $urls);
- }
- }
-}
-
-/**
* Detect the presence of Curl and set a flag accordingly.
*/
define('Auth_OpenID_CURL_PRESENT', function_exists('curl_init'));
+/**
+ * Factory function that will return an instance of the appropriate
+ * HTTP fetcher
+ */
function Auth_OpenID_getHTTPFetcher()
{
if (Auth_OpenID_CURL_PRESENT) {
diff --git a/Auth/OpenID/HTTPFetcher.php b/Auth/OpenID/HTTPFetcher.php
new file mode 100644
index 0000000..ec3944d
--- /dev/null
+++ b/Auth/OpenID/HTTPFetcher.php
@@ -0,0 +1,112 @@
+<?php
+/**
+ * This module contains the HTTP fetcher interface
+ *
+ * PHP versions 4 and 5
+ *
+ * LICENSE: See the COPYING file included in this distribution.
+ *
+ * @package OpenID
+ * @author JanRain, Inc. <openid@janrain.com>
+ * @copyright 2005 Janrain, Inc.
+ * @license http://www.gnu.org/copyleft/lesser.html LGPL
+ */
+
+/**
+ * This is the status code beginAuth returns when it is unable to
+ * fetch the OpenID URL the user entered.
+ */
+define('Auth_OpenID_HTTP_FAILURE', 'http failure');
+
+/**
+ * This class is the interface for HTTP fetchers the OpenID consumer
+ * library uses. This interface is only important if you need to
+ * write a new fetcher for some reason.
+ *
+ * @access private
+ * @package OpenID
+ */
+class Auth_OpenID_HTTPFetcher {
+
+ /**
+ * Return whether a URL should be allowed. Override this method to
+ * conform to your local policy.
+ *
+ * By default, will attempt to fetch any http or https URL.
+ */
+ function allowedURL($url)
+ {
+ return Auth_OpenID_URLHasAllowedScheme($url);
+ }
+
+ /**
+ * This performs an HTTP get, following redirects along the way.
+ *
+ * @return array $tuple This returns a three-tuple on success.
+ * The first value is the http return code. The second value is
+ * the final url that was fetched, after following any redirects.
+ * The third value is the data that was retrieved from the site.
+ * If the fetch didn't succeed, return null.
+ */
+ function get($url)
+ {
+ trigger_error("not implemented", E_USER_ERROR);
+ }
+
+ /**
+ * This performs an HTTP post. If it makes sense, it will follow
+ * redirects along the way.
+ *
+ * @return array $tuple This returns a three-tuple on success.
+ * The first value is the http return code. The second value is
+ * the final url that was fetched, after following any redirects.
+ * The third value is the data that was retrieved from the site.
+ * If the fetch didn't succeed, return null.
+ */
+ function post($url, $body)
+ {
+ trigger_error("not implemented", E_USER_ERROR);
+ }
+
+ /**
+ * Retrieve the given URL and return the identity information
+ * contained therein. That is, perform OpenID discovery.
+ *
+ * @param string $identity_url The URL that the user entered
+ *
+ * @return array list($status, $info) The information parsed from
+ * the page or an error. If the status is Auth_OpenID_SUCCESS, the
+ * information returned is array($consumer_id, $server_id,
+ * $server_url). The $server_url is the OpenID server's URL. The
+ * consumer ID is the identifier by which the user should be known
+ * to the consumer. The server ID is the identifier by which the
+ * user should be known to the server.
+ */
+ function findIdentityInfo($identity_url)
+ {
+ $url = Auth_OpenID_normalizeURL($identity_url);
+ $ret = @$this->get($url);
+ if ($ret === null) {
+ return array(Auth_OpenID_HTTP_FAILURE, null);
+ }
+
+ list($http_code, $consumer_id, $data) = $ret;
+ if ($http_code != 200) {
+ return array(Auth_OpenID_HTTP_FAILURE, $http_code);
+ }
+
+ $link_attrs = Auth_OpenID_parseLinkAttrs($data);
+ $server = Auth_OpenID_findFirstHref($link_attrs, 'openid.server');
+ $delegate = Auth_OpenID_findFirstHref($link_attrs, 'openid.delegate');
+
+ if ($server === null) {
+ return array(Auth_OpenID_PARSE_ERROR, null);
+ } else {
+ $server_id = $delegate ? $delegate : $consumer_id;
+ $urls = array($consumer_id, $server_id, $server);
+ return array(Auth_OpenID_SUCCESS, $urls);
+ }
+ }
+}
+
+?> \ No newline at end of file
diff --git a/Auth/OpenID/Server.php b/Auth/OpenID/Server.php
index 630bee3..16edbd5 100644
--- a/Auth/OpenID/Server.php
+++ b/Auth/OpenID/Server.php
@@ -26,54 +26,6 @@ require_once "Auth/OpenID/TrustRoot.php";
require_once "Auth/OpenID/ServerRequest.php";
/**
- * Status code returned when the only option is to show an error page,
- * since we do not have enough information to redirect back to the
- * consumer. The associated value is an error message that should be
- * displayed on an HTML error page.
- */
-define('Auth_OpenID_LOCAL_ERROR', 'local_error');
-
-/**
- * Status code returned when there is an error to return in key-value
- * form to the consumer. The caller should return a 400 Bad Request
- * response with content-type text/plain and the value as the body.
- */
-define('Auth_OpenID_REMOTE_ERROR', 'remote_error');
-
-/**
- * Status code returned when there is a key-value form OK response to
- * the consumer. The value associated with this code is the
- * response. The caller should return a 200 OK response with
- * content-type text/plain and the value as the body.
- */
-define('Auth_OpenID_REMOTE_OK', 'remote_ok');
-
-/**
- * Status code returned when there is a redirect back to the
- * consumer. The value is the URL to redirect back to. The caller
- * should return a 302 Found redirect with a Location: header
- * containing the URL.
- */
-define('Auth_OpenID_REDIRECT', 'redirect');
-
-/**
- * Status code returned when the caller needs to authenticate the
- * user. The associated value is a Auth_OpenID_ServerRequest
- * object that can be used to complete the authentication. If the user
- * has taken some authentication action, use the retry() method of the
- * Auth_OpenID_ServerRequest object to complete the request.
- */
-define('Auth_OpenID_DO_AUTH', 'do_auth');
-
-/**
- * Status code returned when there were no OpenID arguments
- * passed. This code indicates that the caller should return a 200 OK
- * response and display an HTML page that says that this is an OpenID
- * server endpoint.
- */
-define('Auth_OpenID_DO_ABOUT', 'do_about');
-
-/**
* An object that implements the OpenID protocol for a single URL.
*
* Use this object by calling getOpenIDResponse when you get any
diff --git a/Auth/OpenID/ServerRequest.php b/Auth/OpenID/ServerRequest.php
index 1522aff..ae3f7c1 100644
--- a/Auth/OpenID/ServerRequest.php
+++ b/Auth/OpenID/ServerRequest.php
@@ -18,7 +18,6 @@
* Imports
*/
require_once "Auth/OpenID/Util.php";
-require_once "Auth/OpenID/Server.php";
/**
* Object that holds the state of a request to the OpenID server
diff --git a/Auth/OpenID/Util.php b/Auth/OpenID/Util.php
index 67ba691..1566cff 100644
--- a/Auth/OpenID/Util.php
+++ b/Auth/OpenID/Util.php
@@ -14,6 +14,66 @@
*/
/**
+ * Status code returned by the server when the only option is to show
+ * an error page, since we do not have enough information to redirect
+ * back to the consumer. The associated value is an error message that
+ * should be displayed on an HTML error page.
+ *
+ * @see Auth_OpenID_Server
+ */
+define('Auth_OpenID_LOCAL_ERROR', 'local_error');
+
+/**
+ * Status code returned when there is an error to return in key-value
+ * form to the consumer. The caller should return a 400 Bad Request
+ * response with content-type text/plain and the value as the body.
+ *
+ * @see Auth_OpenID_Server
+ */
+define('Auth_OpenID_REMOTE_ERROR', 'remote_error');
+
+/**
+ * Status code returned when there is a key-value form OK response to
+ * the consumer. The value associated with this code is the
+ * response. The caller should return a 200 OK response with
+ * content-type text/plain and the value as the body.
+ *
+ * @see Auth_OpenID_Server
+ */
+define('Auth_OpenID_REMOTE_OK', 'remote_ok');
+
+/**
+ * Status code returned when there is a redirect back to the
+ * consumer. The value is the URL to redirect back to. The caller
+ * should return a 302 Found redirect with a Location: header
+ * containing the URL.
+ *
+ * @see Auth_OpenID_Server
+ */
+define('Auth_OpenID_REDIRECT', 'redirect');
+
+/**
+ * Status code returned when the caller needs to authenticate the
+ * user. The associated value is a Auth_OpenID_ServerRequest
+ * object that can be used to complete the authentication. If the user
+ * has taken some authentication action, use the retry() method of the
+ * Auth_OpenID_ServerRequest object to complete the request.
+ *
+ * @see Auth_OpenID_Server
+ */
+define('Auth_OpenID_DO_AUTH', 'do_auth');
+
+/**
+ * Status code returned when there were no OpenID arguments
+ * passed. This code indicates that the caller should return a 200 OK
+ * response and display an HTML page that says that this is an OpenID
+ * server endpoint.
+ *
+ * @see Auth_OpenID_Server
+ */
+define('Auth_OpenID_DO_ABOUT', 'do_about');
+
+/**
* Some constants for string checking.
*/
$_Auth_OpenID_letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ";