diff options
author | Yury German <blueknight@gentoo.org> | 2022-06-15 12:08:35 -0400 |
---|---|---|
committer | Yury German <blueknight@gentoo.org> | 2022-06-15 12:08:35 -0400 |
commit | 36d7691c33cb64ece817246e47a779ec648d10b0 (patch) | |
tree | 08f2fb95303a1d8eeba2c8629a24b35a91fb1cac /plugins/openid/lib/Auth/OpenID | |
parent | twentyfourteen upg 2.7 to 3.2 and twentysixteen from 2.0 to 2.5 (diff) | |
download | blogs-gentoo-36d7691c33cb64ece817246e47a779ec648d10b0.tar.gz blogs-gentoo-36d7691c33cb64ece817246e47a779ec648d10b0.tar.bz2 blogs-gentoo-36d7691c33cb64ece817246e47a779ec648d10b0.zip |
Openid-3.6.1 and jetpack-11.0 upgrade
Signed-off-by: Yury German <blueknight@gentoo.org>
Diffstat (limited to 'plugins/openid/lib/Auth/OpenID')
21 files changed, 589 insertions, 469 deletions
diff --git a/plugins/openid/lib/Auth/OpenID/AX.php b/plugins/openid/lib/Auth/OpenID/AX.php index acc9af52..82b354d1 100644 --- a/plugins/openid/lib/Auth/OpenID/AX.php +++ b/plugins/openid/lib/Auth/OpenID/AX.php @@ -130,7 +130,7 @@ class Auth_OpenID_AX_Message extends Auth_OpenID_Extension { */ function _newArgs() { - return array('mode' => $this->mode); + return ['mode' => $this->mode]; } } @@ -248,7 +248,7 @@ class Auth_OpenID_AX_AttrInfo { */ function Auth_OpenID_AX_toTypeURIs($namespace_map, $alias_list_s) { - $uris = array(); + $uris = []; if ($alias_list_s) { foreach (explode(',', $alias_list_s) as $alias) { @@ -295,7 +295,7 @@ class Auth_OpenID_AX_FetchRequest extends Auth_OpenID_AX_Message { * * @var array */ - private $requested_attributes = array(); + private $requested_attributes = []; function __construct($update_url=null) { @@ -331,8 +331,8 @@ class Auth_OpenID_AX_FetchRequest extends Auth_OpenID_AX_Message { { $aliases = new Auth_OpenID_NamespaceMap(); - $required = array(); - $if_available = array(); + $required = []; + $if_available = []; $ax_args = $this->_newArgs(); @@ -383,7 +383,7 @@ class Auth_OpenID_AX_FetchRequest extends Auth_OpenID_AX_Message { */ function getRequiredAttrs() { - $required = array(); + $required = []; foreach ($this->requested_attributes as $type_uri => $attribute) { if ($attribute->required) { $required[] = $type_uri; @@ -559,7 +559,7 @@ class Auth_OpenID_AX_FetchRequest extends Auth_OpenID_AX_Message { class Auth_OpenID_AX_KeyValueMessage extends Auth_OpenID_AX_Message { /** @var array */ - protected $data = array(); + protected $data = []; /** * Add a single value for the given attribute type to the @@ -574,7 +574,7 @@ class Auth_OpenID_AX_KeyValueMessage extends Auth_OpenID_AX_Message { function addValue($type_uri, $value) { if (!array_key_exists($type_uri, $this->data)) { - $this->data[$type_uri] = array(); + $this->data[$type_uri] = []; } $values =& $this->data[$type_uri]; @@ -609,7 +609,7 @@ class Auth_OpenID_AX_KeyValueMessage extends Auth_OpenID_AX_Message { $aliases = new Auth_OpenID_NamespaceMap(); } - $ax_args = array(); + $ax_args = []; foreach ($this->data as $type_uri => $values) { $alias = $aliases->add($type_uri); @@ -683,7 +683,7 @@ class Auth_OpenID_AX_KeyValueMessage extends Auth_OpenID_AX_Message { ); } - $values = array(); + $values = []; for ($i = 1; $i < $count + 1; $i++) { $value_key = sprintf('value.%s.%d', $alias, $i); @@ -710,9 +710,9 @@ class Auth_OpenID_AX_KeyValueMessage extends Auth_OpenID_AX_Message { $value = $ax_args['value.' . $alias]; if ($value == '') { - $values = array(); + $values = []; } else { - $values = array($value); + $values = [$value]; } } @@ -828,7 +828,7 @@ class Auth_OpenID_AX_FetchResponse extends Auth_OpenID_AX_KeyValueMessage { { $aliases = new Auth_OpenID_NamespaceMap(); - $zero_value_types = array(); + $zero_value_types = []; if ($request !== null) { // Validate the data in the context of the request (the @@ -865,7 +865,7 @@ class Auth_OpenID_AX_FetchResponse extends Auth_OpenID_AX_KeyValueMessage { if (array_key_exists($attr_info->type_uri, $this->data)) { $values = $this->data[$attr_info->type_uri]; } else { - $values = array(); + $values = []; $zero_value_types[] = $attr_info; } diff --git a/plugins/openid/lib/Auth/OpenID/Association.php b/plugins/openid/lib/Auth/OpenID/Association.php index 23ced3a4..ef166b78 100644 --- a/plugins/openid/lib/Auth/OpenID/Association.php +++ b/plugins/openid/lib/Auth/OpenID/Association.php @@ -55,19 +55,19 @@ class Auth_OpenID_Association { * * @access private */ - public $assoc_keys = array( - 'version', - 'handle', - 'secret', - 'issued', - 'lifetime', - 'assoc_type' - ); - - public $_macs = array( - 'HMAC-SHA1' => 'Auth_OpenID_HMACSHA1', - 'HMAC-SHA256' => 'Auth_OpenID_HMACSHA256' - ); + public $assoc_keys = [ + 'version', + 'handle', + 'secret', + 'issued', + 'lifetime', + 'assoc_type', + ]; + + public $_macs = [ + 'HMAC-SHA1' => 'Auth_OpenID_HMACSHA1', + 'HMAC-SHA256' => 'Auth_OpenID_HMACSHA256', + ]; /** * This is an alternate constructor (factory method) used by the @@ -186,14 +186,14 @@ class Auth_OpenID_Association { */ function serialize() { - $data = array( - 'version' => '2', - 'handle' => $this->handle, - 'secret' => base64_encode($this->secret), - 'issued' => strval(intval($this->issued)), - 'lifetime' => strval(intval($this->lifetime)), - 'assoc_type' => $this->assoc_type - ); + $data = [ + 'version' => '2', + 'handle' => $this->handle, + 'secret' => base64_encode($this->secret), + 'issued' => strval(intval($this->issued)), + 'lifetime' => strval(intval($this->lifetime)), + 'assoc_type' => $this->assoc_type, + ]; assert(array_keys($data) == $this->assoc_keys); @@ -211,8 +211,8 @@ class Auth_OpenID_Association { static function deserialize($class_name, $assoc_s) { $pairs = Auth_OpenID_KVForm::toArray($assoc_s, $strict = true); - $keys = array(); - $values = array(); + $keys = []; + $values = []; foreach ($pairs as $key => $value) { if (is_array($value)) { list($key, $value) = $value; @@ -269,7 +269,7 @@ class Auth_OpenID_Association { /* Invalid association types should be caught at constructor */ $callback = $this->_macs[$this->assoc_type]; - return call_user_func_array($callback, array($this->secret, $kv)); + return call_user_func_array($callback, [$this->secret, $kv]); } /** @@ -304,7 +304,7 @@ class Auth_OpenID_Association { $this->handle); $message_keys = array_keys($signed_message->toPostArgs()); - $signed_list = array(); + $signed_list = []; $signed_prefix = 'openid.'; foreach ($message_keys as $k) { @@ -341,12 +341,14 @@ class Auth_OpenID_Association { } $signed_list = explode(',', $signed); - $pairs = array(); + $pairs = []; $data = $message->toPostArgs(); foreach ($signed_list as $field) { - $pairs[] = array($field, Auth_OpenID::arrayGet($data, + $pairs[] = [ + $field, Auth_OpenID::arrayGet($data, 'openid.' . - $field, '')); + $field, '') + ]; } return $pairs; } @@ -400,12 +402,12 @@ function Auth_OpenID_getSecretSize($assoc_type) function Auth_OpenID_getAllAssociationTypes() { - return array('HMAC-SHA1', 'HMAC-SHA256'); + return ['HMAC-SHA1', 'HMAC-SHA256']; } function Auth_OpenID_getSupportedAssociationTypes() { - $a = array('HMAC-SHA1'); + $a = ['HMAC-SHA1']; if (Auth_OpenID_HMACSHA256_SUPPORTED) { $a[] = 'HMAC-SHA256'; @@ -420,15 +422,16 @@ function Auth_OpenID_getSupportedAssociationTypes() */ function Auth_OpenID_getSessionTypes($assoc_type) { - $assoc_to_session = array( - 'HMAC-SHA1' => array('DH-SHA1', 'no-encryption')); + $assoc_to_session = [ + 'HMAC-SHA1' => ['DH-SHA1', 'no-encryption'] + ]; if (Auth_OpenID_HMACSHA256_SUPPORTED) { $assoc_to_session['HMAC-SHA256'] = - array('DH-SHA256', 'no-encryption'); + ['DH-SHA256', 'no-encryption']; } - return Auth_OpenID::arrayGet($assoc_to_session, $assoc_type, array()); + return Auth_OpenID::arrayGet($assoc_to_session, $assoc_type, []); } function Auth_OpenID_checkSessionType($assoc_type, $session_type) @@ -443,20 +446,20 @@ function Auth_OpenID_checkSessionType($assoc_type, $session_type) function Auth_OpenID_getDefaultAssociationOrder() { - $order = array(); + $order = []; if (!Auth_OpenID_noMathSupport()) { - $order[] = array('HMAC-SHA1', 'DH-SHA1'); + $order[] = ['HMAC-SHA1', 'DH-SHA1']; if (Auth_OpenID_HMACSHA256_SUPPORTED) { - $order[] = array('HMAC-SHA256', 'DH-SHA256'); + $order[] = ['HMAC-SHA256', 'DH-SHA256']; } } - $order[] = array('HMAC-SHA1', 'no-encryption'); + $order[] = ['HMAC-SHA1', 'no-encryption']; if (Auth_OpenID_HMACSHA256_SUPPORTED) { - $order[] = array('HMAC-SHA256', 'no-encryption'); + $order[] = ['HMAC-SHA256', 'no-encryption']; } return $order; @@ -464,7 +467,7 @@ function Auth_OpenID_getDefaultAssociationOrder() function Auth_OpenID_getOnlyEncryptedOrder() { - $result = array(); + $result = []; foreach (Auth_OpenID_getDefaultAssociationOrder() as $pair) { list($assoc, $session) = $pair; @@ -538,7 +541,7 @@ function Auth_OpenID_getEncryptedNegotiator() class Auth_OpenID_SessionNegotiator { function __construct($allowed_types) { - $this->allowed_types = array(); + $this->allowed_types = []; $this->setAllowedTypes($allowed_types); } @@ -576,7 +579,7 @@ class Auth_OpenID_SessionNegotiator { function addAllowedType($assoc_type, $session_type = null) { if ($this->allowed_types === null) { - $this->allowed_types = array(); + $this->allowed_types = []; } if ($session_type === null) { @@ -591,7 +594,7 @@ class Auth_OpenID_SessionNegotiator { } } else { if (Auth_OpenID_checkSessionType($assoc_type, $session_type)) { - $this->allowed_types[] = array($assoc_type, $session_type); + $this->allowed_types[] = [$assoc_type, $session_type]; } else { return false; } @@ -603,7 +606,7 @@ class Auth_OpenID_SessionNegotiator { // Is this combination of association type and session type allowed? function isAllowed($assoc_type, $session_type) { - $assoc_good = in_array(array($assoc_type, $session_type), + $assoc_good = in_array([$assoc_type, $session_type], $this->allowed_types); $matches = in_array($session_type, @@ -619,7 +622,7 @@ class Auth_OpenID_SessionNegotiator { function getAllowedType() { if (!$this->allowed_types) { - return array(null, null); + return [null, null]; } return $this->allowed_types[0]; diff --git a/plugins/openid/lib/Auth/OpenID/BigMath.php b/plugins/openid/lib/Auth/OpenID/BigMath.php index 6a33322a..512b1a43 100644 --- a/plugins/openid/lib/Auth/OpenID/BigMath.php +++ b/plugins/openid/lib/Auth/OpenID/BigMath.php @@ -55,7 +55,7 @@ abstract class Auth_OpenID_MathLibrary { return "\x00"; } - $bytes = array(); + $bytes = []; while ($this->cmp($long, 0) > 0) { array_unshift($bytes, $this->mod($long, 256)); @@ -137,7 +137,7 @@ abstract class Auth_OpenID_MathLibrary { */ function rand($stop) { - static $duplicate_cache = array(); + static $duplicate_cache = []; // Used as the key for the duplicate cache $rbytes = $this->longToBinary($stop); @@ -158,10 +158,10 @@ abstract class Auth_OpenID_MathLibrary { $duplicate = $this->mod($mxrand, $stop); if (count($duplicate_cache) > 10) { - $duplicate_cache = array(); + $duplicate_cache = []; } - $duplicate_cache[$rbytes] = array($duplicate, $nbytes); + $duplicate_cache[$rbytes] = [$duplicate, $nbytes]; } do { @@ -391,18 +391,21 @@ class Auth_OpenID_GmpMathWrapper extends Auth_OpenID_MathLibrary{ */ function Auth_OpenID_math_extensions() { - $result = array(); + $result = []; if (!defined('Auth_OpenID_BUGGY_GMP')) { - $result[] = - array('modules' => array('gmp', 'php_gmp'), - 'extension' => 'gmp', - 'class' => 'Auth_OpenID_GmpMathWrapper'); + $result[] = [ + 'modules' => ['gmp', 'php_gmp'], + 'extension' => 'gmp', + 'class' => 'Auth_OpenID_GmpMathWrapper', + ]; } - $result[] = array('modules' => array('bcmath', 'php_bcmath'), - 'extension' => 'bcmath', - 'class' => 'Auth_OpenID_BcMathWrapper'); + $result[] = [ + 'modules' => ['bcmath', 'php_bcmath'], + 'extension' => 'bcmath', + 'class' => 'Auth_OpenID_BcMathWrapper', + ]; return $result; } @@ -466,7 +469,7 @@ function Auth_OpenID_getMathLib() // works. $ext = Auth_OpenID_detectMathLibrary(Auth_OpenID_math_extensions()); if ($ext === false) { - $tried = array(); + $tried = []; foreach (Auth_OpenID_math_extensions() as $extinfo) { $tried[] = $extinfo['extension']; } diff --git a/plugins/openid/lib/Auth/OpenID/Consumer.php b/plugins/openid/lib/Auth/OpenID/Consumer.php index fb1257ef..f4b4df34 100644 --- a/plugins/openid/lib/Auth/OpenID/Consumer.php +++ b/plugins/openid/lib/Auth/OpenID/Consumer.php @@ -214,14 +214,20 @@ define('Auth_OpenID_PARSE_ERROR', 'parse error'); */ class Auth_OpenID_Consumer { + /** @var Auth_OpenID_GenericConsumer */ + public $consumer; + + /** @var Auth_Yadis_PHPSession */ + public $session; + private $discoverMethod = 'Auth_OpenID_discover'; private $session_key_prefix = "_openid_consumer_"; private $_token_suffix = "last_token"; - /** @var Auth_OpenID_GenericConsumer */ - public $consumer; + /** @var string */ + private $_token_key; /** * Initialize a Consumer instance. @@ -426,8 +432,7 @@ class Auth_OpenID_Consumer { $current_url); $this->session->del($this->_token_key); - if (in_array($response->status, array(Auth_OpenID_SUCCESS, - Auth_OpenID_CANCEL))) { + if (in_array($response->status, [Auth_OpenID_SUCCESS, Auth_OpenID_CANCEL])) { if ($response->identity_url !== null) { $disco = $this->getDiscoveryObject($this->session, $response->identity_url, @@ -449,7 +454,10 @@ class Auth_OpenID_DiffieHellmanSHA1ConsumerSession { public $session_type = 'DH-SHA1'; public $hash_func = 'Auth_OpenID_SHA1'; public $secret_size = 20; - public $allowed_assoc_types = array('HMAC-SHA1'); + public $allowed_assoc_types = ['HMAC-SHA1']; + + /** @var Auth_OpenID_DiffieHellman */ + protected $dh; function __construct($dh = null) { @@ -466,14 +474,15 @@ class Auth_OpenID_DiffieHellmanSHA1ConsumerSession { $cpub = $math->longToBase64($this->dh->public); - $args = array('dh_consumer_public' => $cpub); + $args = ['dh_consumer_public' => $cpub]; if (!$this->dh->usingDefaultValues()) { - $args = array_merge($args, array( + $args = array_merge($args, [ 'dh_modulus' => $math->longToBase64($this->dh->mod), 'dh_gen' => - $math->longToBase64($this->dh->gen))); + $math->longToBase64($this->dh->gen) + ]); } return $args; @@ -516,7 +525,7 @@ class Auth_OpenID_DiffieHellmanSHA256ConsumerSession extends public $session_type = 'DH-SHA256'; public $hash_func = 'Auth_OpenID_SHA256'; public $secret_size = 32; - public $allowed_assoc_types = array('HMAC-SHA256'); + public $allowed_assoc_types = ['HMAC-SHA256']; } /** @@ -526,11 +535,11 @@ class Auth_OpenID_DiffieHellmanSHA256ConsumerSession extends */ class Auth_OpenID_PlainTextConsumerSession { public $session_type = 'no-encryption'; - public $allowed_assoc_types = array('HMAC-SHA1', 'HMAC-SHA256'); + public $allowed_assoc_types = ['HMAC-SHA1', 'HMAC-SHA256']; function getRequest() { - return array(); + return []; } /** @@ -553,10 +562,11 @@ class Auth_OpenID_PlainTextConsumerSession { */ function Auth_OpenID_getAvailableSessionTypes() { - $types = array( + $types = [ 'no-encryption' => 'Auth_OpenID_PlainTextConsumerSession', 'DH-SHA1' => 'Auth_OpenID_DiffieHellmanSHA1ConsumerSession', - 'DH-SHA256' => 'Auth_OpenID_DiffieHellmanSHA256ConsumerSession'); + 'DH-SHA256' => 'Auth_OpenID_DiffieHellmanSHA256ConsumerSession' + ]; return $types; } @@ -596,6 +606,15 @@ class Auth_OpenID_GenericConsumer { */ public $openid1_return_to_identifier_name = 'openid1_claimed_id'; + /** @var Auth_Yadis_ParanoidHTTPFetcher|Auth_Yadis_PlainHTTPFetcher */ + public $fetcher; + + /** @var array */ + public $session_types; + + /** @var Auth_OpenID_SessionNegotiator */ + public $negotiator; + /** * This method initializes a new {@link Auth_OpenID_Consumer} * instance to access the library. @@ -662,18 +681,18 @@ class Auth_OpenID_GenericConsumer { $mode = $message->getArg(Auth_OpenID_OPENID_NS, 'mode', '<no mode set>'); - $mode_methods = array( + $mode_methods = [ 'cancel' => '_complete_cancel', 'error' => '_complete_error', 'setup_needed' => '_complete_setup_needed', 'id_res' => '_complete_id_res', - ); + ]; $method = Auth_OpenID::arrayGet($mode_methods, $mode, '_completeInvalid'); - return call_user_func_array(array($this, $method), - array($message, $endpoint, $return_to)); + return call_user_func_array([$this, $method], + [$message, $endpoint, $return_to]); } /** @@ -883,7 +902,7 @@ class Auth_OpenID_GenericConsumer { // The URL scheme, authority, and path MUST be the same // between the two URLs. - foreach (array('scheme', 'host', 'port', 'path') as $component) { + foreach (['scheme', 'host', 'port', 'path'] as $component) { // If the url component is absent in either URL, fail. // There should always be a scheme, host, port, and path. if (!array_key_exists($component, $return_to_parts)) { @@ -927,7 +946,7 @@ class Auth_OpenID_GenericConsumer { $parsed_url = parse_url($return_to); - $q = array(); + $q = []; if (array_key_exists('query', $parsed_url)) { $rt_query = $parsed_url['query']; $q = Auth_OpenID::parse_str($rt_query); @@ -1049,7 +1068,7 @@ class Auth_OpenID_GenericConsumer { } $to_match = new Auth_OpenID_ServiceEndpoint(); - $to_match->type_uris = array(Auth_OpenID_TYPE_1_1); + $to_match->type_uris = [Auth_OpenID_TYPE_1_1]; $to_match->local_id = $message->getArg(Auth_OpenID_OPENID1_NS, 'identity'); @@ -1062,7 +1081,7 @@ class Auth_OpenID_GenericConsumer { } $to_match_1_0 = $to_match->copy(); - $to_match_1_0->type_uris = array(Auth_OpenID_TYPE_1_0); + $to_match_1_0->type_uris = [Auth_OpenID_TYPE_1_0]; if ($endpoint !== null) { $result = $this->_verifyDiscoverySingle($endpoint, $to_match); @@ -1084,7 +1103,7 @@ class Auth_OpenID_GenericConsumer { // Endpoint is either bad (failed verification) or None return $this->_discoverAndVerify($to_match->claimed_id, - array($to_match, $to_match_1_0)); + [$to_match, $to_match_1_0]); } /** @@ -1150,7 +1169,7 @@ class Auth_OpenID_GenericConsumer { function _verifyDiscoveryResultsOpenID2($message, $endpoint) { $to_match = new Auth_OpenID_ServiceEndpoint(); - $to_match->type_uris = array(Auth_OpenID_TYPE_2_0); + $to_match->type_uris = [Auth_OpenID_TYPE_2_0]; $to_match->claimed_id = $message->getArg(Auth_OpenID_OPENID2_NS, 'claimed_id'); @@ -1194,7 +1213,7 @@ class Auth_OpenID_GenericConsumer { // the original request. // oidutil.log('No pre-discovered information supplied.') return $this->_discoverAndVerify($to_match->claimed_id, - array($to_match)); + [$to_match]); } else { // The claimed ID matches, so we use the endpoint that we @@ -1204,7 +1223,7 @@ class Auth_OpenID_GenericConsumer { if (Auth_OpenID::isFailure($result)) { $endpoint = $this->_discoverAndVerify($to_match->claimed_id, - array($to_match)); + [$to_match]); if (Auth_OpenID::isFailure($endpoint)) { return $endpoint; } @@ -1230,10 +1249,10 @@ class Auth_OpenID_GenericConsumer { { // oidutil.log('Performing discovery on %s' % (claimed_id,)) list(, $services) = call_user_func_array($this->discoverMethod, - array( + [ $claimed_id, $this->fetcher, - )); + ]); if (!$services) { return new Auth_OpenID_FailureResponse(null, @@ -1342,26 +1361,28 @@ class Auth_OpenID_GenericConsumer { */ function _idResCheckForFields($message) { - $basic_fields = array('return_to', 'assoc_handle', 'sig', 'signed'); - $basic_sig_fields = array('return_to', 'identity'); + $basic_fields = ['return_to', 'assoc_handle', 'sig', 'signed']; + $basic_sig_fields = ['return_to', 'identity']; - $require_fields = array( + $require_fields = [ Auth_OpenID_OPENID2_NS => array_merge($basic_fields, - array('op_endpoint')), + ['op_endpoint']), Auth_OpenID_OPENID1_NS => array_merge($basic_fields, - array('identity')) - ); + ['identity']) + ]; - $require_sigs = array( + $require_sigs = [ Auth_OpenID_OPENID2_NS => array_merge($basic_sig_fields, - array('response_nonce', + [ + 'response_nonce', 'claimed_id', 'assoc_handle', - 'op_endpoint')), + 'op_endpoint' + ]), Auth_OpenID_OPENID1_NS => array_merge($basic_sig_fields, - array('nonce')) - ); + ['nonce']) + ]; foreach ($require_fields[$message->getOpenIDNamespace()] as $field) { if (!$message->hasKey(Auth_OpenID_OPENID_NS, $field)) { @@ -1562,7 +1583,7 @@ class Auth_OpenID_GenericConsumer { $session_type)) { return null; } else { - return array($assoc_type, $session_type); + return [$assoc_type, $session_type]; } } @@ -1756,9 +1777,10 @@ class Auth_OpenID_GenericConsumer { return null; } - $args = array( + $args = [ 'mode' => 'associate', - 'assoc_type' => $assoc_type); + 'assoc_type' => $assoc_type + ]; if (!$endpoint->compatibilityMode()) { $args['ns'] = Auth_OpenID_OPENID2_NS; @@ -1773,7 +1795,7 @@ class Auth_OpenID_GenericConsumer { $args = array_merge($args, $assoc_session->getRequest()); $message = Auth_OpenID_Message::fromOpenIDArgs($args); - return array($assoc_session, $message); + return [$assoc_session, $message]; } /** @@ -1825,6 +1847,21 @@ class Auth_OpenID_GenericConsumer { */ class Auth_OpenID_AuthRequest { + /** @var Auth_OpenID_Association */ + public $assoc; + + /** @var Auth_OpenID_ServiceEndpoint */ + public $endpoint; + + /** @var array */ + public $return_to_args; + + /** @var Auth_OpenID_Message */ + public $message; + + /** @var bool */ + public $_anonymous; + /** * Initialize an authentication request with the specified token, * association, and endpoint. @@ -1840,7 +1877,7 @@ class Auth_OpenID_AuthRequest { { $this->assoc = $assoc; $this->endpoint = $endpoint; - $this->return_to_args = array(); + $this->return_to_args = []; $this->message = new Auth_OpenID_Message($endpoint->preferredNamespace()); $this->_anonymous = false; } @@ -1964,10 +2001,11 @@ class Auth_OpenID_AuthRequest { } $message->updateArgs(Auth_OpenID_OPENID_NS, - array( + [ $realm_key => $realm, 'mode' => $mode, - 'return_to' => $return_to)); + 'return_to' => $return_to + ]); if (!$this->_anonymous) { if ($this->endpoint->isOPIdentifier()) { @@ -2139,7 +2177,7 @@ class Auth_OpenID_SuccessResponse extends Auth_OpenID_ConsumerResponse { public $status = Auth_OpenID_SUCCESS; /** @var array */ - public $signed_args = array(); + public $signed_args = []; /** @var Auth_OpenID_Message */ public $message; @@ -2285,10 +2323,10 @@ class Auth_OpenID_TypeURIMismatch extends Auth_OpenID_FailureResponse { class Auth_OpenID_ServerErrorContainer { /** @var Auth_OpenID_Message */ - private $message; + public $message; /** @var string */ - private $error_code; + public $error_code; /** @var string */ private $error_text; diff --git a/plugins/openid/lib/Auth/OpenID/DatabaseConnection.php b/plugins/openid/lib/Auth/OpenID/DatabaseConnection.php index b74f0afe..903bba31 100644 --- a/plugins/openid/lib/Auth/OpenID/DatabaseConnection.php +++ b/plugins/openid/lib/Auth/OpenID/DatabaseConnection.php @@ -48,7 +48,7 @@ class Auth_OpenID_DatabaseConnection { * underlying database engine. This method is usually used when * the result of a query is not important, like a DDL query. */ - function query($sql, $params = array()) + function query($sql, $params = []) { return null; } @@ -89,7 +89,7 @@ class Auth_OpenID_DatabaseConnection { * first row of the result set. False if no such result was * found. */ - function getOne($sql, $params = array()) + function getOne($sql, $params = []) { return false; } @@ -108,7 +108,7 @@ class Auth_OpenID_DatabaseConnection { * @return array|bool $result The first row of the result set, if any, * keyed on column name. False if no such result was found. */ - function getRow($sql, $params = array()) + function getRow($sql, $params = []) { return false; } @@ -126,9 +126,9 @@ class Auth_OpenID_DatabaseConnection { * @return array $result An array of arrays representing the * result of the query; each array is keyed on column name. */ - function getAll($sql, $params = array()) + function getAll($sql, $params = []) { - return array(); + return []; } } diff --git a/plugins/openid/lib/Auth/OpenID/Discover.php b/plugins/openid/lib/Auth/OpenID/Discover.php index 95c32f45..177d4880 100644 --- a/plugins/openid/lib/Auth/OpenID/Discover.php +++ b/plugins/openid/lib/Auth/OpenID/Discover.php @@ -24,16 +24,18 @@ define('Auth_OpenID_RP_RETURN_TO_URL_TYPE', function Auth_OpenID_getOpenIDTypeURIs() { - return array(Auth_OpenID_TYPE_2_0_IDP, - Auth_OpenID_TYPE_2_0, - Auth_OpenID_TYPE_1_2, - Auth_OpenID_TYPE_1_1, - Auth_OpenID_TYPE_1_0); + return [ + Auth_OpenID_TYPE_2_0_IDP, + Auth_OpenID_TYPE_2_0, + Auth_OpenID_TYPE_1_2, + Auth_OpenID_TYPE_1_1, + Auth_OpenID_TYPE_1_0, + ]; } function Auth_OpenID_getOpenIDConsumerTypeURIs() { - return array(Auth_OpenID_RP_RETURN_TO_URL_TYPE); + return [Auth_OpenID_RP_RETURN_TO_URL_TYPE]; } @@ -67,7 +69,7 @@ class Auth_OpenID_ServiceEndpoint { { $this->claimed_id = null; $this->server_url = null; - $this->type_uris = array(); + $this->type_uris = []; $this->local_id = null; $this->canonicalID = null; $this->used_yadis = false; // whether this came from an XRDS @@ -123,7 +125,7 @@ class Auth_OpenID_ServiceEndpoint { */ function matchTypes($type_uris) { - $result = array(); + $result = []; foreach ($type_uris as $test_uri) { if ($this->supportsType($test_uri)) { $result[] = $test_uri; @@ -157,7 +159,7 @@ class Auth_OpenID_ServiceEndpoint { // a given OP Endpoint URL $obj = new Auth_OpenID_ServiceEndpoint(); $obj->server_url = $op_endpoint_url; - $obj->type_uris = array(Auth_OpenID_TYPE_2_0_IDP); + $obj->type_uris = [Auth_OpenID_TYPE_2_0_IDP]; return $obj; } @@ -210,7 +212,7 @@ class Auth_OpenID_ServiceEndpoint { if ($xrds) { $yadis_services = - $xrds->services(array('filter_MatchesAnyOpenIDConsumerType')); + $xrds->services(['filter_MatchesAnyOpenIDConsumerType']); return Auth_OpenID_makeOpenIDEndpoints($uri, $yadis_services); } @@ -229,7 +231,7 @@ class Auth_OpenID_ServiceEndpoint { if ($xrds) { $yadis_services = - $xrds->services(array('filter_MatchesAnyOpenIDType')); + $xrds->services(['filter_MatchesAnyOpenIDType']); return Auth_OpenID_makeOpenIDEndpoints($uri, $yadis_services); } @@ -258,14 +260,20 @@ class Auth_OpenID_ServiceEndpoint { static function fromHTML($uri, $html) { - $discovery_types = array( - array(Auth_OpenID_TYPE_2_0, - 'openid2.provider', 'openid2.local_id'), - array(Auth_OpenID_TYPE_1_1, - 'openid.server', 'openid.delegate') - ); - - $services = array(); + $discovery_types = [ + [ + Auth_OpenID_TYPE_2_0, + 'openid2.provider', + 'openid2.local_id', + ], + [ + Auth_OpenID_TYPE_1_1, + 'openid.server', + 'openid.delegate', + ], + ]; + + $services = []; foreach ($discovery_types as $triple) { list($type_uri, $server_rel, $delegate_rel) = $triple; @@ -283,7 +291,7 @@ class Auth_OpenID_ServiceEndpoint { $service->claimed_id = $uri; $service->local_id = $delegate_url; $service->server_url = $server_url; - $service->type_uris = array($type_uri); + $service->type_uris = [$type_uri]; $services[] = $service; } @@ -326,7 +334,7 @@ function Auth_OpenID_findOPLocalIdentifier($service, $type_uris) $parser = $service->parser; - $permitted_tags = array(); + $permitted_tags = []; if (in_array(Auth_OpenID_TYPE_1_1, $type_uris) || in_array(Auth_OpenID_TYPE_1_0, $type_uris)) { @@ -416,11 +424,13 @@ function Auth_OpenID_arrangeByType($service_list, $preferred_types) // Build a list with the service elements in tuples whose // comparison will prefer the one with the best matching service - $prio_services = array(); + $prio_services = []; foreach ($service_list as $index => $service) { - $prio_services[] = array(Auth_OpenID_bestMatchingService($service, - $preferred_types), - $index, $service); + $prio_services[] = [ + Auth_OpenID_bestMatchingService($service, $preferred_types), + $index, + $service, + ]; } sort($prio_services); @@ -443,11 +453,9 @@ function Auth_OpenID_arrangeByType($service_list, $preferred_types) // Returns a list of OpenIDServiceEndpoint objects.""" function Auth_OpenID_getOPOrUserServices($openid_services) { - $op_services = Auth_OpenID_arrangeByType($openid_services, - array(Auth_OpenID_TYPE_2_0_IDP)); + $op_services = Auth_OpenID_arrangeByType($openid_services, [Auth_OpenID_TYPE_2_0_IDP]); - $openid_services = Auth_OpenID_arrangeByType($openid_services, - Auth_OpenID_getOpenIDTypeURIs()); + $openid_services = Auth_OpenID_arrangeByType($openid_services, Auth_OpenID_getOpenIDTypeURIs()); if ($op_services) { return $op_services; @@ -463,7 +471,7 @@ function Auth_OpenID_getOPOrUserServices($openid_services) */ function Auth_OpenID_makeOpenIDEndpoints($uri, $yadis_services) { - $s = array(); + $s = []; if (!$yadis_services) { return $s; @@ -504,16 +512,15 @@ function Auth_OpenID_discoverWithYadis($uri, $fetcher, // OpenID 1.0 discovery on the same URL will help, so don't bother // to catch it. if ($discover_function === null) { - $discover_function = array('Auth_Yadis_Yadis', 'discover'); + $discover_function = ['Auth_Yadis_Yadis', 'discover']; } - $response = call_user_func_array($discover_function, - array($uri, $fetcher)); + $response = call_user_func_array($discover_function, [$uri, $fetcher]); $yadis_url = $response->normalized_uri; if ($response->isFailure() && !$response->isXRDS()) { - return array($uri, array()); + return [$uri, []]; } $openid_services = Auth_OpenID_ServiceEndpoint::fromXRDS( @@ -534,9 +541,9 @@ function Auth_OpenID_discoverWithYadis($uri, $fetcher, } $openid_services = call_user_func_array($endpoint_filter, - array($openid_services)); + [$openid_services]); - return array($yadis_url, $openid_services); + return [$yadis_url, $openid_services]; } function Auth_OpenID_discoverURI($uri, $fetcher) @@ -555,7 +562,7 @@ function Auth_OpenID_discoverWithoutYadis($uri, $fetcher) $http_resp = @$fetcher->get($uri); if ($http_resp->status != 200 and $http_resp->status != 206) { - return array($uri, array()); + return [$uri, []]; } $identity_url = $http_resp->final_url; @@ -566,7 +573,7 @@ function Auth_OpenID_discoverWithoutYadis($uri, $fetcher) $identity_url, $http_resp->body); - return array($identity_url, $openid_services); + return [$identity_url, $openid_services]; } function Auth_OpenID_discoverXRI($iname, $fetcher) @@ -575,7 +582,7 @@ function Auth_OpenID_discoverXRI($iname, $fetcher) list($canonicalID, $yadis_services) = $resolver->query($iname, Auth_OpenID_getOpenIDTypeURIs(), - array('filter_MatchesAnyOpenIDType')); + ['filter_MatchesAnyOpenIDType']); $openid_services = Auth_OpenID_makeOpenIDEndpoints($iname, $yadis_services); @@ -589,7 +596,7 @@ function Auth_OpenID_discoverXRI($iname, $fetcher) } // FIXME: returned xri should probably be in some normal form - return array($iname, $openid_services); + return [$iname, $openid_services]; } /** @@ -602,7 +609,7 @@ function Auth_OpenID_discover($uri, $fetcher) // If the fetcher (i.e., PHP) doesn't support SSL, we can't do // discovery on an HTTPS URL. if ($fetcher->isHTTPS($uri) && !$fetcher->supportsSSL()) { - return array($uri, array()); + return [$uri, []]; } if (Auth_Yadis_identifierScheme($uri) == 'XRI') { @@ -614,7 +621,7 @@ function Auth_OpenID_discover($uri, $fetcher) // If the fetcher doesn't support SSL, we can't interact with // HTTPS server URLs; remove those endpoints from the list. if (!$fetcher->supportsSSL()) { - $http_endpoints = array(); + $http_endpoints = []; list($new_uri, $endpoints) = $result; foreach ($endpoints as $e) { @@ -623,7 +630,7 @@ function Auth_OpenID_discover($uri, $fetcher) } } - $result = array($new_uri, $http_endpoints); + $result = [$new_uri, $http_endpoints]; } return $result; diff --git a/plugins/openid/lib/Auth/OpenID/FileStore.php b/plugins/openid/lib/Auth/OpenID/FileStore.php index afeaf2b2..f8378b87 100644 --- a/plugins/openid/lib/Auth/OpenID/FileStore.php +++ b/plugins/openid/lib/Auth/OpenID/FileStore.php @@ -117,11 +117,11 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { $name = Auth_OpenID_FileStore::_mkstemp($dir = $this->temp_dir); $file_obj = @fopen($name, 'wb'); if ($file_obj !== false) { - return array($file_obj, $name); + return [$file_obj, $name]; } else { Auth_OpenID_FileStore::_removeIfPresent($name); } - return array(); + return []; } function cleanupNonces() @@ -265,7 +265,7 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { } else { $association_files = Auth_OpenID_FileStore::_listdir($this->association_dir); - $matching_files = array(); + $matching_files = []; // strip off the path to do the comparison $name = basename($filename); @@ -276,18 +276,20 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { } } - $matching_associations = array(); + $matching_associations = []; // read the matching files and sort by time issued foreach ($matching_files as $full_name) { $association = $this->_getAssociation($full_name); if ($association !== null) { - $matching_associations[] = array($association->issued, - $association); + $matching_associations[] = [ + $association->issued, + $association + ]; } } - $issued = array(); - $assocs = array(); + $issued = []; + $assocs = []; foreach ($matching_associations as $key => $assoc) { $issued[$key] = $assoc[0]; $assocs[$key] = $assoc[1]; @@ -436,7 +438,7 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { */ function _allAssocs() { - $all_associations = array(); + $all_associations = []; $association_filenames = Auth_OpenID_FileStore::_listdir($this->association_dir); @@ -459,8 +461,10 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { $association_filename); } else { if ($association->getExpiresIn() == 0) { - $all_associations[] = array($association_filename, - $association); + $all_associations[] = [ + $association_filename, + $association, + ]; } } } @@ -509,7 +513,7 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { if ($handle = opendir($dir)) { while (false !== ($item = readdir($handle))) { - if (!in_array($item, array('.', '..'))) { + if (!in_array($item, ['.', '..'])) { if (is_dir($dir . $item)) { if (!Auth_OpenID_FileStore::_rmtree($dir . $item)) { @@ -580,9 +584,9 @@ class Auth_OpenID_FileStore extends Auth_OpenID_OpenIDStore { function _listdir($dir) { $handle = opendir($dir); - $files = array(); + $files = []; while (false !== ($filename = readdir($handle))) { - if (!in_array($filename, array('.', '..'))) { + if (!in_array($filename, ['.', '..'])) { $files[] = $dir . DIRECTORY_SEPARATOR . $filename; } } diff --git a/plugins/openid/lib/Auth/OpenID/Interface.php b/plugins/openid/lib/Auth/OpenID/Interface.php index a8a335d5..5335d9f2 100644 --- a/plugins/openid/lib/Auth/OpenID/Interface.php +++ b/plugins/openid/lib/Auth/OpenID/Interface.php @@ -89,7 +89,7 @@ class Auth_OpenID_OpenIDStore { */ function cleanup() { - return array($this->cleanupNonces(), $this->cleanupAssociations()); + return [$this->cleanupNonces(), $this->cleanupAssociations()]; } /** diff --git a/plugins/openid/lib/Auth/OpenID/KVForm.php b/plugins/openid/lib/Auth/OpenID/KVForm.php index f7806533..82ead9cf 100644 --- a/plugins/openid/lib/Auth/OpenID/KVForm.php +++ b/plugins/openid/lib/Auth/OpenID/KVForm.php @@ -41,7 +41,7 @@ class Auth_OpenID_KVForm { } } - $values = array(); + $values = []; for ($lineno = 0; $lineno < count($lines); $lineno++) { $line = $lines[$lineno]; @@ -94,7 +94,7 @@ class Auth_OpenID_KVForm { $serialized = ''; foreach ($values as $key => $value) { if (is_array($value)) { - list($key, $value) = array($value[0], $value[1]); + list($key, $value) = [$value[0], $value[1]]; } if (strpos($key, ':') !== false) { diff --git a/plugins/openid/lib/Auth/OpenID/MDB2Store.php b/plugins/openid/lib/Auth/OpenID/MDB2Store.php index 9349702e..e6cb4c47 100644 --- a/plugins/openid/lib/Auth/OpenID/MDB2Store.php +++ b/plugins/openid/lib/Auth/OpenID/MDB2Store.php @@ -84,7 +84,7 @@ class Auth_OpenID_MDB2Store extends Auth_OpenID_OpenIDStore { // Be sure to set the fetch mode so the results are keyed on // column name instead of column index. $this->connection->setFetchMode(MDB2_FETCHMODE_ASSOC); - + if (@PEAR::isError($this->connection->loadModule('Extended'))) { trigger_error("Unable to load MDB2_Extended module", E_USER_ERROR); return; @@ -144,38 +144,38 @@ class Auth_OpenID_MDB2Store extends Auth_OpenID_OpenIDStore { $this->connection->loadModule('Manager'))) { return false; } - $fields = array( - "server_url" => array( + $fields = [ + "server_url" => [ "type" => "text", "length" => 2047, "notnull" => true - ), - "timestamp" => array( + ], + "timestamp" => [ "type" => "integer", "notnull" => true - ), - "salt" => array( + ], + "salt" => [ "type" => "text", "length" => 40, "fixed" => true, "notnull" => true - ) - ); - $constraint = array( + ] + ]; + $constraint = [ "unique" => 1, - "fields" => array( + "fields" => [ "server_url" => true, "timestamp" => true, "salt" => true - ) - ); - + ] + ]; + $r = $this->connection->createTable($this->nonces_table_name, $fields); if (@PEAR::isError($r)) { return false; } - + $r = $this->connection->createConstraint( $this->nonces_table_name, $this->nonces_table_name . "_constraint", @@ -217,43 +217,43 @@ class Auth_OpenID_MDB2Store extends Auth_OpenID_OpenIDStore { $this->connection->loadModule('Manager'))) { return false; } - $fields = array( - "server_url" => array( + $fields = [ + "server_url" => [ "type" => "text", "length" => 2047, "notnull" => true - ), - "handle" => array( + ], + "handle" => [ "type" => "text", "length" => 255, "notnull" => true - ), - "secret" => array( + ], + "secret" => [ "type" => "blob", "length" => "255", "notnull" => true - ), - "issued" => array( + ], + "issued" => [ "type" => "integer", "notnull" => true - ), - "lifetime" => array( + ], + "lifetime" => [ "type" => "integer", "notnull" => true - ), - "assoc_type" => array( + ], + "assoc_type" => [ "type" => "text", "length" => 64, "notnull" => true - ) - ); - $options = array( - "primary" => array( + ] + ]; + $options = [ + "primary" => [ "server_url" => true, "handle" => true - ) - ); - + ] + ]; + $r = $this->connection->createTable( $this->associations_table_name, $fields, @@ -269,30 +269,30 @@ class Auth_OpenID_MDB2Store extends Auth_OpenID_OpenIDStore { function storeAssociation($server_url, $association) { - $fields = array( - "server_url" => array( + $fields = [ + "server_url" => [ "value" => $server_url, "key" => true - ), - "handle" => array( + ], + "handle" => [ "value" => $association->handle, "key" => true - ), - "secret" => array( + ], + "secret" => [ "value" => $association->secret, "type" => "blob" - ), - "issued" => array( + ], + "issued" => [ "value" => $association->issued - ), - "lifetime" => array( + ], + "lifetime" => [ "value" => $association->lifetime - ), - "assoc_type" => array( + ], + "assoc_type" => [ "value" => $association->assoc_type - ) - ); - + ] + ]; + return !@PEAR::isError($this->connection->replace( $this->associations_table_name, $fields)); @@ -319,25 +319,25 @@ class Auth_OpenID_MDB2Store extends Auth_OpenID_OpenIDStore { { $sql = ""; $params = null; - $types = array( - "text", - "blob", - "integer", - "integer", - "text" - ); + $types = [ + "text", + "blob", + "integer", + "integer", + "text", + ]; if ($handle !== null) { $sql = sprintf("SELECT handle, secret, issued, lifetime, assoc_type " . "FROM %s WHERE server_url = ? AND handle = ?", $this->associations_table_name); - $params = array($server_url, $handle); + $params = [$server_url, $handle]; } else { $sql = sprintf("SELECT handle, secret, issued, lifetime, assoc_type " . "FROM %s WHERE server_url = ? ORDER BY issued DESC", $this->associations_table_name); - $params = array($server_url); + $params = [$server_url]; } - + $assoc = $this->connection->getRow($sql, $types, $params); if (!$assoc || @PEAR::isError($assoc)) { @@ -359,8 +359,8 @@ class Auth_OpenID_MDB2Store extends Auth_OpenID_OpenIDStore { $r = $this->connection->execParam( sprintf("DELETE FROM %s WHERE server_url = ? AND handle = ?", $this->associations_table_name), - array($server_url, $handle)); - + [$server_url, $handle]); + if (@PEAR::isError($r) || $r == 0) { return false; } @@ -374,21 +374,21 @@ class Auth_OpenID_MDB2Store extends Auth_OpenID_OpenIDStore { if (abs($timestamp - time()) > $Auth_OpenID_SKEW ) { return false; } - - $fields = array( - "timestamp" => $timestamp, - "salt" => $salt - ); - + + $fields = [ + "timestamp" => $timestamp, + "salt" => $salt, + ]; + if (!empty($server_url)) { $fields["server_url"] = $server_url; } - + $r = $this->connection->autoExecute( $this->nonces_table_name, $fields, MDB2_AUTOQUERY_INSERT); - + if (@PEAR::isError($r)) { return false; } diff --git a/plugins/openid/lib/Auth/OpenID/MemcachedStore.php b/plugins/openid/lib/Auth/OpenID/MemcachedStore.php index 5badd0ab..900549b0 100644 --- a/plugins/openid/lib/Auth/OpenID/MemcachedStore.php +++ b/plugins/openid/lib/Auth/OpenID/MemcachedStore.php @@ -74,7 +74,7 @@ class Auth_OpenID_MemcachedStore extends Auth_OpenID_OpenIDStore { // if no such list, initialize it with empty array if (!$serverAssociations) { - $serverAssociations = array(); + $serverAssociations = []; } // and store given association key in it $serverAssociations[$association->issued] = $associationKey; diff --git a/plugins/openid/lib/Auth/OpenID/Message.php b/plugins/openid/lib/Auth/OpenID/Message.php index f2cbb3b6..7614d90d 100644 --- a/plugins/openid/lib/Auth/OpenID/Message.php +++ b/plugins/openid/lib/Auth/OpenID/Message.php @@ -56,17 +56,18 @@ define('Auth_OpenID_OPENID1_URL_LIMIT', 2047); // All OpenID protocol fields. Used to check namespace aliases. global $Auth_OpenID_OPENID_PROTOCOL_FIELDS; -$Auth_OpenID_OPENID_PROTOCOL_FIELDS = array( +$Auth_OpenID_OPENID_PROTOCOL_FIELDS = [ 'ns', 'mode', 'error', 'return_to', 'contact', 'reference', 'signed', 'assoc_type', 'session_type', 'dh_modulus', 'dh_gen', 'dh_consumer_public', 'claimed_id', 'identity', 'realm', 'invalidate_handle', 'op_endpoint', 'response_nonce', 'sig', - 'assoc_handle', 'trust_root', 'openid'); + 'assoc_handle', 'trust_root', 'openid' +]; // Global namespace / alias registration map. See // Auth_OpenID_registerNamespaceAlias. global $Auth_OpenID_registered_aliases; -$Auth_OpenID_registered_aliases = array(); +$Auth_OpenID_registered_aliases = []; /** * Registers a (namespace URI, alias) mapping in a global namespace @@ -131,6 +132,10 @@ function Auth_OpenID_removeNamespaceAlias($namespace_uri, $alias) * @package OpenID */ class Auth_OpenID_Mapping { + + private $keys = []; + private $values = []; + /** * Initialize a mapping. If $classic_array is specified, its keys * and values are used to populate the mapping. @@ -139,9 +144,6 @@ class Auth_OpenID_Mapping { */ function __construct($classic_array = null) { - $this->keys = array(); - $this->values = array(); - if (is_array($classic_array)) { foreach ($classic_array as $key => $value) { $this->set($key, $value); @@ -183,11 +185,13 @@ class Auth_OpenID_Mapping { */ function items() { - $temp = array(); + $temp = []; for ($i = 0; $i < count($this->keys); $i++) { - $temp[] = array($this->keys[$i], - $this->values[$i]); + $temp[] = [ + $this->keys[$i], + $this->values[$i] + ]; } return $temp; } @@ -204,7 +208,7 @@ class Auth_OpenID_Mapping { * Sets a key-value pair in the mapping. If the key already * exists, its value is replaced with the new value. * - * @param string $key + * @param string|array $key * @param mixed $value */ function set($key, $value) @@ -224,7 +228,7 @@ class Auth_OpenID_Mapping { * specified key. If the key does not exist in the mapping, * $default is returned instead. * - * @param string $key + * @param string|array $key * @param mixed $default * @return mixed|null */ @@ -249,8 +253,8 @@ class Auth_OpenID_Mapping { $old_keys = $this->keys; $old_values = $this->values; - $this->keys = array(); - $this->values = array(); + $this->keys = []; + $this->values = []; foreach ($old_keys as $k) { $this->keys[] = $k; @@ -265,7 +269,7 @@ class Auth_OpenID_Mapping { * Deletes a key-value pair from the mapping with the specified * key. * - * @param string $key + * @param string|array $key * @return bool */ function del($key) @@ -285,12 +289,12 @@ class Auth_OpenID_Mapping { * Returns true if the specified value has a key in the mapping; * false if not. * - * @param string $value + * @param string|array $key * @return bool */ - function contains($value) + function contains($key) { - return (array_search($value, $this->keys) !== false); + return array_search($key, $this->keys) !== false; } } @@ -300,11 +304,27 @@ class Auth_OpenID_Mapping { * @package OpenID */ class Auth_OpenID_NamespaceMap { + + /** + * @var Auth_OpenID_Mapping + */ + private $alias_to_namespace; + + /** + * @var Auth_OpenID_Mapping + */ + private $namespace_to_alias; + + /** + * @var array + */ + private $implicit_namespaces = []; + function __construct() { $this->alias_to_namespace = new Auth_OpenID_Mapping(); $this->namespace_to_alias = new Auth_OpenID_Mapping(); - $this->implicit_namespaces = array(); + $this->implicit_namespaces = []; } function getAlias($namespace_uri) @@ -440,19 +460,32 @@ class Auth_OpenID_NamespaceMap { */ class Auth_OpenID_Message { + private $allowed_openid_namespaces = [ + Auth_OpenID_OPENID1_NS, + Auth_OpenID_THE_OTHER_OPENID1_NS, + Auth_OpenID_OPENID2_NS + ]; + + /** + * @var Auth_OpenID_Mapping + */ + private $args; + + /** + * @var Auth_OpenID_NamespaceMap + */ + public $namespaces; + + /** + * @var null|string + */ + private $_openid_ns_uri = null; + function __construct($openid_namespace = null) { - // Create an empty Message - $this->allowed_openid_namespaces = array( - Auth_OpenID_OPENID1_NS, - Auth_OpenID_THE_OTHER_OPENID1_NS, - Auth_OpenID_OPENID2_NS); - $this->args = new Auth_OpenID_Mapping(); $this->namespaces = new Auth_OpenID_NamespaceMap(); - if ($openid_namespace === null) { - $this->_openid_ns_uri = null; - } else { + if ($openid_namespace !== null) { $implicit = Auth_OpenID_isOpenID1($openid_namespace); $this->setOpenIDNamespace($openid_namespace, $implicit); } @@ -478,7 +511,7 @@ class Auth_OpenID_Message { $obj = new Auth_OpenID_Message(); // Partition into "openid." args and bare args - $openid_args = array(); + $openid_args = []; foreach ($args as $key => $value) { if (is_array($value)) { @@ -495,7 +528,7 @@ class Auth_OpenID_Message { } if ($prefix != 'openid') { - $obj->args->set(array(Auth_OpenID_BARE_NS, $key), $value); + $obj->args->set([Auth_OpenID_BARE_NS, $key], $value); } else { $openid_args[$rest] = $value; } @@ -534,7 +567,7 @@ class Auth_OpenID_Message { $openid_args = new Auth_OpenID_Mapping($openid_args); } - $ns_args = array(); + $ns_args = []; // Resolve namespaces foreach ($openid_args->items() as $pair) { @@ -560,7 +593,7 @@ class Auth_OpenID_Message { return false; } } else { - $ns_args[] = array($ns_alias, $ns_key, $value); + $ns_args[] = [$ns_alias, $ns_key, $value]; } } @@ -645,7 +678,7 @@ class Auth_OpenID_Message { // Return all arguments with openid. in front of namespaced // arguments. - $args = array(); + $args = []; // Add namespace definitions to the output foreach ($this->namespaces->iteritems() as $pair) { @@ -676,7 +709,7 @@ class Auth_OpenID_Message { // Return all namespaced arguments, failing if any // non-namespaced arguments exist. $post_args = $this->toPostArgs(); - $kvargs = array(); + $kvargs = []; foreach ($post_args as $k => $v) { if (strpos($k, 'openid.') !== 0) { // raise ValueError( @@ -703,7 +736,7 @@ class Auth_OpenID_Message { "enctype=\"application/x-www-form-urlencoded\""; if (!$form_tag_attrs) { - $form_tag_attrs = array(); + $form_tag_attrs = []; } $form_tag_attrs['action'] = $action_url; @@ -752,10 +785,10 @@ class Auth_OpenID_Message { function toURLEncoded() { // Generate an x-www-urlencoded string - $args = array(); + $args = []; foreach ($this->toPostArgs() as $k => $v) { - $args[] = array($k, $v); + $args[] = [$k, $v]; } sort($args); @@ -812,7 +845,7 @@ class Auth_OpenID_Message { // XXX log me return false; } else { - return $this->args->contains(array($namespace, $ns_key)); + return $this->args->contains([$namespace, $ns_key]); } } @@ -857,13 +890,13 @@ class Auth_OpenID_Message { if (Auth_OpenID::isFailure($namespace)) { return $namespace; } else { - if ((!$this->args->contains(array($namespace, $key))) && - ($default == Auth_OpenID_NO_DEFAULT)) { + if ((!$this->args->contains([$namespace, $key])) && + ($default == Auth_OpenID_NO_DEFAULT)) { $err_msg = sprintf("Namespace %s missing required field %s", $namespace, $key); return new Auth_OpenID_FailureResponse(null, $err_msg); } else { - return $this->args->get(array($namespace, $key), $default); + return $this->args->get([$namespace, $key], $default); } } } @@ -876,7 +909,7 @@ class Auth_OpenID_Message { if (Auth_OpenID::isFailure($namespace)) { return $namespace; } else { - $stuff = array(); + $stuff = []; foreach ($this->args->items() as $pair) { list($key, $value) = $pair; list($pair_ns, $ns_key) = $key; @@ -913,7 +946,7 @@ class Auth_OpenID_Message { if (Auth_OpenID::isFailure($namespace)) { return $namespace; } else { - $this->args->set(array($namespace, $key), $value); + $this->args->set([$namespace, $key], $value); if ($namespace !== Auth_OpenID_BARE_NS) { $this->namespaces->add($namespace); } @@ -928,7 +961,7 @@ class Auth_OpenID_Message { if (Auth_OpenID::isFailure($namespace)) { return $namespace; } else { - return $this->args->del(array($namespace, $key)); + return $this->args->del([$namespace, $key]); } } diff --git a/plugins/openid/lib/Auth/OpenID/Nonce.php b/plugins/openid/lib/Auth/OpenID/Nonce.php index 41bb3c32..523eab31 100644 --- a/plugins/openid/lib/Auth/OpenID/Nonce.php +++ b/plugins/openid/lib/Auth/OpenID/Nonce.php @@ -53,7 +53,7 @@ function Auth_OpenID_splitNonce($nonce_string) return null; } - return array($timestamp, $uniquifier); + return [$timestamp, $uniquifier]; } function Auth_OpenID_checkTimestamp($nonce_string, diff --git a/plugins/openid/lib/Auth/OpenID/PAPE.php b/plugins/openid/lib/Auth/OpenID/PAPE.php index f3db7774..8ab7e5f7 100644 --- a/plugins/openid/lib/Auth/OpenID/PAPE.php +++ b/plugins/openid/lib/Auth/OpenID/PAPE.php @@ -38,13 +38,13 @@ class Auth_OpenID_PAPE_Request extends Auth_OpenID_Extension { public $ns_uri = Auth_OpenID_PAPE_NS_URI; private $max_auth_age = 0; - private $preferred_auth_policies = array(); + private $preferred_auth_policies = []; function __construct($preferred_auth_policies=null, $max_auth_age=null) { if ($preferred_auth_policies === null) { - $preferred_auth_policies = array(); + $preferred_auth_policies = []; } $this->preferred_auth_policies = $preferred_auth_policies; @@ -78,10 +78,9 @@ class Auth_OpenID_PAPE_Request extends Auth_OpenID_Extension { */ function getExtensionArgs($request = null) { - $ns_args = array( - 'preferred_auth_policies' => - implode(' ', $this->preferred_auth_policies) - ); + $ns_args = [ + 'preferred_auth_policies' => implode(' ', $this->preferred_auth_policies), + ]; if ($this->max_auth_age !== null) { $ns_args['max_auth_age'] = strval($this->max_auth_age); @@ -102,7 +101,7 @@ class Auth_OpenID_PAPE_Request extends Auth_OpenID_Extension { $obj = new Auth_OpenID_PAPE_Request(); $args = $request->message->getArgs(Auth_OpenID_PAPE_NS_URI); - if ($args === null || $args === array()) { + if ($args === null || $args === []) { return null; } @@ -120,7 +119,7 @@ class Auth_OpenID_PAPE_Request extends Auth_OpenID_Extension { { // preferred_auth_policies is a space-separated list of policy // URIs - $this->preferred_auth_policies = array(); + $this->preferred_auth_policies = []; $policies_str = Auth_OpenID::arrayGet($args, 'preferred_auth_policies'); if ($policies_str) { @@ -156,7 +155,7 @@ class Auth_OpenID_PAPE_Request extends Auth_OpenID_Extension { */ function preferredTypes($supported_types) { - $result = array(); + $result = []; foreach ($supported_types as $st) { if (in_array($st, $this->preferred_auth_policies)) { @@ -178,7 +177,7 @@ class Auth_OpenID_PAPE_Response extends Auth_OpenID_Extension { private $auth_time = 0; private $nist_auth_level = 0; - private $auth_policies = array(); + private $auth_policies = []; function __construct($auth_policies=null, $auth_time=null, $nist_auth_level=null) @@ -186,7 +185,7 @@ class Auth_OpenID_PAPE_Response extends Auth_OpenID_Extension { if ($auth_policies) { $this->auth_policies = $auth_policies; } else { - $this->auth_policies = array(); + $this->auth_policies = []; } $this->auth_time = $auth_time; @@ -227,7 +226,7 @@ class Auth_OpenID_PAPE_Response extends Auth_OpenID_Extension { // PAPE requires that the args be signed. $args = $success_response->getSignedNS(Auth_OpenID_PAPE_NS_URI); - if ($args === null || $args === array()) { + if ($args === null || $args === []) { return null; } @@ -299,7 +298,7 @@ class Auth_OpenID_PAPE_Response extends Auth_OpenID_Extension { */ function getExtensionArgs($request = null) { - $ns_args = array(); + $ns_args = []; if (count($this->auth_policies) > 0) { $ns_args['auth_policies'] = implode(' ', $this->auth_policies); } else { diff --git a/plugins/openid/lib/Auth/OpenID/Parse.php b/plugins/openid/lib/Auth/OpenID/Parse.php index 2e830e9c..fe4b8d24 100644 --- a/plugins/openid/lib/Auth/OpenID/Parse.php +++ b/plugins/openid/lib/Auth/OpenID/Parse.php @@ -113,12 +113,12 @@ class Auth_OpenID_Parse { $this->_link_find = sprintf("/<link\b(?!:)([^>]*)(?!<)>/%s", $this->_re_flags); - $this->_entity_replacements = array( - 'amp' => '&', - 'lt' => '<', - 'gt' => '>', - 'quot' => '"' - ); + $this->_entity_replacements = [ + 'amp' => '&', + 'lt' => '<', + 'gt' => '>', + 'quot' => '"', + ]; $this->_attr_find = sprintf("/%s/%s", $this->_attr_find, @@ -146,7 +146,7 @@ class Auth_OpenID_Parse { $expr = $this->_tag_expr; if ($close_tags) { - $options = implode("|", array_merge(array($tag_name), $close_tags)); + $options = implode("|", array_merge([$tag_name], $close_tags)); $closer = sprintf("(?:%s)", $options); } else { $closer = $tag_name; @@ -170,7 +170,7 @@ class Auth_OpenID_Parse { function htmlBegin($s) { - $matches = array(); + $matches = []; $result = preg_match($this->openTag('html'), $s, $matches, PREG_OFFSET_CAPTURE); if ($result === false || !$matches) { @@ -182,7 +182,7 @@ class Auth_OpenID_Parse { function htmlEnd($s) { - $matches = array(); + $matches = []; $result = preg_match($this->closeTag('html'), $s, $matches, PREG_OFFSET_CAPTURE); if ($result === false || !$matches) { @@ -194,7 +194,7 @@ class Auth_OpenID_Parse { function headFind() { - return $this->tagMatcher('head', array('body', 'html')); + return $this->tagMatcher('head', ['body', 'html']); } function replaceEntities($str) @@ -207,7 +207,7 @@ class Auth_OpenID_Parse { function removeQuotes($str) { - $matches = array(); + $matches = []; $double = '/^"(.*)"$/'; $single = "/^\'(.*)\'$/"; @@ -251,7 +251,7 @@ class Auth_OpenID_Parse { $html_end = $this->htmlEnd($stripped); if ($html_begin === false) { - return array(); + return []; } if ($html_end === false) { @@ -266,25 +266,25 @@ class Auth_OpenID_Parse { // Try to find the <HEAD> tag. $head_re = $this->headFind(); - $head_match = array(); + $head_match = []; if (!$this->match($head_re, $stripped, $head_match)) { ini_set( 'pcre.backtrack_limit', $old_btlimit ); - return array(); + return []; } - $link_data = array(); - $link_matches = array(); + $link_data = []; + $link_matches = []; if (!preg_match_all($this->_link_find, $head_match[0], $link_matches)) { ini_set( 'pcre.backtrack_limit', $old_btlimit ); - return array(); + return []; } foreach ($link_matches[0] as $link) { - $attr_matches = array(); + $attr_matches = []; preg_match_all($this->_attr_find, $link, $attr_matches); - $link_attrs = array(); + $link_attrs = []; foreach ($attr_matches[0] as $index => $full_match) { $name = $attr_matches[1][$index]; $value = $this->replaceEntities( @@ -328,7 +328,7 @@ class Auth_OpenID_Parse { // Filter the list of link attributes on whether it has // target_rel as a relationship. // XXX: TESTME - $result = array(); + $result = []; foreach ($link_attrs_list as $attr) { if ($this->linkHasRel($attr, $target_rel)) { $result[] = $attr; @@ -368,7 +368,7 @@ function Auth_OpenID_legacy_discover($html_text, $server_rel, } else { $delegate_url = $p->findFirstHref($link_attrs, $delegate_rel); - return array($delegate_url, $server_url); + return [$delegate_url, $server_url]; } } diff --git a/plugins/openid/lib/Auth/OpenID/PostgreSQLStore.php b/plugins/openid/lib/Auth/OpenID/PostgreSQLStore.php index d90e43e0..a3a33684 100644 --- a/plugins/openid/lib/Auth/OpenID/PostgreSQLStore.php +++ b/plugins/openid/lib/Auth/OpenID/PostgreSQLStore.php @@ -29,7 +29,7 @@ class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore { "UNIQUE (server_url, timestamp, salt))"; $this->sql['assoc_table'] = - "CREATE TABLE %s (server_url VARCHAR(2047) NOT NULL, ". + "CREATE TABLE %s (server_url VARCHAR(2047) NOT NULL, ". "handle VARCHAR(255) NOT NULL, ". "secret BYTEA NOT NULL, ". "issued INTEGER NOT NULL, ". @@ -40,14 +40,14 @@ class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore { "(LENGTH(secret) <= 128))"; $this->sql['set_assoc'] = - array( + [ 'insert_assoc' => "INSERT INTO %s (server_url, handle, ". "secret, issued, lifetime, assoc_type) VALUES ". "(?, ?, '!', ?, ?, ?)", 'update_assoc' => "UPDATE %s SET secret = '!', issued = ?, ". "lifetime = ?, assoc_type = ? WHERE server_url = ? AND ". "handle = ?" - ); + ]; $this->sql['get_assocs'] = "SELECT handle, secret, issued, lifetime, assoc_type FROM %s ". @@ -82,14 +82,27 @@ class Auth_OpenID_PostgreSQLStore extends Auth_OpenID_SQLStore { if ($result) { // Update the table since this associations already exists. $this->connection->query($this->sql['set_assoc']['update_assoc'], - array($secret, $issued, $lifetime, - $assoc_type, $server_url, $handle)); + [ + $secret, + $issued, + $lifetime, + $assoc_type, + $server_url, + $handle, + ]); } else { // Insert a new record because this association wasn't // found. $this->connection->query($this->sql['set_assoc']['insert_assoc'], - array($server_url, $handle, $secret, - $issued, $lifetime, $assoc_type)); + [ + $server_url, + $handle, + $secret, + $issued, + $lifetime, + $assoc_type, + ] + ); } } diff --git a/plugins/openid/lib/Auth/OpenID/SQLStore.php b/plugins/openid/lib/Auth/OpenID/SQLStore.php index b2a953d6..0829abb4 100644 --- a/plugins/openid/lib/Auth/OpenID/SQLStore.php +++ b/plugins/openid/lib/Auth/OpenID/SQLStore.php @@ -69,7 +69,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { protected $max_nonce_age = 0; /** @var array */ - protected $sql = array(); + protected $sql = []; /** * This creates a new SQLStore instance. It requires an @@ -136,7 +136,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { $this->connection->autoCommit(false); // Create an empty SQL strings array. - $this->sql = array(); + $this->sql = []; // Call this method (which should be overridden by subclasses) // to populate the $this->sql array with SQL strings. @@ -223,17 +223,17 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { */ function _verifySQL() { - $missing = array(); - $empty = array(); - - $required_sql_keys = array( - 'nonce_table', - 'assoc_table', - 'set_assoc', - 'get_assoc', - 'get_assocs', - 'remove_assoc' - ); + $missing = []; + $empty = []; + + $required_sql_keys = [ + 'nonce_table', + 'assoc_table', + 'set_assoc', + 'get_assoc', + 'get_assocs', + 'remove_assoc', + ]; foreach ($required_sql_keys as $key) { if (!array_key_exists($key, $this->sql)) { @@ -243,7 +243,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { } } - return array($missing, $empty); + return [$missing, $empty]; } /** @@ -251,23 +251,27 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { */ function _fixSQL() { - $replacements = array( - array( - 'value' => $this->nonces_table_name, - 'keys' => array('nonce_table', - 'add_nonce', - 'clean_nonce') - ), - array( - 'value' => $this->associations_table_name, - 'keys' => array('assoc_table', - 'set_assoc', - 'get_assoc', - 'get_assocs', - 'remove_assoc', - 'clean_assoc') - ) - ); + $replacements = [ + [ + 'value' => $this->nonces_table_name, + 'keys' => [ + 'nonce_table', + 'add_nonce', + 'clean_nonce', + ], + ], + [ + 'value' => $this->associations_table_name, + 'keys' => [ + 'assoc_table', + 'set_assoc', + 'get_assoc', + 'get_assocs', + 'remove_assoc', + 'clean_assoc', + ], + ], + ]; foreach ($replacements as $item) { $value = $item['value']; @@ -276,8 +280,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { foreach ($keys as $k) { if (is_array($this->sql[$k])) { foreach ($this->sql[$k] as $part_key => $part_value) { - $this->sql[$k][$part_key] = sprintf($part_value, - $value); + $this->sql[$k][$part_key] = sprintf($part_value, $value); } } else { $this->sql[$k] = sprintf($this->sql[$k], $value); @@ -342,13 +345,14 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { $lifetime, $assoc_type) { return $this->connection->query($this->sql['set_assoc'], - array( - $server_url, - $handle, - $secret, - $issued, - $lifetime, - $assoc_type)); + [ + $server_url, + $handle, + $secret, + $issued, + $lifetime, + $assoc_type, + ]); } function storeAssociation($server_url, $association) @@ -377,7 +381,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { function _get_assoc($server_url, $handle) { $result = $this->connection->getRow($this->sql['get_assoc'], - array($server_url, $handle)); + [$server_url, $handle]); if ($this->isError($result)) { return null; } else { @@ -393,10 +397,10 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { function _get_assocs($server_url) { $result = $this->connection->getAll($this->sql['get_assocs'], - array($server_url)); + [$server_url]); if ($this->isError($result)) { - return array(); + return []; } else { return $result; } @@ -410,7 +414,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { if ($this->resultToBool($this->connection->query( $this->sql['remove_assoc'], - array($server_url, $handle)))) { + [$server_url, $handle]))) { $this->connection->commit(); } else { $this->connection->rollback(); @@ -424,7 +428,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { if ($handle !== null) { $assoc = $this->_get_assoc($server_url, $handle); - $assocs = array(); + $assocs = []; if ($assoc) { $assocs[] = $assoc; } @@ -435,7 +439,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { if (!$assocs || (count($assocs) == 0)) { return null; } else { - $associations = array(); + $associations = []; foreach ($assocs as $assoc_row) { $assoc = new Auth_OpenID_Association($assoc_row['handle'], @@ -449,13 +453,13 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { if ($assoc->getExpiresIn() == 0) { $this->removeAssociation($server_url, $assoc->handle); } else { - $associations[] = array($assoc->issued, $assoc); + $associations[] = [$assoc->issued, $assoc]; } } if ($associations) { - $issued = array(); - $assocs = array(); + $issued = []; + $assocs = []; foreach ($associations as $key => $assoc) { $issued[$key] = $assoc[0]; $assocs[$key] = $assoc[1]; @@ -483,9 +487,11 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { function _add_nonce($server_url, $timestamp, $salt) { $sql = $this->sql['add_nonce']; - $result = $this->connection->query($sql, array($server_url, - $timestamp, - $salt)); + $result = $this->connection->query($sql, [ + $server_url, + $timestamp, + $salt, + ]); if ($this->isError($result)) { $this->connection->rollback(); } else { @@ -571,7 +577,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { global $Auth_OpenID_SKEW; $v = time() - $Auth_OpenID_SKEW; - $this->connection->query($this->sql['clean_nonce'], array($v)); + $this->connection->query($this->sql['clean_nonce'], [$v]); $num = $this->connection->affectedRows(); $this->connection->commit(); return $num; @@ -579,7 +585,7 @@ class Auth_OpenID_SQLStore extends Auth_OpenID_OpenIDStore { function cleanupAssociations() { - $this->connection->query($this->sql['clean_assoc'], array(time())); + $this->connection->query($this->sql['clean_assoc'], [time()]); $num = $this->connection->affectedRows(); $this->connection->commit(); return $num; diff --git a/plugins/openid/lib/Auth/OpenID/SReg.php b/plugins/openid/lib/Auth/OpenID/SReg.php index 78259f3a..a3d2715e 100644 --- a/plugins/openid/lib/Auth/OpenID/SReg.php +++ b/plugins/openid/lib/Auth/OpenID/SReg.php @@ -47,16 +47,17 @@ require_once 'Auth/OpenID/Extension.php'; // The data fields that are listed in the sreg spec global $Auth_OpenID_sreg_data_fields; -$Auth_OpenID_sreg_data_fields = array( - 'fullname' => 'Full Name', - 'nickname' => 'Nickname', - 'dob' => 'Date of Birth', - 'email' => 'E-mail Address', - 'gender' => 'Gender', - 'postcode' => 'Postal Code', - 'country' => 'Country', - 'language' => 'Language', - 'timezone' => 'Time Zone'); +$Auth_OpenID_sreg_data_fields = [ + 'fullname' => 'Full Name', + 'nickname' => 'Nickname', + 'dob' => 'Date of Birth', + 'email' => 'E-mail Address', + 'gender' => 'Gender', + 'postcode' => 'Postal Code', + 'country' => 'Country', + 'language' => 'Language', + 'timezone' => 'Time Zone', +]; /** * Check to see that the given value is a valid simple registration @@ -135,8 +136,7 @@ class Auth_OpenID_SRegBase extends Auth_OpenID_Extension { // See if there exists an alias for one of the two defined // simple registration types. - foreach (array(Auth_OpenID_SREG_NS_URI_1_1, - Auth_OpenID_SREG_NS_URI_1_0) as $sreg_ns_uri) { + foreach ([Auth_OpenID_SREG_NS_URI_1_1, Auth_OpenID_SREG_NS_URI_1_0] as $sreg_ns_uri) { $alias = $message->namespaces->getAlias($sreg_ns_uri); if ($alias !== null) { $found_ns_uri = $sreg_ns_uri; @@ -177,9 +177,9 @@ class Auth_OpenID_SRegRequest extends Auth_OpenID_SRegBase { /** @var string */ public $ns_alias = 'sreg'; /** @var array */ - public $required = array(); + public $required = []; /** @var array */ - public $optional = array(); + public $optional = []; /** @var string */ public $policy_url = ''; @@ -201,8 +201,8 @@ class Auth_OpenID_SRegRequest extends Auth_OpenID_SRegBase { /** @var Auth_OpenID_SRegRequest $obj */ $obj = new $cls(); - $obj->required = array(); - $obj->optional = array(); + $obj->required = []; + $obj->optional = []; $obj->policy_url = $policy_url; $obj->ns_uri = $sreg_ns_uri; @@ -241,8 +241,8 @@ class Auth_OpenID_SRegRequest extends Auth_OpenID_SRegBase { static function fromOpenIDRequest($request, $cls='Auth_OpenID_SRegRequest') { - $obj = call_user_func_array(array($cls, 'build'), - array(null, null, null, Auth_OpenID_SREG_NS_URI, $cls)); + $obj = call_user_func_array([$cls, 'build'], + [null, null, null, Auth_OpenID_SREG_NS_URI, $cls]); // Since we're going to mess with namespace URI mapping, don't // mutate the object that was passed in. @@ -290,7 +290,7 @@ class Auth_OpenID_SRegRequest extends Auth_OpenID_SRegBase { */ function parseExtensionArgs($args, $strict=false) { - foreach (array('required', 'optional') as $list_name) { + foreach (['required', 'optional'] as $list_name) { $required = ($list_name == 'required'); $items = Auth_OpenID::arrayGet($args, $list_name); if ($items) { @@ -433,7 +433,7 @@ class Auth_OpenID_SRegRequest extends Auth_OpenID_SRegBase { */ function getExtensionArgs($request = null) { - $args = array(); + $args = []; if ($this->required) { $args['required'] = implode(',', $this->required); @@ -465,7 +465,7 @@ class Auth_OpenID_SRegResponse extends Auth_OpenID_SRegBase { public $ns_alias = 'sreg'; /** @var array */ - public $data = array(); + public $data = []; function __construct($data=null, $sreg_ns_uri=Auth_OpenID_SREG_NS_URI) { diff --git a/plugins/openid/lib/Auth/OpenID/Server.php b/plugins/openid/lib/Auth/OpenID/Server.php index 0901d507..6af8c7c3 100644 --- a/plugins/openid/lib/Auth/OpenID/Server.php +++ b/plugins/openid/lib/Auth/OpenID/Server.php @@ -111,8 +111,10 @@ define('AUTH_OPENID_HTTP_ERROR', 400); * @access private */ global $_Auth_OpenID_Request_Modes; -$_Auth_OpenID_Request_Modes = array('checkid_setup', - 'checkid_immediate'); +$_Auth_OpenID_Request_Modes = [ + 'checkid_setup', + 'checkid_immediate', +]; /** * @access private @@ -222,8 +224,11 @@ class Auth_OpenID_ServerError { function encodeToKVForm() { return Auth_OpenID_KVForm::fromArray( - array('mode' => 'error', - 'error' => $this->toString())); + [ + 'mode' => 'error', + 'error' => $this->toString(), + ] + ); } function toFormMarkup($form_tag_attrs=null) @@ -411,7 +416,7 @@ class Auth_OpenID_CheckAuthRequest extends Auth_OpenID_Request { */ static function fromMessage($message) { - $required_keys = array('assoc_handle', 'sig', 'signed'); + $required_keys = ['assoc_handle', 'sig', 'signed']; foreach ($required_keys as $k) { if (!$message->getArg(Auth_OpenID_OPENID_NS, $k)) { @@ -478,7 +483,7 @@ class Auth_OpenID_PlainTextServerSession { */ public $session_type = 'no-encryption'; public $needs_math = false; - public $allowed_assoc_types = array('HMAC-SHA1', 'HMAC-SHA256'); + public $allowed_assoc_types = ['HMAC-SHA1', 'HMAC-SHA256']; static function fromMessage() { @@ -487,7 +492,7 @@ class Auth_OpenID_PlainTextServerSession { function answer($secret) { - return array('mac_key' => base64_encode($secret)); + return ['mac_key' => base64_encode($secret)]; } } @@ -504,7 +509,7 @@ class Auth_OpenID_DiffieHellmanSHA1ServerSession { public $session_type = 'DH-SHA1'; public $needs_math = true; - public $allowed_assoc_types = array('HMAC-SHA1'); + public $allowed_assoc_types = ['HMAC-SHA1']; public $hash_func = 'Auth_OpenID_SHA1'; /** @var Auth_OpenID_DiffieHellman */ @@ -579,7 +584,7 @@ class Auth_OpenID_DiffieHellmanSHA1ServerSession { "dh_consumer_public is not base64"); } - return array($dh, $consumer_pubkey); + return [$dh, $consumer_pubkey]; } static function fromMessage($message) @@ -600,10 +605,11 @@ class Auth_OpenID_DiffieHellmanSHA1ServerSession { $lib = Auth_OpenID_getMathLib(); $mac_key = $this->dh->xorSecret($this->consumer_pubkey, $secret, $this->hash_func); - return array( + return [ 'dh_server_public' => $lib->longToBase64($this->dh->public), - 'enc_mac_key' => base64_encode($mac_key)); + 'enc_mac_key' => base64_encode($mac_key) + ]; } } @@ -617,7 +623,7 @@ class Auth_OpenID_DiffieHellmanSHA256ServerSession public $session_type = 'DH-SHA256'; public $hash_func = 'Auth_OpenID_SHA256'; - public $allowed_assoc_types = array('HMAC-SHA256'); + public $allowed_assoc_types = ['HMAC-SHA256']; static function fromMessage($message) { @@ -648,10 +654,11 @@ class Auth_OpenID_AssociateRequest extends Auth_OpenID_Request { static function getSessionClasses() { - return array( + return [ 'no-encryption' => 'Auth_OpenID_PlainTextServerSession', 'DH-SHA1' => 'Auth_OpenID_DiffieHellmanSHA1ServerSession', - 'DH-SHA256' => 'Auth_OpenID_DiffieHellmanSHA256ServerSession'); + 'DH-SHA256' => 'Auth_OpenID_DiffieHellmanSHA256ServerSession' + ]; } /** @@ -702,7 +709,7 @@ class Auth_OpenID_AssociateRequest extends Auth_OpenID_Request { $session_type); } - $session = call_user_func(array($session_class, 'fromMessage'), + $session = call_user_func([$session_class, 'fromMessage'], $message); if (is_a($session, 'Auth_OpenID_ServerError')) { return $session; @@ -731,10 +738,12 @@ class Auth_OpenID_AssociateRequest extends Auth_OpenID_Request { { $response = new Auth_OpenID_ServerResponse($this); $response->fields->updateArgs(Auth_OpenID_OPENID_NS, - array( - 'expires_in' => sprintf('%d', $assoc->getExpiresIn()), - 'assoc_type' => $this->assoc_type, - 'assoc_handle' => $assoc->handle)); + [ + 'expires_in' => sprintf('%d', $assoc->getExpiresIn()), + 'assoc_type' => $this->assoc_type, + 'assoc_handle' => $assoc->handle, + ] + ); $response->fields->updateArgs(Auth_OpenID_OPENID_NS, $this->session->answer($assoc->secret)); @@ -925,7 +934,7 @@ class Auth_OpenID_CheckIDRequest extends Auth_OpenID_Request { { $fetcher = Auth_Yadis_Yadis::getHTTPFetcher(); return call_user_func_array($this->verifyReturnTo, - array($this->trust_root, $this->return_to, $fetcher)); + [$this->trust_root, $this->return_to, $fetcher]); } /** @@ -1171,9 +1180,12 @@ class Auth_OpenID_CheckIDRequest extends Auth_OpenID_Request { } $response->fields->updateArgs(Auth_OpenID_OPENID_NS, - array('mode' => $mode, - 'return_to' => $this->return_to, - 'response_nonce' => Auth_OpenID_mkNonce())); + [ + 'mode' => $mode, + 'return_to' => $this->return_to, + 'response_nonce' => Auth_OpenID_mkNonce(), + ] + ); if (!$this->message->isOpenID1()) { $response->fields->setArg(Auth_OpenID_OPENID_NS, @@ -1241,10 +1253,12 @@ class Auth_OpenID_CheckIDRequest extends Auth_OpenID_Request { // Encodable too. That's right, code imported from alternate // realities all for the love of you, id_res/user_setup_url. - $q = array('mode' => $this->mode, - 'identity' => $this->identity, - 'claimed_id' => $this->claimed_id, - 'return_to' => $this->return_to); + $q = [ + 'mode' => $this->mode, + 'identity' => $this->identity, + 'claimed_id' => $this->claimed_id, + 'return_to' => $this->return_to, + ]; if ($this->trust_root) { if ($this->message->isOpenID1()) { @@ -1399,7 +1413,7 @@ class Auth_OpenID_WebResponse { if ($headers !== null) { $this->headers = $headers; } else { - $this->headers = array(); + $this->headers = []; } if ($body !== null) { @@ -1608,9 +1622,9 @@ class Auth_OpenID_Encoder { } else if ($encode_as == Auth_OpenID_ENCODE_URL) { $location = $response->encodeToURL(); $wr = new $cls(AUTH_OPENID_HTTP_REDIRECT, - array('location' => $location)); + ['location' => $location]); } else if ($encode_as == Auth_OpenID_ENCODE_HTML_FORM) { - $wr = new $cls(AUTH_OPENID_HTTP_OK, array(), + $wr = new $cls(AUTH_OPENID_HTTP_OK, [], $response->toHTML()); } else { return new Auth_OpenID_EncodingError($response); @@ -1682,12 +1696,12 @@ class Auth_OpenID_Decoder { /** @var Auth_OpenID_Server */ private $server; - private $handlers = array( + private $handlers = [ 'checkid_setup' => 'Auth_OpenID_CheckIDRequest', 'checkid_immediate' => 'Auth_OpenID_CheckIDRequest', 'check_authentication' => 'Auth_OpenID_CheckAuthRequest', 'associate' => 'Auth_OpenID_AssociateRequest' - ); + ]; /** * Auth_OpenID_Decoder constructor. @@ -1746,8 +1760,8 @@ class Auth_OpenID_Decoder { $this->defaultDecoder($message)); if (!is_a($handlerCls, 'Auth_OpenID_ServerError')) { - return call_user_func_array(array($handlerCls, 'fromMessage'), - array($message, $this->server)); + return call_user_func_array([$handlerCls, 'fromMessage'], + [$message, $this->server]); } else { return $handlerCls; } @@ -1909,8 +1923,8 @@ class Auth_OpenID_Server { function handleRequest($request) { if (method_exists($this, "openid_" . $request->mode)) { - $handler = array($this, "openid_" . $request->mode); - return call_user_func_array($handler, array($request)); + $handler = [$this, "openid_" . $request->mode]; + return call_user_func_array($handler, [$request]); } return null; } diff --git a/plugins/openid/lib/Auth/OpenID/TrustRoot.php b/plugins/openid/lib/Auth/OpenID/TrustRoot.php index 379366b7..8842fb5a 100644 --- a/plugins/openid/lib/Auth/OpenID/TrustRoot.php +++ b/plugins/openid/lib/Auth/OpenID/TrustRoot.php @@ -109,14 +109,14 @@ class Auth_OpenID_TrustRoot { return false; } - $required_parts = array('scheme', 'host'); - $forbidden_parts = array('user', 'pass', 'fragment'); + $required_parts = ['scheme', 'host']; + $forbidden_parts = ['user', 'pass', 'fragment']; $keys = array_keys($parts); if (array_intersect($keys, $required_parts) != $required_parts) { return false; } - if (array_intersect($keys, $forbidden_parts) != array()) { + if (array_intersect($keys, $forbidden_parts) != []) { return false; } @@ -125,7 +125,7 @@ class Auth_OpenID_TrustRoot { } $scheme = strtolower($parts['scheme']); - $allowed_schemes = array('http', 'https'); + $allowed_schemes = ['http', 'https']; if (!in_array($scheme, $allowed_schemes)) { return false; } @@ -343,7 +343,7 @@ class Auth_OpenID_TrustRoot { */ function filter_extractReturnURL($endpoint) { - if ($endpoint->matchTypes(array(Auth_OpenID_RP_RETURN_TO_URL_TYPE))) { + if ($endpoint->matchTypes([Auth_OpenID_RP_RETURN_TO_URL_TYPE])) { return $endpoint; } else { return null; @@ -352,7 +352,7 @@ function filter_extractReturnURL($endpoint) function &Auth_OpenID_extractReturnURL(&$endpoint_list) { - $result = array(); + $result = []; foreach ($endpoint_list as $endpoint) { if (filter_extractReturnURL($endpoint)) { @@ -398,10 +398,10 @@ function Auth_OpenID_getAllowedReturnURLs($relying_party_url, $fetcher, $discover_function=null) { if ($discover_function === null) { - $discover_function = array('Auth_Yadis_Yadis', 'discover'); + $discover_function = ['Auth_Yadis_Yadis', 'discover']; } - $xrds_parse_cb = array('Auth_OpenID_ServiceEndpoint', 'consumerFromXRDS'); + $xrds_parse_cb = ['Auth_OpenID_ServiceEndpoint', 'consumerFromXRDS']; list($rp_url_after_redirects, $endpoints) = Auth_Yadis_getServiceEndpoints($relying_party_url, $xrds_parse_cb, @@ -413,9 +413,9 @@ function Auth_OpenID_getAllowedReturnURLs($relying_party_url, $fetcher, } call_user_func_array($discover_function, - array($relying_party_url, $fetcher)); + [$relying_party_url, $fetcher]); - $return_to_urls = array(); + $return_to_urls = []; $matching_endpoints = Auth_OpenID_extractReturnURL($endpoints); foreach ($matching_endpoints as $e) { @@ -445,7 +445,7 @@ function Auth_OpenID_verifyReturnTo($realm_str, $return_to, $fetcher, } $allowable_urls = call_user_func_array($_vrfy, - array($disco_url, $fetcher)); + [$disco_url, $fetcher]); // The realm_str could not be parsed. if ($allowable_urls === false) { diff --git a/plugins/openid/lib/Auth/OpenID/URINorm.php b/plugins/openid/lib/Auth/OpenID/URINorm.php index f8c73ada..b088f6f3 100644 --- a/plugins/openid/lib/Auth/OpenID/URINorm.php +++ b/plugins/openid/lib/Auth/OpenID/URINorm.php @@ -40,7 +40,7 @@ function Auth_OpenID_getURLIllegalCharRE() function Auth_OpenID_getUnreserved() { - $_unreserved = array(); + $_unreserved = []; for ($i = 0; $i < 256; $i++) { $_unreserved[$i] = false; } @@ -67,7 +67,7 @@ function Auth_OpenID_getUnreserved() function Auth_OpenID_getEscapeRE() { - $parts = array(); + $parts = []; foreach (array_merge(Auth_Yadis_getUCSChars(), Auth_Yadis_getIPrivateChars()) as $pair) { list($m, $n) = $pair; @@ -105,7 +105,7 @@ function Auth_OpenID_pct_encoded_replace($mo) function Auth_OpenID_remove_dot_segments($path) { - $result_segments = array(); + $result_segments = []; while ($path) { if (Auth_Yadis_startswith($path, '../')) { @@ -148,7 +148,7 @@ function Auth_OpenID_remove_dot_segments($path) function Auth_OpenID_urinorm($uri) { - $uri_matches = array(); + $uri_matches = []; preg_match(Auth_OpenID_getURIPattern(), $uri, $uri_matches); if (count($uri_matches) < 9) { @@ -157,7 +157,7 @@ function Auth_OpenID_urinorm($uri) } } - $illegal_matches = array(); + $illegal_matches = []; preg_match(Auth_OpenID_getURLIllegalCharRE(), $uri, $illegal_matches); if ($illegal_matches) { @@ -171,7 +171,7 @@ function Auth_OpenID_urinorm($uri) } $scheme = strtolower($scheme); - if (!in_array($scheme, array('http', 'https'))) { + if (!in_array($scheme, ['http', 'https'])) { // Not an absolute HTTP or HTTPS URI return null; } @@ -182,7 +182,7 @@ function Auth_OpenID_urinorm($uri) return null; } - $authority_matches = array(); + $authority_matches = []; preg_match(Auth_OpenID_getAuthorityPattern(), $authority, $authority_matches); if (count($authority_matches) === 0) { |