|
1 <?php |
|
2 // $Id: openid.module,v 1.19.2.6 2009/06/10 14:05:23 goba Exp $ |
|
3 |
|
4 /** |
|
5 * @file |
|
6 * Implement OpenID Relying Party support for Drupal |
|
7 */ |
|
8 |
|
9 /** |
|
10 * Implementation of hook_menu. |
|
11 */ |
|
12 function openid_menu() { |
|
13 $items['openid/authenticate'] = array( |
|
14 'title' => 'OpenID Login', |
|
15 'page callback' => 'openid_authentication_page', |
|
16 'access callback' => 'user_is_anonymous', |
|
17 'type' => MENU_CALLBACK, |
|
18 'file' => 'openid.pages.inc', |
|
19 ); |
|
20 $items['user/%user/openid'] = array( |
|
21 'title' => 'OpenID identities', |
|
22 'page callback' => 'openid_user_identities', |
|
23 'page arguments' => array(1), |
|
24 'access callback' => 'user_edit_access', |
|
25 'access arguments' => array(1), |
|
26 'type' => MENU_LOCAL_TASK, |
|
27 'file' => 'openid.pages.inc', |
|
28 ); |
|
29 $items['user/%user/openid/delete'] = array( |
|
30 'title' => 'Delete OpenID', |
|
31 'page callback' => 'drupal_get_form', |
|
32 'page arguments' => array('openid_user_delete_form', 1), |
|
33 'access callback' => 'user_edit_access', |
|
34 'access arguments' => array(1), |
|
35 'type' => MENU_CALLBACK, |
|
36 'file' => 'openid.pages.inc', |
|
37 ); |
|
38 return $items; |
|
39 } |
|
40 |
|
41 /** |
|
42 * Implementation of hook_help(). |
|
43 */ |
|
44 function openid_help($path, $arg) { |
|
45 switch ($path) { |
|
46 case 'user/%/openid': |
|
47 $output = '<p>'. t('This site supports <a href="@openid-net">OpenID</a>, a secure way to log into many websites using a single username and password. OpenID can reduce the necessity of managing many usernames and passwords for many websites.', array('@openid-net' => 'http://openid.net')) .'</p>'; |
|
48 $output .= '<p>'. t('To use OpenID you must first establish an identity on a public or private OpenID server. If you do not have an OpenID and would like one, look into one of the <a href="@openid-providers">free public providers</a>. You can find out more about OpenID at <a href="@openid-net">this website</a>.', array('@openid-providers' => 'http://openid.net/get/', '@openid-net' => 'http://openid.net')) .'</p>'; |
|
49 $output .= '<p>'. t('If you already have an OpenID, enter the URL to your OpenID server below (e.g. myusername.openidprovider.com). Next time you login, you will be able to use this URL instead of a regular username and password. You can have multiple OpenID servers if you like; just keep adding them here.') .'</p>'; |
|
50 return $output; |
|
51 |
|
52 case 'admin/help#openid': |
|
53 $output = '<p>'. t('OpenID is a secure method for logging into many websites with a single username and password. It does not require special software, and it does not share passwords with any site to which it is associated; including your site.') .'</p>'; |
|
54 $output .= '<p>'. t('Users can create accounts using their OpenID, assign one or more OpenIDs to an existing account, and log in using an OpenID. This lowers the barrier to registration, which is good for the site, and offers convenience and security to the users. OpenID is not a trust system, so email verification is still necessary. The benefit stems from the fact that users can have a single password that they can use on many websites. This means they can easily update their single password from a centralized location, rather than having to change dozens of passwords individually.') .'</p>'; |
|
55 $output .= '<p>'. t('The basic concept is as follows: A user has an account on an OpenID server. This account provides them with a unique URL (such as myusername.openidprovider.com). When the user comes to your site, they are presented with the option of entering this URL. Your site then communicates with the OpenID server, asking it to verify the identity of the user. If the user is logged into their OpenID server, the server communicates back to your site, verifying the user. If they are not logged in, the OpenID server will ask the user for their password. At no point does your site record, or need to record the user\'s password.') .'</p>'; |
|
56 $output .= '<p>'. t('More information on OpenID is available at <a href="@openid-net">OpenID.net</a>.', array('@openid-net' => url('http://openid.net'))) .'</p>'; |
|
57 $output .= '<p>'. t('For more information, see the online handbook entry for <a href="@handbook">OpenID module</a>.', array('@handbook' => 'http://drupal.org/handbook/modules/openid')) .'</p>'; |
|
58 return $output; |
|
59 } |
|
60 } |
|
61 |
|
62 /** |
|
63 * Implementation of hook_user(). |
|
64 */ |
|
65 function openid_user($op, &$edit, &$account, $category = NULL) { |
|
66 if ($op == 'insert' && isset($_SESSION['openid']['values'])) { |
|
67 // The user has registered after trying to login via OpenID. |
|
68 if (variable_get('user_email_verification', TRUE)) { |
|
69 drupal_set_message(t('Once you have verified your email address, you may log in via OpenID.')); |
|
70 } |
|
71 unset($_SESSION['openid']); |
|
72 } |
|
73 } |
|
74 |
|
75 /** |
|
76 * Implementation of hook_form_alter : adds OpenID login to the login forms. |
|
77 */ |
|
78 function openid_form_alter(&$form, $form_state, $form_id) { |
|
79 if ($form_id == 'user_login_block' || $form_id == 'user_login') { |
|
80 drupal_add_css(drupal_get_path('module', 'openid') .'/openid.css', 'module'); |
|
81 drupal_add_js(drupal_get_path('module', 'openid') .'/openid.js'); |
|
82 if (!empty($form_state['post']['openid_identifier'])) { |
|
83 $form['name']['#required'] = FALSE; |
|
84 $form['pass']['#required'] = FALSE; |
|
85 unset($form['#submit']); |
|
86 $form['#validate'] = array('openid_login_validate'); |
|
87 } |
|
88 |
|
89 $items = array(); |
|
90 $items[] = array( |
|
91 'data' => l(t('Log in using OpenID'), '#'), |
|
92 'class' => 'openid-link', |
|
93 ); |
|
94 $items[] = array( |
|
95 'data' => l(t('Cancel OpenID login'), '#'), |
|
96 'class' => 'user-link', |
|
97 ); |
|
98 |
|
99 $form['openid_links'] = array( |
|
100 '#value' => theme('item_list', $items), |
|
101 '#weight' => 1, |
|
102 ); |
|
103 |
|
104 $form['links']['#weight'] = 2; |
|
105 |
|
106 $form['openid_identifier'] = array( |
|
107 '#type' => 'textfield', |
|
108 '#title' => t('Log in using OpenID'), |
|
109 '#size' => ($form_id == 'user_login') ? 58 : 13, |
|
110 '#maxlength' => 255, |
|
111 '#weight' => -1, |
|
112 '#description' => l(t('What is OpenID?'), 'http://openid.net/', array('external' => TRUE)), |
|
113 ); |
|
114 $form['openid.return_to'] = array('#type' => 'hidden', '#value' => url('openid/authenticate', array('absolute' => TRUE, 'query' => drupal_get_destination()))); |
|
115 } |
|
116 elseif ($form_id == 'user_register' && isset($_SESSION['openid'])) { |
|
117 // We were unable to auto-register a new user. Prefill the registration |
|
118 // form with the values we have. |
|
119 $form['name']['#default_value'] = $_SESSION['openid']['values']['name']; |
|
120 $form['mail']['#default_value'] = $_SESSION['openid']['values']['mail']; |
|
121 // If user_email_verification is off, hide the password field and just fill |
|
122 // with random password to avoid confusion. |
|
123 if (!variable_get('user_email_verification', TRUE)) { |
|
124 $form['pass']['#type'] = 'hidden'; |
|
125 $form['pass']['#value'] = user_password(); |
|
126 } |
|
127 $form['auth_openid'] = array('#type' => 'hidden', '#value' => $_SESSION['openid']['values']['auth_openid']); |
|
128 } |
|
129 return $form; |
|
130 } |
|
131 |
|
132 /** |
|
133 * Login form _validate hook |
|
134 */ |
|
135 function openid_login_validate($form, &$form_state) { |
|
136 $return_to = $form_state['values']['openid.return_to']; |
|
137 if (empty($return_to)) { |
|
138 $return_to = url('', array('absolute' => TRUE)); |
|
139 } |
|
140 |
|
141 openid_begin($form_state['values']['openid_identifier'], $return_to, $form_state['values']); |
|
142 } |
|
143 |
|
144 /** |
|
145 * The initial step of OpenID authentication responsible for the following: |
|
146 * - Perform discovery on the claimed OpenID. |
|
147 * - If possible, create an association with the Provider's endpoint. |
|
148 * - Create the authentication request. |
|
149 * - Perform the appropriate redirect. |
|
150 * |
|
151 * @param $claimed_id The OpenID to authenticate |
|
152 * @param $return_to The endpoint to return to from the OpenID Provider |
|
153 */ |
|
154 function openid_begin($claimed_id, $return_to = '', $form_values = array()) { |
|
155 module_load_include('inc', 'openid'); |
|
156 |
|
157 $claimed_id = _openid_normalize($claimed_id); |
|
158 |
|
159 $services = openid_discovery($claimed_id); |
|
160 if (count($services) == 0) { |
|
161 form_set_error('openid_identifier', t('Sorry, that is not a valid OpenID. Please ensure you have spelled your ID correctly.')); |
|
162 return; |
|
163 } |
|
164 |
|
165 // Store discovered information in the users' session so we don't have to rediscover. |
|
166 $_SESSION['openid']['service'] = $services[0]; |
|
167 // Store the claimed id |
|
168 $_SESSION['openid']['claimed_id'] = $claimed_id; |
|
169 // Store the login form values so we can pass them to |
|
170 // user_exteral_login later. |
|
171 $_SESSION['openid']['user_login_values'] = $form_values; |
|
172 |
|
173 $op_endpoint = $services[0]['uri']; |
|
174 // If bcmath is present, then create an association |
|
175 $assoc_handle = ''; |
|
176 if (function_exists('bcadd')) { |
|
177 $assoc_handle = openid_association($op_endpoint); |
|
178 } |
|
179 |
|
180 // Now that there is an association created, move on |
|
181 // to request authentication from the IdP |
|
182 // First check for LocalID. If not found, check for Delegate. Fall |
|
183 // back to $claimed_id if neither is found. |
|
184 if (!empty($services[0]['localid'])) { |
|
185 $identity = $services[0]['localid']; |
|
186 } |
|
187 else if (!empty($services[0]['delegate'])) { |
|
188 $identity = $services[0]['delegate']; |
|
189 } |
|
190 else { |
|
191 $identity = $claimed_id; |
|
192 } |
|
193 |
|
194 if (isset($services[0]['types']) && is_array($services[0]['types']) && in_array(OPENID_NS_2_0 .'/server', $services[0]['types'])) { |
|
195 $identity = 'http://specs.openid.net/auth/2.0/identifier_select'; |
|
196 } |
|
197 $authn_request = openid_authentication_request($claimed_id, $identity, $return_to, $assoc_handle, $services[0]['version']); |
|
198 |
|
199 if ($services[0]['version'] == 2) { |
|
200 openid_redirect($op_endpoint, $authn_request); |
|
201 } |
|
202 else { |
|
203 openid_redirect_http($op_endpoint, $authn_request); |
|
204 } |
|
205 } |
|
206 |
|
207 /** |
|
208 * Completes OpenID authentication by validating returned data from the OpenID |
|
209 * Provider. |
|
210 * |
|
211 * @param $response Array of returned values from the OpenID Provider. |
|
212 * |
|
213 * @return $response Response values for further processing with |
|
214 * $response['status'] set to one of 'success', 'failed' or 'cancel'. |
|
215 */ |
|
216 function openid_complete($response = array()) { |
|
217 module_load_include('inc', 'openid'); |
|
218 |
|
219 if (count($response) == 0) { |
|
220 $response = _openid_response(); |
|
221 } |
|
222 |
|
223 // Default to failed response |
|
224 $response['status'] = 'failed'; |
|
225 if (isset($_SESSION['openid']['service']['uri']) && isset($_SESSION['openid']['claimed_id'])) { |
|
226 $service = $_SESSION['openid']['service']; |
|
227 $claimed_id = $_SESSION['openid']['claimed_id']; |
|
228 unset($_SESSION['openid']['service']); |
|
229 unset($_SESSION['openid']['claimed_id']); |
|
230 if (isset($response['openid.mode'])) { |
|
231 if ($response['openid.mode'] == 'cancel') { |
|
232 $response['status'] = 'cancel'; |
|
233 } |
|
234 else { |
|
235 if (openid_verify_assertion($service['uri'], $response)) { |
|
236 // If the returned claimed_id is different from the session claimed_id, |
|
237 // then we need to do discovery and make sure the op_endpoint matches. |
|
238 if ($service['version'] == 2 && $response['openid.claimed_id'] != $claimed_id) { |
|
239 $disco = openid_discovery($response['openid.claimed_id']); |
|
240 if ($disco[0]['uri'] != $service['uri']) { |
|
241 return $response; |
|
242 } |
|
243 } |
|
244 else { |
|
245 $response['openid.claimed_id'] = $claimed_id; |
|
246 } |
|
247 $response['status'] = 'success'; |
|
248 } |
|
249 } |
|
250 } |
|
251 } |
|
252 return $response; |
|
253 } |
|
254 |
|
255 /** |
|
256 * Perform discovery on a claimed ID to determine the OpenID provider endpoint. |
|
257 * |
|
258 * @param $claimed_id The OpenID URL to perform discovery on. |
|
259 * |
|
260 * @return Array of services discovered (including OpenID version, endpoint |
|
261 * URI, etc). |
|
262 */ |
|
263 function openid_discovery($claimed_id) { |
|
264 module_load_include('inc', 'openid'); |
|
265 module_load_include('inc', 'openid', 'xrds'); |
|
266 |
|
267 $services = array(); |
|
268 |
|
269 $xrds_url = $claimed_id; |
|
270 if (_openid_is_xri($claimed_id)) { |
|
271 $xrds_url = 'http://xri.net/'. $claimed_id; |
|
272 } |
|
273 $url = @parse_url($xrds_url); |
|
274 if ($url['scheme'] == 'http' || $url['scheme'] == 'https') { |
|
275 // For regular URLs, try Yadis resolution first, then HTML-based discovery |
|
276 $headers = array('Accept' => 'application/xrds+xml'); |
|
277 $result = drupal_http_request($xrds_url, $headers); |
|
278 |
|
279 if (!isset($result->error)) { |
|
280 if (isset($result->headers['Content-Type']) && preg_match("/application\/xrds\+xml/", $result->headers['Content-Type'])) { |
|
281 // Parse XML document to find URL |
|
282 $services = xrds_parse($result->data); |
|
283 } |
|
284 else { |
|
285 $xrds_url = NULL; |
|
286 if (isset($result->headers['X-XRDS-Location'])) { |
|
287 $xrds_url = $result->headers['X-XRDS-Location']; |
|
288 } |
|
289 else { |
|
290 // Look for meta http-equiv link in HTML head |
|
291 $xrds_url = _openid_meta_httpequiv('X-XRDS-Location', $result->data); |
|
292 } |
|
293 if (!empty($xrds_url)) { |
|
294 $headers = array('Accept' => 'application/xrds+xml'); |
|
295 $xrds_result = drupal_http_request($xrds_url, $headers); |
|
296 if (!isset($xrds_result->error)) { |
|
297 $services = xrds_parse($xrds_result->data); |
|
298 } |
|
299 } |
|
300 } |
|
301 |
|
302 // Check for HTML delegation |
|
303 if (count($services) == 0) { |
|
304 // Look for 2.0 links |
|
305 $uri = _openid_link_href('openid2.provider', $result->data); |
|
306 $delegate = _openid_link_href('openid2.local_id', $result->data); |
|
307 $version = 2; |
|
308 |
|
309 // 1.0 links |
|
310 if (empty($uri)) { |
|
311 $uri = _openid_link_href('openid.server', $result->data); |
|
312 $delegate = _openid_link_href('openid.delegate', $result->data); |
|
313 $version = 1; |
|
314 } |
|
315 if (!empty($uri)) { |
|
316 $services[] = array('uri' => $uri, 'delegate' => $delegate, 'version' => $version); |
|
317 } |
|
318 } |
|
319 } |
|
320 } |
|
321 return $services; |
|
322 } |
|
323 |
|
324 /** |
|
325 * Attempt to create a shared secret with the OpenID Provider. |
|
326 * |
|
327 * @param $op_endpoint URL of the OpenID Provider endpoint. |
|
328 * |
|
329 * @return $assoc_handle The association handle. |
|
330 */ |
|
331 function openid_association($op_endpoint) { |
|
332 module_load_include('inc', 'openid'); |
|
333 |
|
334 // Remove Old Associations: |
|
335 db_query("DELETE FROM {openid_association} WHERE created + expires_in < %d", time()); |
|
336 |
|
337 // Check to see if we have an association for this IdP already |
|
338 $assoc_handle = db_result(db_query("SELECT assoc_handle FROM {openid_association} WHERE idp_endpoint_uri = '%s'", $op_endpoint)); |
|
339 if (empty($assoc_handle)) { |
|
340 $mod = OPENID_DH_DEFAULT_MOD; |
|
341 $gen = OPENID_DH_DEFAULT_GEN; |
|
342 $r = _openid_dh_rand($mod); |
|
343 $private = bcadd($r, 1); |
|
344 $public = bcpowmod($gen, $private, $mod); |
|
345 |
|
346 // If there is no existing association, then request one |
|
347 $assoc_request = openid_association_request($public); |
|
348 $assoc_message = _openid_encode_message(_openid_create_message($assoc_request)); |
|
349 $assoc_headers = array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'); |
|
350 $assoc_result = drupal_http_request($op_endpoint, $assoc_headers, 'POST', $assoc_message); |
|
351 if (isset($assoc_result->error)) { |
|
352 return FALSE; |
|
353 } |
|
354 |
|
355 $assoc_response = _openid_parse_message($assoc_result->data); |
|
356 if (isset($assoc_response['mode']) && $assoc_response['mode'] == 'error') { |
|
357 return FALSE; |
|
358 } |
|
359 |
|
360 if ($assoc_response['session_type'] == 'DH-SHA1') { |
|
361 $spub = _openid_dh_base64_to_long($assoc_response['dh_server_public']); |
|
362 $enc_mac_key = base64_decode($assoc_response['enc_mac_key']); |
|
363 $shared = bcpowmod($spub, $private, $mod); |
|
364 $assoc_response['mac_key'] = base64_encode(_openid_dh_xorsecret($shared, $enc_mac_key)); |
|
365 } |
|
366 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)", |
|
367 $op_endpoint, $assoc_response['session_type'], $assoc_response['assoc_handle'], $assoc_response['assoc_type'], $assoc_response['expires_in'], $assoc_response['mac_key'], time()); |
|
368 |
|
369 $assoc_handle = $assoc_response['assoc_handle']; |
|
370 } |
|
371 |
|
372 return $assoc_handle; |
|
373 } |
|
374 |
|
375 /** |
|
376 * Authenticate a user or attempt registration. |
|
377 * |
|
378 * @param $response Response values from the OpenID Provider. |
|
379 */ |
|
380 function openid_authentication($response) { |
|
381 module_load_include('inc', 'openid'); |
|
382 |
|
383 $identity = $response['openid.claimed_id']; |
|
384 |
|
385 $account = user_external_load($identity); |
|
386 if (isset($account->uid)) { |
|
387 if (!variable_get('user_email_verification', TRUE) || $account->login) { |
|
388 user_external_login($account, $_SESSION['openid']['user_login_values']); |
|
389 } |
|
390 else { |
|
391 drupal_set_message(t('You must validate your email address for this account before logging in via OpenID')); |
|
392 } |
|
393 } |
|
394 elseif (variable_get('user_register', 1)) { |
|
395 // Register new user |
|
396 $form_state['redirect'] = NULL; |
|
397 $form_state['values']['name'] = (empty($response['openid.sreg.nickname'])) ? $identity : $response['openid.sreg.nickname']; |
|
398 $form_state['values']['mail'] = (empty($response['openid.sreg.email'])) ? '' : $response['openid.sreg.email']; |
|
399 $form_state['values']['pass'] = user_password(); |
|
400 $form_state['values']['status'] = variable_get('user_register', 1) == 1; |
|
401 $form_state['values']['response'] = $response; |
|
402 $form_state['values']['auth_openid'] = $identity; |
|
403 $form = drupal_retrieve_form('user_register', $form_state); |
|
404 drupal_prepare_form('user_register', $form, $form_state); |
|
405 drupal_validate_form('user_register', $form, $form_state); |
|
406 if (form_get_errors()) { |
|
407 // We were unable to register a valid new user, redirect to standard |
|
408 // user/register and prefill with the values we received. |
|
409 drupal_set_message(t('OpenID registration failed for the reasons listed. You may register now, or 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'))), 'error'); |
|
410 $_SESSION['openid']['values'] = $form_state['values']; |
|
411 // We'll want to redirect back to the same place. |
|
412 $destination = drupal_get_destination(); |
|
413 unset($_REQUEST['destination']); |
|
414 drupal_goto('user/register', $destination); |
|
415 } |
|
416 else { |
|
417 unset($form_state['values']['response']); |
|
418 $account = user_save('', $form_state['values']); |
|
419 // Terminate if an error occured during user_save(). |
|
420 if (!$account) { |
|
421 drupal_set_message(t("Error saving user account."), 'error'); |
|
422 drupal_goto(); |
|
423 } |
|
424 user_external_login($account); |
|
425 } |
|
426 drupal_redirect_form($form, $form_state['redirect']); |
|
427 } |
|
428 else { |
|
429 drupal_set_message(t('Only site administrators can create new user accounts.'), 'error'); |
|
430 } |
|
431 drupal_goto(); |
|
432 } |
|
433 |
|
434 function openid_association_request($public) { |
|
435 module_load_include('inc', 'openid'); |
|
436 |
|
437 $request = array( |
|
438 'openid.ns' => OPENID_NS_2_0, |
|
439 'openid.mode' => 'associate', |
|
440 'openid.session_type' => 'DH-SHA1', |
|
441 'openid.assoc_type' => 'HMAC-SHA1' |
|
442 ); |
|
443 |
|
444 if ($request['openid.session_type'] == 'DH-SHA1' || $request['openid.session_type'] == 'DH-SHA256') { |
|
445 $cpub = _openid_dh_long_to_base64($public); |
|
446 $request['openid.dh_consumer_public'] = $cpub; |
|
447 } |
|
448 |
|
449 return $request; |
|
450 } |
|
451 |
|
452 function openid_authentication_request($claimed_id, $identity, $return_to = '', $assoc_handle = '', $version = 2) { |
|
453 module_load_include('inc', 'openid'); |
|
454 |
|
455 $ns = ($version == 2) ? OPENID_NS_2_0 : OPENID_NS_1_0; |
|
456 $request = array( |
|
457 'openid.ns' => $ns, |
|
458 'openid.mode' => 'checkid_setup', |
|
459 'openid.identity' => $identity, |
|
460 'openid.claimed_id' => $claimed_id, |
|
461 'openid.assoc_handle' => $assoc_handle, |
|
462 'openid.return_to' => $return_to, |
|
463 ); |
|
464 |
|
465 if ($version == 2) { |
|
466 $request['openid.realm'] = url('', array('absolute' => TRUE)); |
|
467 } |
|
468 else { |
|
469 $request['openid.trust_root'] = url('', array('absolute' => TRUE)); |
|
470 } |
|
471 |
|
472 // Simple Registration |
|
473 $request['openid.sreg.required'] = 'nickname,email'; |
|
474 $request['openid.ns.sreg'] = "http://openid.net/extensions/sreg/1.1"; |
|
475 |
|
476 $request = array_merge($request, module_invoke_all('openid', 'request', $request)); |
|
477 |
|
478 return $request; |
|
479 } |
|
480 |
|
481 /** |
|
482 * Attempt to verify the response received from the OpenID Provider. |
|
483 * |
|
484 * @param $op_endpoint The OpenID Provider URL. |
|
485 * @param $response Array of repsonse values from the provider. |
|
486 * |
|
487 * @return boolean |
|
488 */ |
|
489 function openid_verify_assertion($op_endpoint, $response) { |
|
490 module_load_include('inc', 'openid'); |
|
491 |
|
492 $valid = FALSE; |
|
493 |
|
494 $association = db_fetch_object(db_query("SELECT * FROM {openid_association} WHERE assoc_handle = '%s'", $response['openid.assoc_handle'])); |
|
495 if ($association && isset($association->session_type)) { |
|
496 $keys_to_sign = explode(',', $response['openid.signed']); |
|
497 $self_sig = _openid_signature($association, $response, $keys_to_sign); |
|
498 if ($self_sig == $response['openid.sig']) { |
|
499 $valid = TRUE; |
|
500 } |
|
501 else { |
|
502 $valid = FALSE; |
|
503 } |
|
504 } |
|
505 else { |
|
506 $request = $response; |
|
507 $request['openid.mode'] = 'check_authentication'; |
|
508 $message = _openid_create_message($request); |
|
509 $headers = array('Content-Type' => 'application/x-www-form-urlencoded; charset=utf-8'); |
|
510 $result = drupal_http_request($op_endpoint, $headers, 'POST', _openid_encode_message($message)); |
|
511 if (!isset($result->error)) { |
|
512 $response = _openid_parse_message($result->data); |
|
513 if (strtolower(trim($response['is_valid'])) == 'true') { |
|
514 $valid = TRUE; |
|
515 } |
|
516 else { |
|
517 $valid = FALSE; |
|
518 } |
|
519 } |
|
520 } |
|
521 return $valid; |
|
522 } |