Skip to content
Snippets Groups Projects
Commit a1277471 authored by Dries Buytaert's avatar Dries Buytaert
Browse files

- Patch #740036 by c960657, Damien Tournoud: Fixed OpenID AX: Request nickname...

- Patch #740036 by c960657, Damien Tournoud: Fixed OpenID AX: Request nickname + support alternative namespaces.
parent 18b73f13
No related branches found
No related tags found
No related merge requests found
......@@ -658,22 +658,26 @@ function openid_extract_namespace($response, $extension_namespace, $fallback_pre
*
* @param $values
* An array as returned by openid_extract_namespace(..., OPENID_NS_AX).
* @param $aliases
* An array of aliases used in the fetch request.
* @param $uris
* An array of identifier URIs.
* @return
* An array of values.
* @see http://openid.net/specs/openid-attribute-exchange-1_0.html#fetch_response
*/
function openid_extract_ax_values($values, $aliases) {
function openid_extract_ax_values($values, $uris) {
$output = array();
foreach ($aliases as $alias) {
if (isset($values['count.' . $alias])) {
for ($i = 1; $i <= $values['count.' . $alias]; $i++) {
$output[] = $values['value.' . $alias . '.' . $i];
foreach ($values as $key => $value) {
if (in_array($value, $uris) && preg_match('/^type\.([^.]+)$/', $key, $matches)) {
$alias = $matches[1];
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];
elseif (isset($values['value.' . $alias])) {
$output[] = $values['value.' . $alias];
}
break;
}
}
return $output;
......
......@@ -175,7 +175,7 @@ function openid_form_user_register_form_alter(&$form, &$form_state) {
// Use the nickname returned by Simple Registration if available.
$form['account']['name']['#default_value'] = $sreg_values['nickname'];
}
elseif ($ax_name_values = openid_extract_ax_values($ax_values, array('name_ao', 'name_son'))) {
elseif ($ax_name_values = openid_extract_ax_values($ax_values, array('http://axschema.org/namePerson/friendly', 'http://schema.openid.net/namePerson/friendly'))) {
// Else, use the first nickname returned by AX if available.
$form['account']['name']['#default_value'] = current($ax_name_values);
}
......@@ -187,7 +187,7 @@ function openid_form_user_register_form_alter(&$form, &$form_state) {
// Use the email returned by Simple Registration if available.
$form['account']['mail']['#default_value'] = $sreg_values['email'];
}
elseif ($ax_mail_values = openid_extract_ax_values($ax_values, array('mail_ao', 'mail_son'))) {
elseif ($ax_mail_values = openid_extract_ax_values($ax_values, array('http://axschema.org/contact/email', 'http://schema.openid.net/contact/email'))) {
// Else, use the first nickname returned by AX if available.
$form['account']['mail']['#default_value'] = current($ax_mail_values);
}
......
......@@ -392,9 +392,11 @@ class OpenIDRegistrationTestCase extends OpenIDWebTestCase {
// 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.mail_ao' => 'john@example.com',
'openid.ext123.count.name_son' => '1',
'openid.ext123.value.name_son.1' => 'john',
'openid.ext123.type.mail456' => 'http://axschema.org/contact/email',
'openid.ext123.value.mail456' => 'john@example.com',
'openid.ext123.type.name789' => 'http://schema.openid.net/namePerson/friendly',
'openid.ext123.count.name789' => '1',
'openid.ext123.value.name789.1' => 'john',
));
// Use a User-supplied Identity that is the URL of an XRDS document.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment