| 1 |
<?php |
<?php |
| 2 |
// $Id$ |
// $Id: services_oauth.pages.inc,v 1.1 2009/05/08 21:12:30 hugowetterberg Exp $ |
| 3 |
|
|
| 4 |
|
function _services_oauth_authorized() { |
| 5 |
|
return t('The application has been authorized'); |
| 6 |
|
} |
| 7 |
|
|
| 8 |
/** |
/** |
| 9 |
* Form for granting access to the consumer |
* Form for granting access to the consumer |
| 33 |
header('Location: ' . drupal_substr($_SERVER['REQUEST_URI'], 1), TRUE, 302); |
header('Location: ' . drupal_substr($_SERVER['REQUEST_URI'], 1), TRUE, 302); |
| 34 |
} |
} |
| 35 |
|
|
| 36 |
if (!user_access('access services')) { |
if (!user_access('services oauth authorize consumers')) { |
| 37 |
drupal_set_message(t('You are not authorized to allow external services access to this system.'), 'error'); |
drupal_set_message(t('You are not authorized to allow external services access to this system.'), 'error'); |
| 38 |
return drupal_access_denied(); |
return drupal_access_denied(); |
| 39 |
} |
} |
| 166 |
|
|
| 167 |
$got_permission = $got_permission || $values['full_access']; |
$got_permission = $got_permission || $values['full_access']; |
| 168 |
|
|
| 169 |
// Pick the callback url apart and add the token parameter |
if (isset($parameters['oauth_callback'])) { |
| 170 |
$callback = parse_url($parameters['oauth_callback']); |
// Pick the callback url apart and add the token parameter |
| 171 |
$query = array(); |
$callback = parse_url($parameters['oauth_callback']); |
| 172 |
parse_str($callback['query'], $query); |
$query = array(); |
| 173 |
$query['oauth_token'] = $token->key; |
parse_str($callback['query'], $query); |
| 174 |
$callback['query'] = http_build_query($query, 'idx_', '&'); |
$query['oauth_token'] = $token->key; |
| 175 |
|
$callback['query'] = http_build_query($query, 'idx_', '&'); |
| 176 |
// Return to the consumer site |
|
| 177 |
header('Location: ' . _services_oauth_glue_url($callback), TRUE, 302); |
// Return to the consumer site |
| 178 |
exit; |
header('Location: ' . _services_oauth_glue_url($callback), TRUE, 302); |
| 179 |
|
exit; |
| 180 |
|
} |
| 181 |
|
else { |
| 182 |
|
drupal_goto('oauth/authorized'); |
| 183 |
|
} |
| 184 |
} |
} |
| 185 |
|
|
| 186 |
function _services_oauth_glue_url($parsed) { |
function _services_oauth_glue_url($parsed) { |
| 210 |
print $server->fetch_request_token($req); |
print $server->fetch_request_token($req); |
| 211 |
} |
} |
| 212 |
catch (OAuthException $e) { |
catch (OAuthException $e) { |
| 213 |
|
var_dump($e); die; |
| 214 |
drupal_set_header('HTTP/1.0 401 Unauthorized: ' . $e->getMessage()); |
drupal_set_header('HTTP/1.0 401 Unauthorized: ' . $e->getMessage()); |
| 215 |
drupal_set_header(sprintf('WWW-Authenticate: OAuth realm="%s"', url('', array('absolute'=>TRUE)))); |
drupal_set_header(sprintf('WWW-Authenticate: OAuth realm="%s"', url('', array('absolute'=>TRUE)))); |
| 216 |
} |
} |
| 287 |
$form['applications'] = $apps; |
$form['applications'] = $apps; |
| 288 |
} |
} |
| 289 |
|
|
| 290 |
if (user_access('access services', $account)) { |
if (user_access('services oauth authorize consumers', $account)) { |
| 291 |
$auth = array( |
$auth = array( |
| 292 |
'#type' => 'fieldset', |
'#type' => 'fieldset', |
| 293 |
'#title' => t('Authorizations'), |
'#title' => t('Authorizations'), |