| 1 |
<?php |
<?php |
| 2 |
// $Id: openid.module,v 1.2.2.7 2008/01/30 20:43:20 walkah Exp $ |
// $Id: openid.module,v 1.2.2.8 2008/07/09 19:46:44 pwolanin Exp $ |
| 3 |
|
|
| 4 |
/** |
/** |
| 5 |
* @file |
* @file |
| 26 |
|
|
| 27 |
if ($account->uid) { |
if ($account->uid) { |
| 28 |
global $user; |
global $user; |
| 29 |
|
|
| 30 |
$access = (user_access('administer users') || $user->uid == arg(1)); |
$access = (user_access('administer users') || $user->uid == arg(1)); |
| 31 |
$items[] = array( |
$items[] = array( |
| 32 |
'path' => 'user/'. arg(1) .'/openid', |
'path' => 'user/'. arg(1) .'/openid', |
| 104 |
'#weight' => -1, |
'#weight' => -1, |
| 105 |
'#description' => l(t('What is OpenID?'), 'http://openid.net/'), |
'#description' => l(t('What is OpenID?'), 'http://openid.net/'), |
| 106 |
'#prefix' => '<div id="edit-openid-identifier-wrapper">', |
'#prefix' => '<div id="edit-openid-identifier-wrapper">', |
| 107 |
'#suffix' => '</div>' |
'#suffix' => '</div>' |
| 108 |
); |
); |
| 109 |
$form['openid.return_to'] = array('#type' => 'hidden', '#value' => url('openid/authenticate', drupal_get_destination(), NULL, TRUE)); |
$form['openid.return_to'] = array('#type' => 'hidden', '#value' => url('openid/authenticate', drupal_get_destination(), NULL, TRUE)); |
| 110 |
$form['name']['#prefix'] = '<div id="edit-name-wrapper">'; |
$form['name']['#prefix'] = '<div id="edit-name-wrapper">'; |
| 164 |
db_query("INSERT INTO {authmap} (uid, authname, module) VALUES (%d, '%s','openid')", $account->uid, $identity); |
db_query("INSERT INTO {authmap} (uid, authname, module) VALUES (%d, '%s','openid')", $account->uid, $identity); |
| 165 |
drupal_set_message(t('Successfully added %identity', array('%identity' => $identity))); |
drupal_set_message(t('Successfully added %identity', array('%identity' => $identity))); |
| 166 |
} |
} |
| 167 |
|
|
| 168 |
$header = array(t('OpenID'), t('Operations')); |
$header = array(t('OpenID'), t('Operations')); |
| 169 |
$rows = array(); |
$rows = array(); |
| 170 |
|
|
| 193 |
if (db_result(db_query("SELECT authname FROM {authmap} WHERE authname='%s'", $claimed_id))) { |
if (db_result(db_query("SELECT authname FROM {authmap} WHERE authname='%s'", $claimed_id))) { |
| 194 |
form_set_error('openid_identifier', t('That OpenID is already in use on this site.')); |
form_set_error('openid_identifier', t('That OpenID is already in use on this site.')); |
| 195 |
} |
} |
|
else { |
|
|
$return_to = url('user/'. arg(1) .'/openid', NULL, NULL, TRUE); |
|
|
openid_begin($form_values['openid_identifier'], $return_to); |
|
|
} |
|
| 196 |
} |
} |
| 197 |
|
|
| 198 |
|
|
| 199 |
|
function openid_user_add_submit($form_id, $form_values) { |
| 200 |
|
// Check for existing entries. |
| 201 |
|
$return_to = url('user/'. arg(1) .'/openid', NULL, NULL, TRUE); |
| 202 |
|
openid_begin($form_values['openid_identifier'], $return_to); |
| 203 |
|
} |
| 204 |
|
|
| 205 |
|
|
| 206 |
/** |
/** |
| 207 |
* Present a confirmation form to delete the specified OpenID identity. |
* Present a confirmation form to delete the specified OpenID identity. |
| 208 |
* |
* |
| 243 |
* |
* |
| 244 |
* @param $claimed_id The OpenID to authenticate |
* @param $claimed_id The OpenID to authenticate |
| 245 |
* @param $return_to The endpoint to return to from the OpenID Provider |
* @param $return_to The endpoint to return to from the OpenID Provider |
| 246 |
*/ |
*/ |
| 247 |
function openid_begin($claimed_id, $return_to = '') { |
function openid_begin($claimed_id, $return_to = '') { |
| 248 |
include_once drupal_get_path('module', 'openid') .'/openid.inc'; |
include_once drupal_get_path('module', 'openid') .'/openid.inc'; |
| 249 |
|
|
| 250 |
$claimed_id = _openid_normalize($claimed_id); |
$claimed_id = _openid_normalize($claimed_id); |
| 251 |
|
|
| 252 |
$services = openid_discovery($claimed_id); |
$services = openid_discovery($claimed_id); |
| 253 |
if (count($services) == 0) { |
if (count($services) == 0) { |
| 260 |
$_SESSION['openid']['service'] = $services[0]; |
$_SESSION['openid']['service'] = $services[0]; |
| 261 |
// Store the claimed id |
// Store the claimed id |
| 262 |
$_SESSION['openid']['claimed_id'] = $claimed_id; |
$_SESSION['openid']['claimed_id'] = $claimed_id; |
| 263 |
|
|
| 264 |
// If bcmath is present, then create an association |
// If bcmath is present, then create an association |
| 265 |
$assoc_handle = ''; |
$assoc_handle = ''; |
| 266 |
if (function_exists('bcadd')) { |
if (function_exists('bcadd')) { |
| 267 |
$assoc_handle = openid_association($op_endpoint); |
$assoc_handle = openid_association($op_endpoint); |
| 268 |
} |
} |
| 269 |
|
|
| 270 |
// Now that there is an association created, move on |
// Now that there is an association created, move on |
| 271 |
// to request authentication from the IdP |
// to request authentication from the IdP |
| 272 |
// First check for LocalID. If not found, check for Delegate. Fall |
// First check for LocalID. If not found, check for Delegate. Fall |
| 280 |
else { |
else { |
| 281 |
$identity = $claimed_id; |
$identity = $claimed_id; |
| 282 |
} |
} |
| 283 |
|
|
| 284 |
if (isset($services[0]['types']) && is_array($services[0]['types']) && in_array(OPENID_NS_2_0 .'/server', $services[0]['types'])) { |
if (isset($services[0]['types']) && is_array($services[0]['types']) && in_array(OPENID_NS_2_0 .'/server', $services[0]['types'])) { |
| 285 |
$identity = 'http://specs.openid.net/auth/2.0/identifier_select'; |
$identity = 'http://specs.openid.net/auth/2.0/identifier_select'; |
| 286 |
} |
} |
| 291 |
} |
} |
| 292 |
else { |
else { |
| 293 |
openid_redirect_http($op_endpoint, $authn_request); |
openid_redirect_http($op_endpoint, $authn_request); |
| 294 |
} |
} |
| 295 |
} |
} |
| 296 |
|
|
| 297 |
/** |
/** |
| 395 |
$uri = _openid_link_href('openid2.provider', $result->data); |
$uri = _openid_link_href('openid2.provider', $result->data); |
| 396 |
$delegate = _openid_link_href('openid2.local_id', $result->data); |
$delegate = _openid_link_href('openid2.local_id', $result->data); |
| 397 |
$version = 2; |
$version = 2; |
| 398 |
|
|
| 399 |
// 1.0 links |
// 1.0 links |
| 400 |
if (empty($uri)) { |
if (empty($uri)) { |
| 401 |
$uri = _openid_link_href('openid.server', $result->data); |
$uri = _openid_link_href('openid.server', $result->data); |
| 432 |
$r = _openid_dh_rand($mod); |
$r = _openid_dh_rand($mod); |
| 433 |
$private = bcadd($r, 1); |
$private = bcadd($r, 1); |
| 434 |
$public = bcpowmod($gen, $private, $mod); |
$public = bcpowmod($gen, $private, $mod); |
| 435 |
|
|
| 436 |
// If there is no existing association, then request one |
// If there is no existing association, then request one |
| 437 |
$assoc_request = openid_association_request($public); |
$assoc_request = openid_association_request($public); |
| 438 |
$assoc_message = _openid_encode_message(_openid_create_message($assoc_request)); |
$assoc_message = _openid_encode_message(_openid_create_message($assoc_request)); |
| 441 |
if (isset($assoc_result->error)) { |
if (isset($assoc_result->error)) { |
| 442 |
return FALSE; |
return FALSE; |
| 443 |
} |
} |
| 444 |
|
|
| 445 |
$assoc_response = _openid_parse_message($assoc_result->data); |
$assoc_response = _openid_parse_message($assoc_result->data); |
| 446 |
if (isset($assoc_response['mode']) && $assoc_response['mode'] == 'error') { |
if (isset($assoc_response['mode']) && $assoc_response['mode'] == 'error') { |
| 447 |
return FALSE; |
return FALSE; |
| 455 |
} |
} |
| 456 |
db_query("INSERT INTO {openid_association} (idp_endpoint_uri, session_type, assoc_handle, assoc_type, expires_in, mac_key, created) VALUES('%s', '%s', '%s', '%s', %d, '%s', %d)", |
db_query("INSERT INTO {openid_association} (idp_endpoint_uri, session_type, assoc_handle, assoc_type, expires_in, mac_key, created) VALUES('%s', '%s', '%s', '%s', %d, '%s', %d)", |
| 457 |
$op_endpoint, $assoc_response['session_type'], $assoc_response['assoc_handle'], $assoc_response['assoc_type'], $assoc_response['expires_in'], $assoc_response['mac_key'], time()); |
$op_endpoint, $assoc_response['session_type'], $assoc_response['assoc_handle'], $assoc_response['assoc_type'], $assoc_response['expires_in'], $assoc_response['mac_key'], time()); |
| 458 |
|
|
| 459 |
$assoc_handle = $assoc_response['assoc_handle']; |
$assoc_handle = $assoc_response['assoc_handle']; |
| 460 |
} |
} |
| 461 |
|
|
| 561 |
// Simple Registration |
// Simple Registration |
| 562 |
$request['openid.sreg.required'] = 'nickname,email'; |
$request['openid.sreg.required'] = 'nickname,email'; |
| 563 |
$request['openid.ns.sreg'] = "http://openid.net/extensions/sreg/1.1"; |
$request['openid.ns.sreg'] = "http://openid.net/extensions/sreg/1.1"; |
| 564 |
|
|
| 565 |
$request = array_merge($request, module_invoke_all('openid', 'request', $request)); |
$request = array_merge($request, module_invoke_all('openid', 'request', $request)); |
| 566 |
|
|
| 567 |
return $request; |
return $request; |
| 579 |
include_once drupal_get_path('module', 'openid') .'/openid.inc'; |
include_once drupal_get_path('module', 'openid') .'/openid.inc'; |
| 580 |
|
|
| 581 |
$valid = FALSE; |
$valid = FALSE; |
| 582 |
|
|
| 583 |
$association = db_fetch_object(db_query("SELECT * FROM {openid_association} WHERE assoc_handle = '%s'", $response['openid.assoc_handle'])); |
$association = db_fetch_object(db_query("SELECT * FROM {openid_association} WHERE assoc_handle = '%s'", $response['openid.assoc_handle'])); |
| 584 |
if ($association && isset($association->session_type)) { |
if ($association && isset($association->session_type)) { |
| 585 |
$keys_to_sign = explode(',', $response['openid.signed']); |
$keys_to_sign = explode(',', $response['openid.signed']); |