summaryrefslogtreecommitdiffstats
path: root/Auth/OpenID/HTTPFetcher.php
diff options
context:
space:
mode:
Diffstat (limited to 'Auth/OpenID/HTTPFetcher.php')
-rw-r--r--Auth/OpenID/HTTPFetcher.php112
1 files changed, 112 insertions, 0 deletions
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