summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Auth/OpenID.php67
-rw-r--r--Auth/OpenID/Consumer.php6
-rw-r--r--Auth/OpenID/Server.php8
-rw-r--r--Auth/OpenID/ServerRequest.php6
-rw-r--r--Auth/OpenID/Util.php68
-rw-r--r--Tests/Auth/OpenID/Util.php3
6 files changed, 79 insertions, 79 deletions
diff --git a/Auth/OpenID.php b/Auth/OpenID.php
index 60bcb6f..67593b4 100644
--- a/Auth/OpenID.php
+++ b/Auth/OpenID.php
@@ -159,6 +159,73 @@ class Auth_OpenID {
return false;
}
}
+
+ /**
+ * Implements the PHP 5 'http_build_query' functionality.
+ *
+ * @access private
+ * @param array $data Either an array key/value pairs or an array
+ * of arrays, each of which holding two values: a key and a value,
+ * sequentially.
+ * @return string $result The result of url-encoding the key/value
+ * pairs from $data into a URL query string
+ * (e.g. "username=bob&id=56").
+ */
+ function httpBuildQuery($data)
+ {
+ $pairs = array();
+ foreach ($data as $key => $value) {
+ if (is_array($value)) {
+ $pairs[] = urlencode($value[0])."=".urlencode($value[1]);
+ } else {
+ $pairs[] = urlencode($key)."=".urlencode($value);
+ }
+ }
+ return implode("&", $pairs);
+ }
+
+ /**
+ * "Appends" query arguments onto a URL. The URL may or may not
+ * already have arguments (following a question mark).
+ *
+ * @param string $url A URL, which may or may not already have
+ * arguments.
+ * @param array $args Either an array key/value pairs or an array of
+ * arrays, each of which holding two values: a key and a value,
+ * sequentially. If $args is an ordinary key/value array, the
+ * parameters will be added to the URL in sorted alphabetical order;
+ * if $args is an array of arrays, their order will be preserved.
+ * @return string $url The original URL with the new parameters added.
+ *
+ */
+ function appendArgs($url, $args)
+ {
+ if (count($args) == 0) {
+ return $url;
+ }
+
+ // Non-empty array; if it is an array of arrays, use
+ // multisort; otherwise use sort.
+ if (array_key_exists(0, $args) &&
+ is_array($args[0])) {
+ // Do nothing here.
+ } else {
+ $keys = array_keys($args);
+ sort($keys);
+ $new_args = array();
+ foreach ($keys as $key) {
+ $new_args[] = array($key, $args[$key]);
+ }
+ $args = $new_args;
+ }
+
+ $sep = '?';
+ if (strpos($url, '?') !== false) {
+ $sep = '&';
+ }
+
+ return $url . $sep . Auth_OpenID::httpBuildQuery($args);
+ }
}
?> \ No newline at end of file
diff --git a/Auth/OpenID/Consumer.php b/Auth/OpenID/Consumer.php
index 2a8561e..f62ed60 100644
--- a/Auth/OpenID/Consumer.php
+++ b/Auth/OpenID/Consumer.php
@@ -461,7 +461,7 @@ class Auth_OpenID_Consumer {
}
$this->store->storeNonce($auth_request->nonce);
- return Auth_OpenID_appendArgs($auth_request->server_url, $redir_args);
+ return Auth_OpenID::appendArgs($auth_request->server_url, $redir_args);
}
/**
@@ -624,7 +624,7 @@ class Auth_OpenID_Consumer {
}
$check_args['openid.mode'] = 'check_authentication';
- $post_data = Auth_OpenID_http_build_query($check_args);
+ $post_data = Auth_OpenID::httpBuildQuery($check_args);
$ret = @$this->fetcher->post($server_url, $post_data);
if ($ret === null) {
@@ -689,7 +689,7 @@ class Auth_OpenID_Consumer {
$dh = $this->_createDiffieHellman();
$args = array_merge($args, $dh->getAssocArgs());
- $body = Auth_OpenID_http_build_query($args);
+ $body = Auth_OpenID::httpBuildQuery($args);
$assoc = $this->_fetchAssociation($dh, $server_url, $body);
}
diff --git a/Auth/OpenID/Server.php b/Auth/OpenID/Server.php
index b27b36b..2301f35 100644
--- a/Auth/OpenID/Server.php
+++ b/Auth/OpenID/Server.php
@@ -206,7 +206,7 @@ class Auth_OpenID_Server {
// checkid_setup.
$args = $request->args;
$args['openid.mode'] = 'checkid_setup';
- $setup_url = Auth_OpenID_appendArgs($this->server_url, $args);
+ $setup_url = Auth_OpenID::appendArgs($this->server_url, $args);
// Return to the consumer, instructing it that the user
// needs to do something in order to verify his identity.
@@ -215,7 +215,7 @@ class Auth_OpenID_Server {
'openid.user_setup_url' => $setup_url
);
- $redir_url = Auth_OpenID_appendArgs($return_to, $rargs);
+ $redir_url = Auth_OpenID::appendArgs($return_to, $rargs);
return array(Auth_OpenID_REDIRECT, $redir_url);
case 'checkid_setup':
@@ -273,7 +273,7 @@ class Auth_OpenID_Server {
$reply['openid.assoc_handle'] = $assoc->handle;
$signed_fields = array('mode', 'identity', 'return_to');
$assoc->addSignature($signed_fields, &$reply);
- $redir_url = Auth_OpenID_appendArgs($return_to, $reply);
+ $redir_url = Auth_OpenID::appendArgs($return_to, $reply);
return array(Auth_OpenID_REDIRECT, $redir_url);
}
@@ -423,7 +423,7 @@ class Auth_OpenID_Server {
'openid.mode' => 'error',
'openid.error' => $msg
);
- $redir_url = Auth_OpenID_appendArgs($return_to, $err);
+ $redir_url = Auth_OpenID::appendArgs($return_to, $err);
return array(Auth_OpenID_REDIRECT, $redir_url);
} else {
foreach (array_keys($args) as $k) {
diff --git a/Auth/OpenID/ServerRequest.php b/Auth/OpenID/ServerRequest.php
index ae3f7c1..b0a496a 100644
--- a/Auth/OpenID/ServerRequest.php
+++ b/Auth/OpenID/ServerRequest.php
@@ -17,7 +17,7 @@
/**
* Imports
*/
-require_once "Auth/OpenID/Util.php";
+require_once "Auth/OpenID.php";
/**
* Object that holds the state of a request to the OpenID server
@@ -100,7 +100,7 @@ class Auth_OpenID_ServerRequest {
{
$cancel_args = array('openid.mode' => 'cancel');
$return_to = $this->args['openid.return_to'];
- return Auth_OpenID_appendArgs($return_to, $cancel_args);
+ return Auth_OpenID::appendArgs($return_to, $cancel_args);
}
/**
@@ -108,7 +108,7 @@ class Auth_OpenID_ServerRequest {
*/
function getRetryURL()
{
- return Auth_OpenID_appendArgs($this->server_url, $this->args);
+ return Auth_OpenID::appendArgs($this->server_url, $this->args);
}
/**
diff --git a/Auth/OpenID/Util.php b/Auth/OpenID/Util.php
index 7dd2859..8b9b3bc 100644
--- a/Auth/OpenID/Util.php
+++ b/Auth/OpenID/Util.php
@@ -21,74 +21,6 @@ $_Auth_OpenID_digits = "0123456789";
$_Auth_OpenID_punct = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
/**
- * Implements the PHP 5 'http_build_query' functionality.
- *
- * @access private
- * @param array $data Either an array key/value pairs or an array of
- * arrays, each of which holding two values: a key and a value,
- * sequentially.
- * @return string $result The result of url-encoding the key/value
- * pairs from $data into a URL query string
- * (e.g. "username=bob&id=56").
- */
-function Auth_OpenID_http_build_query($data)
-{
- $pairs = array();
- foreach ($data as $key => $value) {
- if (is_array($value)) {
- $pairs[] = urlencode($value[0])."=".urlencode($value[1]);
- } else {
- $pairs[] = urlencode($key)."=".urlencode($value);
- }
- }
- return implode("&", $pairs);
-}
-
-/**
- * "Appends" query arguments onto a URL. The URL may or may not
- * already have arguments (following a question mark).
- *
- * @param string $url A URL, which may or may not already have
- * arguments.
- * @param array $args Either an array key/value pairs or an array of
- * arrays, each of which holding two values: a key and a value,
- * sequentially. If $args is an ordinary key/value array, the
- * parameters will be added to the URL in sorted alphabetical order;
- * if $args is an array of arrays, their order will be preserved.
- * @return string $url The original URL with the new parameters added.
- *
- */
-function Auth_OpenID_appendArgs($url, $args)
-{
-
- if (count($args) == 0) {
- return $url;
- }
-
- // Non-empty array; if it is an array of arrays, use multisort;
- // otherwise use sort.
- if (array_key_exists(0, $args) &&
- is_array($args[0])) {
- // Do nothing here.
- } else {
- $keys = array_keys($args);
- sort($keys);
- $new_args = array();
- foreach ($keys as $key) {
- $new_args[] = array($key, $args[$key]);
- }
- $args = $new_args;
- }
-
- $sep = '?';
- if (strpos($url, '?') !== false) {
- $sep = '&';
- }
-
- return $url . $sep . Auth_OpenID_http_build_query($args);
-}
-
-/**
* Turn a string into an ASCII string.
*
* Replace non-ascii characters with a %-encoded, UTF-8 encoding. This
diff --git a/Tests/Auth/OpenID/Util.php b/Tests/Auth/OpenID/Util.php
index c6fa07c..659e7cf 100644
--- a/Tests/Auth/OpenID/Util.php
+++ b/Tests/Auth/OpenID/Util.php
@@ -15,6 +15,7 @@
require_once 'PHPUnit.php';
require_once 'Auth/OpenID/Util.php';
+require_once 'Auth/OpenID.php';
class Tests_Auth_OpenID_Util extends PHPUnit_TestCase {
function test_base64()
@@ -252,7 +253,7 @@ assert not should_raise and actual == expected, case
list($desc, $data, $expected) = $case;
list($url, $query) = $data;
$this->assertEquals($expected,
- Auth_OpenID_appendArgs($url, $query));
+ Auth_OpenID::appendArgs($url, $query));
}
}
}