Index: modules/openid/openid.inc
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.inc,v
retrieving revision 1.26
diff -u -9 -p -r1.26 openid.inc
--- modules/openid/openid.inc	6 Mar 2010 06:39:00 -0000	1.26
+++ modules/openid/openid.inc	11 Mar 2010 21:43:15 -0000
@@ -600,9 +600,35 @@ function openid_extract_namespace($respo
   foreach ($response as $key => $value) {
     if (preg_match('/^openid\.' . $prefix . '\.(.+)$/', $key, $matches)) {
       $local_key = $matches[1];
       $output[$local_key] = $value;
     }
   }
 
   return $output;
 }
+
+/**
+ * Extracts the values with the specified aliases from an OpenID AX Response.
+ *
+ * @param $values
+ *   An array as returned by openid_extract_namespace(..., OPENID_NS_AX).
+ * @param $aliases
+ *   An array of aliases used in the fetch request.
+ * @return
+ *   An array of values.
+ */
+function openid_extract_ax_values($values, $aliases) {
+  $output = array();
+  foreach ($aliases as $alias) {
+    if (isset($values['count.' . $alias])) {
+      for ($i = 1; $i <= $values['count.' . $alias]; $i++) {
+        $output[] = $values['value.' . $alias . '.' . $i];
+      }
+    }
+    elseif (isset($values['value.' . $alias])) {
+      $output[] = $values['value.' . $alias];
+    }
+  }
+  return $output;
+}
+
Index: modules/openid/openid.module
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.module,v
retrieving revision 1.75
diff -u -9 -p -r1.75 openid.module
--- modules/openid/openid.module	9 Mar 2010 12:07:37 -0000	1.75
+++ modules/openid/openid.module	11 Mar 2010 21:43:15 -0000
@@ -560,34 +560,33 @@ function openid_authentication($response
     $ax_values = openid_extract_namespace($response, OPENID_NS_AX, 'ax');
 
     $form_state['build_info']['args'] = array();
     $form_state['redirect'] = NULL;
 
     if (!empty($sreg_values['nickname'])) {
       // Use the nickname returned by Simple Registration if available.
       $form_state['values']['name'] = $sreg_values['nickname'];
     }
-    else if (!empty($ax_values['value.email'])) {
-      // Else, extract the name part of the email address returned by AX if available.
-      list ($name, $domain) = explode('@', $ax_values['value.email'], 2);
-      $form_state['values']['name'] = $name;
+    elseif ($ax_name_values = openid_extract_ax_values($ax_values, array('name_ao', 'name_son'))) {
+      // Else, use the first nickname returned by AX if available.
+      $form_state['values']['name'] = current($ax_name_values);
     }
     else {
       $form_state['values']['name'] = '';
     }
 
     if (!empty($sreg_values['email'])) {
       // Use the email returned by Simple Registration if available.
       $form_state['values']['mail'] = $sreg_values['email'];
     }
-    else if (!empty($ax_values['value.email'])) {
-      // Else, use the email returned by AX if available.
-      $form_state['values']['mail'] = $ax_values['value.email'];
+    elseif ($ax_mail_values = openid_extract_ax_values($ax_values, array('mail_ao', 'mail_son'))) {
+      // Else, use the first nickname returned by AX if available.
+      $form_state['values']['mail'] = current($ax_mail_values);
     }
     else {
       $form_state['values']['mail'] = '';
     }
 
     $form_state['values']['pass']  = user_password();
     $form_state['values']['status'] = variable_get('user_register', 1) == 1;
     $form_state['values']['response'] = $response;
 
@@ -683,20 +682,23 @@ function openid_authentication_request($
   $request['openid.ns.sreg'] = OPENID_NS_SREG;
   $request['openid.sreg.required'] = 'nickname,email';
 
   // Request Attribute Exchange, if available.
   // We only request the minimum attributes we need here, contributed modules
   // can alter the request to add more attribute, and map them to profile fields.
   if (in_array(OPENID_NS_AX, $service['types'])) {
     $request['openid.ns.ax'] = OPENID_NS_AX;
     $request['openid.ax.mode'] = 'fetch_request';
-    $request['openid.ax.required'] = 'email';
-    $request['openid.ax.type.email'] = 'http://schema.openid.net/contact/email';
+    $request['openid.ax.required'] = 'mail_ao,name_ao,mail_son,name_son';
+    $request['openid.ax.type.mail_ao'] = 'http://axschema.org/contact/email';
+    $request['openid.ax.type.name_ao'] = 'http://axschema.org/namePerson/friendly';
+    $request['openid.ax.type.mail_son'] = 'http://schema.openid.net/contact/email';
+    $request['openid.ax.type.name_son'] = 'http://schema.openid.net/namePerson/friendly';
   }
 
   $request = array_merge($request, module_invoke_all('openid', 'request', $request));
 
   return $request;
 }
 
 /**
  * Attempt to verify the response received from the OpenID Provider.
Index: modules/openid/openid.test
===================================================================
RCS file: /cvs/drupal/drupal/modules/openid/openid.test,v
retrieving revision 1.15
diff -u -9 -p -r1.15 openid.test
--- modules/openid/openid.test	2 Mar 2010 08:59:54 -0000	1.15
+++ modules/openid/openid.test	11 Mar 2010 21:43:15 -0000
@@ -1,22 +1,22 @@
 <?php
 // $Id: openid.test,v 1.15 2010/03/02 08:59:54 dries Exp $
 
 /**
- * Test login and account registration using OpenID.
+ * Test discovery and login using OpenID.
  */
-class OpenIDFunctionalTest extends DrupalWebTestCase {
+class OpenIDLoginTestCase extends DrupalWebTestCase {
   protected $web_user;
 
   public static function getInfo() {
     return array(
-      'name' => 'OpenID login and account registration',
-      'description' => "Adds an identity to a user's profile and uses it to log in, creates a user account using auto-registration.",
+      'name' => 'OpenID discovery and login',
+      'description' => "Adds an identity to a user's profile and uses it to log in.",
       'group' => 'OpenID'
     );
   }
 
   function setUp() {
     parent::setUp('openid', 'openid_test');
 
     // User doesn't need special permissions; only the ability to log in.
     $this->web_user = $this->drupalCreateUser(array());
@@ -187,18 +187,35 @@ class OpenIDFunctionalTest extends Drupa
       $this->assertRaw('<script type="text/javascript">document.getElementById("openid-redirect-form").submit();</script>', t('JavaScript form submission found.'));
       $this->drupalPost(NULL, array(), t('Send'));
     }
 
     if (!$claimed_id) {
       $claimed_id = $identity;
     }
     $this->assertRaw(t('Successfully added %identity', array('%identity' => $claimed_id)), t('Identity %identity was added.', array('%identity' => $identity)));
   }
+}
+
+/**
+ * Test account registration using Simple Registration and Attribute Exchange.
+ */
+class OpenIDRegistrationTestCase extends DrupalWebTestCase {
+  public static function getInfo() {
+    return array(
+      'name' => 'OpenID account registration',
+      'description' => 'Creates a user account using auto-registration.',
+      'group' => 'OpenID'
+    );
+  }
+
+  function setUp() {
+    parent::setUp('openid', 'openid_test');
+  }
 
   /**
    * Test OpenID auto-registration with e-mail verification disabled.
    */
   function testRegisterUserWithoutEmailVerification() {
     variable_set('user_email_verification', FALSE);
 
     // Load the front page to get the user login block.
     $this->drupalGet('');
@@ -231,32 +248,33 @@ class OpenIDFunctionalTest extends Drupa
    */
   function testRegisterUserWithInvalidSreg() {
     // Load the front page to get the user login block.
     $this->drupalGet('');
 
     // Use a User-supplied Identity that is the URL of an XRDS document.
     $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
 
     // Tell openid_test.module to respond with these SREG fields.
-    variable_set('openid_test_response', array('openid.sreg.nickname' => $this->web_user->name, 'openid.sreg.email' => 'mail@invalid#'));
+    $web_user = $this->drupalCreateUser(array());
+    variable_set('openid_test_response', array('openid.sreg.nickname' => $web_user->name, 'openid.sreg.email' => 'mail@invalid#'));
 
     // Fill out and submit the login form.
     $edit = array('openid_identifier' => $identity);
     $this->drupalPost(NULL, $edit, t('Log in'));
 
     // Check we are on the OpenID redirect form.
     $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
 
     // Submit form to the OpenID Provider Endpoint.
     $this->drupalPost(NULL, array(), t('Send'));
 
     $this->assertRaw(t('Account registration using the information provided by your OpenID provider failed due to the reasons listed below. Complete the registration by filling out the form below. If you already have an account, you can <a href="@login">log in</a> now and add your OpenID under "My account".', array('@login' => url('user/login'))), t('User was asked to complete the registration process manually.'));
-    $this->assertRaw(t('The name %name is already taken.', array('%name' => $this->web_user->name)), t('Form validation error for username was displayed.'));
+    $this->assertRaw(t('The name %name is already taken.', array('%name' => $web_user->name)), t('Form validation error for username was displayed.'));
     $this->assertRaw(t('The e-mail address %mail is not valid.', array('%mail' => 'mail@invalid#')), t('Form validation error for e-mail address was displayed.'));
 
     // Enter username and e-mail address manually.
     $edit = array('name' => 'john', 'mail' => 'john@example.com');
     $this->drupalPost(NULL, $edit, t('Create new account'));
     $this->assertRaw(t('Once you have verified your e-mail address, you may log in via OpenID.'), t('User was asked to verify e-mail address.'));
 
     $user = user_load_by_name('john');
     $this->assertTrue($user, t('User was registered with right username.'));
@@ -326,19 +344,21 @@ class OpenIDFunctionalTest extends Drupa
     // Load the front page to get the user login block.
     $this->drupalGet('');
 
     // Use a User-supplied Identity that is the URL of an XRDS document.
     $identity = url('openid-test/yadis/xrds', array('absolute' => TRUE));
 
     // Tell openid_test.module to respond with these AX fields.
     variable_set('openid_test_response', array(
       'openid.ns.ext123' => 'http://openid.net/srv/ax/1.0',
-      'openid.ext123.value.email' => 'john@example.com',
+      'openid.ext123.value.mail_ao' => 'john@example.com',
+      'openid.ext123.count.name_son' => '1',
+      'openid.ext123.value.name_son.1' => 'john',
     ));
 
     // Fill out and submit the login form.
     $edit = array('openid_identifier' => $identity);
     $this->drupalPost(NULL, $edit, t('Log in'));
 
     // Check we are on the OpenID redirect form.
     $this->assertTitle(t('OpenID redirect'), t('OpenID redirect page was displayed.'));
 
