diff options
author | Luke Shepard <lshepard@devrs006.snc1.facebook.com> | 2009-05-28 07:08:30 +0800 |
---|---|---|
committer | Will Norris <will@willnorris.com> | 2009-05-28 13:01:42 +0800 |
commit | d90728f6b8c63ee2d8957bf47d09c76802cf743c (patch) | |
tree | 02306114d09d508282469ea316992001d0031bb2 | |
parent | 164375f493ea7de083ee64d25137b276f45ef172 (diff) | |
download | php-openid-d90728f6b8c63ee2d8957bf47d09c76802cf743c.zip php-openid-d90728f6b8c63ee2d8957bf47d09c76802cf743c.tar.gz php-openid-d90728f6b8c63ee2d8957bf47d09c76802cf743c.tar.bz2 |
[ few random cleanup changes ]
A few minor changes made over the past few months. This adds some
additional logging, an extra helper function for error messages,
and fixes a small bug with the association handler ... not to mention
standardizing on "false" instead of "False".
Signed-off-by: Will Norris <will@willnorris.com>
-rw-r--r-- | Auth/OpenID.php | 17 | ||||
-rw-r--r-- | Auth/OpenID/Association.php | 6 | ||||
-rw-r--r-- | Auth/OpenID/Consumer.php | 4 | ||||
-rw-r--r-- | Auth/OpenID/Discover.php | 22 | ||||
-rw-r--r-- | Auth/OpenID/FileStore.php | 2 | ||||
-rw-r--r-- | Auth/OpenID/SQLStore.php | 2 |
6 files changed, 44 insertions, 9 deletions
diff --git a/Auth/OpenID.php b/Auth/OpenID.php index bc66d62..924cd1e 100644 --- a/Auth/OpenID.php +++ b/Auth/OpenID.php @@ -102,9 +102,7 @@ define('Auth_OpenID_digits', define('Auth_OpenID_punct', "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~"); -if (Auth_OpenID_getMathLib() === null) { - Auth_OpenID_setNoMathSupport(); -} +Auth_OpenID_include_init(); /** * The OpenID utility function class. @@ -139,6 +137,9 @@ class Auth_OpenID { * Returns an empty array if neither GET nor POST was used, or if * POST was used but php://input cannot be opened. * + * See background: + * http://lists.openidenabled.com/pipermail/dev/2007-March/000395.html + * * @access private */ function getQuery($query_str=null) @@ -550,3 +551,13 @@ class Auth_OpenID { } } +/* + * Function to run when this file is included. + * Abstracted to a function to make life easier + * for some PHP optimizers. + */ +function Auth_OpenID_include_init() { + if (Auth_OpenID_getMathLib() === null) { + Auth_OpenID_setNoMathSupport(); + } +} diff --git a/Auth/OpenID/Association.php b/Auth/OpenID/Association.php index 2cd74e5..6a3a11b 100644 --- a/Auth/OpenID/Association.php +++ b/Auth/OpenID/Association.php @@ -131,8 +131,10 @@ class Auth_OpenID_Association { function Auth_OpenID_Association( $handle, $secret, $issued, $lifetime, $assoc_type) { - if (!in_array($assoc_type, - Auth_OpenID_getSupportedAssociationTypes())) { + // use array_key_exists because in_array doesn't check + // correctly for numerical indexes + $types_hash = array_flip(Auth_OpenID_getSupportedAssociationTypes()); + if (!array_key_exists($assoc_type, $types_hash)) { $fmt = 'Unsupported association type (%s)'; trigger_error(sprintf($fmt, $assoc_type), E_USER_ERROR); } diff --git a/Auth/OpenID/Consumer.php b/Auth/OpenID/Consumer.php index b7f9439..d2d6f92 100644 --- a/Auth/OpenID/Consumer.php +++ b/Auth/OpenID/Consumer.php @@ -1216,8 +1216,8 @@ class Auth_OpenID_GenericConsumer { } return new Auth_OpenID_FailureResponse(null, - sprintf('No matching endpoint found after discovering %s', - $claimed_id)); + sprintf('No matching endpoint found after discovering %s: %s', + $claimed_id, $result->message)); } /** diff --git a/Auth/OpenID/Discover.php b/Auth/OpenID/Discover.php index 6bc30f3..ac17927 100644 --- a/Auth/OpenID/Discover.php +++ b/Auth/OpenID/Discover.php @@ -32,6 +32,28 @@ function Auth_OpenID_getOpenIDTypeURIs() Auth_OpenID_RP_RETURN_TO_URL_TYPE); } + +/* + * Provides a user-readable interpretation of a type uri. + * Useful for error messages. + */ +function Auth_OpenID_getOpenIDTypeName($type_uri) { + switch ($type_uri) { + case Auth_OpenID_TYPE_2_0_IDP: + return 'OpenID 2.0 IDP'; + case Auth_OpenID_TYPE_2_0: + return 'OpenID 2.0'; + case Auth_OpenID_TYPE_1_2: + return 'OpenID 1.2'; + case Auth_OpenID_TYPE_1_1: + return 'OpenID 1.1'; + case Auth_OpenID_TYPE_1_0: + return 'OpenID 1.0'; + case Auth_OpenID_RP_RETURN_TO_URL_TYPE: + return 'OpenID relying party'; + } +} + /** * Object representing an OpenID service endpoint. */ diff --git a/Auth/OpenID/FileStore.php b/Auth/OpenID/FileStore.php index 6774a7f..187234e 100644 --- a/Auth/OpenID/FileStore.php +++ b/Auth/OpenID/FileStore.php @@ -367,7 +367,7 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { } if ( abs($timestamp - time()) > $Auth_OpenID_SKEW ) { - return False; + return false; } if ($server_url) { diff --git a/Auth/OpenID/SQLStore.php b/Auth/OpenID/SQLStore.php index abd81bf..5c75e70 100644 --- a/Auth/OpenID/SQLStore.php +++ b/Auth/OpenID/SQLStore.php @@ -482,7 +482,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { global $Auth_OpenID_SKEW; if ( abs($timestamp - time()) > $Auth_OpenID_SKEW ) { - return False; + return false; } return $this->_add_nonce($server_url, $timestamp, $salt); |