diff --git a/modules/openid/openid.inc b/modules/openid/openid.inc index dfa71a95efbf5afa7f9e6ed61bddb2ddd50bb75f..6945f34ed5a8a3a18de3cd7a1e0edf52c4fd9d3f 100644 --- a/modules/openid/openid.inc +++ b/modules/openid/openid.inc @@ -188,32 +188,33 @@ function _openid_select_service(array $services) { // Extensible Resource Identifier (XRI) Resolution Version 2.0, section 4.3.3: // Find the service with the highest priority (lowest integer value). If there // is a tie, select a random one, not just the first in the XML document. - $selected_service = NULL; shuffle($services); + $selected_service = NULL; + $selected_type_priority = FALSE; // Search for an OP Identifier Element. foreach ($services as $service) { if (!empty($service['uri'])) { + $type_priority = FALSE; if (in_array('http://specs.openid.net/auth/2.0/server', $service['types'])) { $service['version'] = 2; + $type_priority = 1; + } + elseif (in_array('http://specs.openid.net/auth/2.0/signon', $service['types'])) { + $service['version'] = 2; + $type_priority = 2; } elseif (in_array(OPENID_NS_1_0, $service['types']) || in_array(OPENID_NS_1_1, $service['types'])) { $service['version'] = 1; + $type_priority = 3; } - if (isset($service['version']) && (!$selected_service || $service['priority'] < $selected_service['priority'])) { - $selected_service = $service; - } - } - } - if (!$selected_service) { - // Search for Claimed Identifier Element. - foreach ($services as $service) { - if (!empty($service['uri']) && in_array('http://specs.openid.net/auth/2.0/signon', $service['types'])) { - $service['version'] = 2; - if (!$selected_service || $service['priority'] < $selected_service['priority']) { - $selected_service = $service; - } + if ($type_priority + && (!$selected_service + || $type_priority < $selected_type_priority + || ($type_priority == $selected_type_priority && $service['priority'] < $selected_service['priority']))) { + $selected_service = $service; + $selected_type_priority = $type_priority; } } } diff --git a/modules/openid/tests/openid_test.module b/modules/openid/tests/openid_test.module index d2afa9f595f08ff5403d71ac2125b37eee008690..bad1184a311a07c70228fe2d3b99f55f2e01fa12 100644 --- a/modules/openid/tests/openid_test.module +++ b/modules/openid/tests/openid_test.module @@ -105,6 +105,10 @@ function openid_test_yadis_xrds() { <Service> <Type>http://example.com/this-is-ignored</Type> </Service> + <Service priority="5"> + <Type>http://openid.net/signon/1.0</Type> + <URI>http://example.com/this-is-only-openid-1.0</URI> + </Service> <Service priority="10"> <Type>http://specs.openid.net/auth/2.0/signon</Type> <Type>http://openid.net/srv/ax/1.0</Type> @@ -133,7 +137,7 @@ function openid_test_yadis_xrds() { } elseif (arg(3) == 'delegate') { print ' - <Service priority="5"> + <Service priority="0"> <Type>http://specs.openid.net/auth/2.0/signon</Type> <Type>http://openid.net/srv/ax/1.0</Type> <URI>' . url('openid-test/endpoint', array('absolute' => TRUE)) . '</URI>