You are here

function oauth_grant_access_submit in OAuth 1.0 6

Asks users for granting proper access/deny permissions for different services

Parameters

method_name : name of service provided by Services module

services_oauth_serialized: a serialized array storing permissions for different services to be stored in oauth_services table

Submit callback for oauth/auth

Authorizes an existing oauth request token and redirects to sender.

File

./oauth.module, line 275

Code

function oauth_grant_access_submit($form, &$form_state) {
  global $user;
  module_invoke('services');
  $services = services_get_all();
  foreach ($services as $service) {
    $method_name = $service['#method'];
    if ($form_state['values']['services'][$method_name] == 0) {
      $services_oauth[$method_name]['name'] = $method_name;
      $services_oauth[$method_name]['permission'] = 1;
    }
    elseif ($form_state['values']['services'][$method_name] == 1) {
      $services_oauth[$method_name]['name'] = $method_name;
      $services_oauth[$method_name]['permission'] = 0;
    }
  }
  $services_oauth_serialized = serialize($services_oauth);
  db_query("INSERT INTO {oauth_services} (consumer_key, services, timestamp, session_id ) VALUES ('%s', '%s', %d, '%s')", $form_state['values']['oauth_consumer_key'], $services_oauth_serialized, $form_state['values']['oauth_nonce_timestamp'], $user->sid);
  $server = _oauth_init_server();
  $q = $_GET['q'];
  unset($_GET['q']);
  try {
    $req = OAuthRequest::from_request();
    oauth_authorize_request_token($form_state['values']['oauth_token']);
    drupal_goto($req
      ->get_parameter('oauth_callback'));
  } catch (OAuthException $e) {
    print $e
      ->getMessage() . "\n<hr />\n";
    print_r($req);
    die;
  }

  // Set the $_GET['q'] back to it's original value
  $_GET['q'] = $q;
  $form_state['redirect'] = $form_state['values']['oauth_callback'];
}