You are here

oauth.module in OAuth 1.0 6

Same filename and directory in other branches
  1. 8.2 oauth.module
  2. 8 oauth.module

File

oauth.module
View source
<?php

require_once "OAuth.php";
require_once "common.inc.php";

/**
 * Implementation of hook_menu
 */
function oauth_menu() {
  $items = array();
  $items['admin/build/oauth'] = array(
    'title' => t('Test OAuth'),
    'description' => t('Test OAuth calls to server'),
    'page callback' => 'oauth_test_calls',
    //  'access callback' => 'oauth_test_calls',
    'access arguments' => array(
      'consume provided services',
    ),
    'weight' => 10,
  );
  $items['oauth/request'] = array(
    'title' => t('Request token'),
    'page callback' => 'oauth_request_token',
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['oauth/auth'] = array(
    'title' => t('Authorize remote service'),
    'page callback' => 'oauth_auth_token',
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
  );
  $items['oauth/access'] = array(
    'title' => t('Request'),
    'page callback' => 'oauth_access_token',
    'access arguments' => array(
      'access content',
    ),
    'type' => MENU_CALLBACK,
  );

  /**
   * @TODO Move the consumer settings to a separate tab.
   */

  /*
  $items['user/%user/services'] = array(
    'title' => t('Consumer settings'),
    'page callback' => 'oauth_consumer_view',
    'access callback' => 'oauth_access_consumer_view',
    'type' => MENU_LOCAL_TASK,
    'weight' => 10
  );
  */
  return $items;
}

/**
 * Implementation of hook_perm
 */
function oauth_perm() {
  return array(
    "authorize external services",
    "consume provided services",
  );
}

/**
 * Implementation of hook_user
 *
 * Used to provide consumer key/secret for consumers
 */
function oauth_user($op, &$edit, $account, $category) {
  global $user;
  switch ($op) {
    case 'view':
      if ($account->uid == $user->uid && user_access("consume provided services") || $user->uid == 1) {
        $consumer = oauth_get_consumer($account->uid);
        $account->content['consumer_key'] = array();
        $account->content['consumer_key'] += array(
          '#type' => 'user_profile_category',
          '#attributes' => array(
            'class' => 'user-member',
          ),
          '#weight' => 5,
          '#title' => t('External services'),
        );
        $account->content['consumer_key']['request_url'] = array(
          '#type' => 'user_profile_item',
          '#title' => t('Request token URL'),
          '#value' => url('oauth/request', array(
            'absolute' => TRUE,
          )),
          '#weight' => 1,
        );
        $account->content['consumer_key']['auth_url'] = array(
          '#type' => 'user_profile_item',
          '#title' => t('User authentication URL'),
          '#value' => url('oauth/auth', array(
            'absolute' => TRUE,
          )),
          '#weight' => 2,
        );
        $account->content['consumer_key']['access_url'] = array(
          '#type' => 'user_profile_item',
          '#title' => t('Access token URL'),
          '#value' => url('oauth/access', array(
            'absolute' => TRUE,
          )),
          '#weight' => 3,
        );
        $account->content['consumer_key']['key'] = array(
          '#type' => 'user_profile_item',
          '#title' => t('Consumer key'),
          '#value' => $consumer->key,
          '#weight' => 4,
        );
        $account->content['consumer_key']['secret'] = array(
          '#type' => 'user_profile_item',
          '#title' => t('Consumer secret'),
          '#value' => $consumer->secret,
          '#weight' => 5,
        );
      }
      break;
  }
}

/**
 * Initialize and store an OAuthServer object.
 */
function _oauth_init_server() {
  static $server = null;
  require_once "OAuth.php";
  require_once "OAuth_TestServer.php";
  $server = new OAuthServer(new DrupalOAuthDataStore());
  $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
  $plaintext_method = new OAuthSignatureMethod_PLAINTEXT();
  $rsa_method = new TestOAuthSignatureMethod_RSA_SHA1();
  $server
    ->add_signature_method($hmac_method);
  $server
    ->add_signature_method($plaintext_method);
  $server
    ->add_signature_method($rsa_method);
  return $server;
}

/**
 * Generate a request token from the request
 */
function oauth_request_token() {
  $server = _oauth_init_server();

  // Remove the q variable from the query string, as it will break
  // the signature validation.
  $q = $_GET['q'];
  unset($_GET['q']);
  try {
    $req = OAuthRequest::from_request();
    $token = $server
      ->fetch_request_token($req);
    print $token;
  } 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;
}

/**
 * Authorize a request token.
 *
 * Redirects to login form if not logged in, and displays the grant access form once logged in.
 */
function oauth_auth_token() {

  // Redirect to the right form, or present an error.
  global $user;
  if ($user->uid != 0) {
    if (user_access("authorize external services")) {
      return drupal_get_form("oauth_grant_access");
    }
    else {
      drupal_set_message("error", t("You are not authorized to allow external services access to this system."));
      drupal_access_denied();
    }
  }
  else {
    return drupal_get_form("user_login");

    //oauth_auth_token();
  }
}
function oauth_access_token() {
  $server = _oauth_init_server();

  // Remove the q variable from the query string, as it will break
  // the signature validation.
  $q = $_GET['q'];
  unset($_GET['q']);
  try {
    global $user;
    $req = OAuthRequest::from_request();
    $token = $server
      ->fetch_access_token($req);
    parse_str($token);
    print $token;
  } 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 callback for granting access to the consumer
 */
function oauth_grant_access() {
  module_invoke('services');
  $services = services_get_all();

  #todo tripple check image reference.
  $form['oauth_callback'] = array(
    '#type' => 'hidden',
    '#value' => $_GET['oauth_callback'],
  );
  $form['oauth_token'] = array(
    '#type' => 'hidden',
    '#value' => $_GET['oauth_token'],
  );
  $form['oauth_consumer_key'] = array(
    '#type' => 'hidden',
    '#value' => $_GET['oauth_consumer_key'],
  );
  $form['oauth_nonce'] = array(
    '#type' => 'hidden',
    '#value' => $_GET['oauth_nonce'],
  );
  $form['oauth_nonce_timestamp'] = array(
    '#type' => 'hidden',
    '#value' => $_GET['oauth_timestamp'],
  );
  $form['services'] = array(
    '#title' => t('Select services'),
    '#type' => 'fieldset',
  );
  foreach ($services as $service) {
    $method_name = $service['#method'];
    $form['services'][$method_name] = array(
      '#title' => $service['#method'],
      '#type' => 'radios',
      '#options' => array(
        0 => t('access'),
        1 => t('block'),
      ),
      '#default_value' => 1,
    );
  }
  $form['confirm'] = array(
    '#type' => 'submit',
    '#value' => t('Grant access'),
    '#weight' => 10,
  );
  $form['#tree'] = TRUE;
  return $form;
}

/**
 * 
 * Asks users for granting proper access/deny permissions for different services
 * 
 * @param method_name 
 * 			name of service provided by Services module
 * 
 * @param 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.
 */
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'];
}

/**
 * Authorize a request token
 *
 * Set the authorized property for the token, to allow an access token to be generated, 
 * also set the UID of the request token.
 *
 * @param key
 *   Request token key.
 */
function oauth_authorize_request_token($key) {
  global $user;
  db_query("UPDATE {oauth_token} SET authorized = 1, uid=%d WHERE token_key = '%s'", $user->uid, $key);
}

/**
 * Authorize access from access token
 *
 * Used by services that implement oauth access. This function also sets the active user to the person
 * who authorized the access token.
 *
 * @param key
 *   Access token key
 * @param secret
 *   Access token secret
 * @return
 *   The user ID assigned to the token if successful, or null if unsuccessful.
 */
function oauth_authorize_access($key, $secret) {
  global $user;
  $result = db_query("SELECT * FROM {oauth_token} WHERE type='access' AND token_key = '%s' AND token_secret='%s'", $key, $secret);
  if ($object = db_fetch_object($result)) {
    $user = user_load($object->uid);
    return $user->uid;
  }
  return null;
}

# Return a list of services
function oauth_services() {
}

/**
 * Implementation of hook_cron
 *
 * Prune the oauth_nonce table
 */
function oauth_cron() {
  db_query("DELETE FROM {oauth_nonce} WHERE nonce_timestamp > %d", strtotime("-1 day"));
}

/**
 * Generate a new consumer ID for a user.
 *
 * @param uid
 *    User ID to generate the consumer record for
 * @return
 *    OAuthConsumer object for new client.
 */
function oauth_generate_consumer($uid) {
  $key = user_password(32);
  $secret = user_password(32);
  oauth_save_consumer($uid, $key, $secret);
  return new OAuthConsumer($key, $secret);
}

/**
 * Save consumer record to oauth_consumer table
 *
 * @param uid
 *   User ID to save consumer record for
 * @param key
 *   Consumer Key
 * @param secret
 *   Consumer Secret
 */
function oauth_save_consumer($uid, $key, $secret) {
  db_query("INSERT INTO {oauth_consumer} VALUES (%d, '%s', '%s')", $uid, $key, $secret);
}

/**
 * Return consumer object for a user
 *
 * If the consumer record does not exist, it will be created.
 *
 * @param uid
 *   User ID to retrieve consumer object for.
 * @return
 *   Consumer object.
 */
function oauth_get_consumer($uid) {
  $result = db_query("SELECT * FROM {oauth_consumer} WHERE uid=%d", $uid);
  if ($object = db_fetch_object($result)) {
    return new OAuthConsumer($object->consumer_key, $object->consumer_secret);
  }
  else {
    return oauth_generate_consumer($uid);
  }
}

/**
 * Database abstraction class
 */
class DrupalOAuthDataStore extends OAuthDataStore {
  function lookup_consumer($consumer_key) {
    $result = db_query("SELECT * FROM {oauth_consumer} WHERE consumer_key='%s'", $consumer_key);
    if ($object = db_fetch_object($result)) {
      return new OAuthConsumer($object->consumer_key, $object->consumer_secret);
    }
    return null;
  }
  function lookup_token($consumer, $token_type, $token) {
    $result = db_query("SELECT * FROM {oauth_token} WHERE type='%s' AND consumer_key='%s' AND token_key = '%s'", $token_type, $consumer->key, $token);
    if ($object = db_fetch_object($result)) {
      return new OAuthToken($object->token_key, $object->token_secret);
    }
    return null;
  }
  function lookup_nonce($consumer, $token, $nonce, $timestamp) {
    $nonce_1 = db_result(db_query("SELECT nonce FROM {oauth_nonce} WHERE nonce_timestamp='%s'", $timestamp));
    if (!$nonce_1) {
      db_query("INSERT INTO {oauth_nonce} (nonce, nonce_timestamp) VALUES ('%s', %d)", $nonce, $timestamp);
      return null;
    }
    return $nonce_1;
  }
  function new_request_token($consumer) {
    $user_id = db_result(db_query("SELECT uid FROM {oauth_consumer} WHERE consumer_key='%s'", $consumer->key));
    $token = new OAuthToken(user_password(32), user_password(32));
    db_query("INSERT INTO {oauth_token} (consumer_key, type, token_key, token_secret, uid) VALUES ('%s', '%s', '%s', '%s', %d)", $consumer->key, 'request', $token->key, $token->secret, $user_id);
    return $token;
  }

  /**
   *
   *@param session_id
   * 		is session id corresponding to logged in user
   * 		we are storing session id in oauth_services table to keep track of users and issued access tokens
   *
   * @param user_id
   * 		user_id is actually $user->id but we are fetching it from oauth_consumer table and using it to get session_id from sessions
   * 		table and also storing its value to oauth_token table (corresponding to access token here)
   *
   */
  function new_access_token($request_token, $consumer, $user = NULL) {
    if ($object = db_fetch_object(db_query("SELECT * FROM {oauth_token} WHERE type='request' and token_key = '%s'", $request_token->key))) {
      if ($object->authorized) {
        $token = new OAuthToken(user_password(32), user_password(32));
        $user_id = db_result(db_query("SELECT uid FROM {oauth_consumer} WHERE consumer_key = '%s'", $consumer->key));
        $session_id = db_result(db_query("SELECT sid FROM {sessions} WHERE uid=%d", $user_id));
        db_query("INSERT INTO {oauth_token} (consumer_key, type, token_key, token_secret, uid) VALUES ('%s', '%s', '%s', '%s', %d)", $consumer->key, 'access', $token->key, $token->secret, $user_id);
        db_query("DELETE FROM {oauth_token} WHERE type='request' AND token_key='%s'", $request_token->key);
        db_query("UPDATE {oauth_services} SET token_key = '%s' WHERE session_id= '%s'", $token->key, $session_id);
        return $token;
      }
    }
    return null;
  }

}

/**
 * 
 * this function is to make test calls to any oauth server for producing oauth tokens corresponding to your keys and secret
 * 
 * this code can be used by client to make calls to server to fetch and phrase tokens as we are doing here  
 * 
 */
function oauth_test_calls() {
  return drupal_get_form("oauth_request_call");
}
function oauth_request_call($form_state) {
  if (!$_SESSION['oauth']['operation']) {
    $_SESSION['oauth']['operation'] = 'request';
  }

  // indicator of step number
  $form['indicator'] = array(
    '#type' => 'fieldset',
    '#title' => t('Step @number', array(
      '@number' => $_SESSION['oauth']['operation'],
    )),
  );
  if ($_SESSION['oauth']['operation'] == 'request') {
    $form['indicator']['consumer'] = array(
      '#type' => 'fieldset',
      '#title' => t('consumer details'),
    );
    $form['indicator']['consumer']['consumer_key'] = array(
      '#title' => t('consumer key'),
      '#description' => t('consumer key of user on test server'),
      '#type' => 'textfield',
    );
    $form['indicator']['consumer']['consumer_secret'] = array(
      '#title' => t('consumer secret'),
      '#description' => t('consumer secret of user on test server'),
      '#type' => 'textfield',
    );
    $form['indicator']['endpoints'] = array(
      '#title' => t('end points of testing server'),
      '#type' => 'fieldset',
    );
    $form['indicator']['endpoints']['request_url'] = array(
      '#title' => t('Request URL'),
      '#type' => 'textfield',
      '#weight' => 5,
      '#default_value' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?q=oauth/request',
    );
    $form['indicator']['signature_method'] = array(
      '#title' => t('Select Signature Method'),
      '#type' => 'fieldset',
    );
    $form['indicator']['signature_method']['indicator']['sig_method'] = array(
      '#title' => t('Please select signature method to use'),
      '#type' => 'radios',
      '#options' => array(
        0 => t('HMAC-SHA1'),
        1 => t('PLAINTEXT'),
        2 => t('RSA-SHA1'),
      ),
      '#weight' => 9,
    );
    $form['indicator']['request_call'] = array(
      '#value' => t('Request Token Call'),
      '#title' => t('Make call to server'),
      '#type' => 'submit',
      '#weight' => 10,
    );
  }
  if ($_SESSION['oauth']['operation'] == 'auth') {
    $form['indicator']['endpoints'] = array(
      '#title' => t('end points of testing server'),
      '#type' => 'fieldset',
    );
    $form['indicator']['endpoints']['auth_url'] = array(
      '#title' => t('Authentication URL'),
      '#type' => 'textfield',
      '#weight' => 6,
      '#default_value' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?q=oauth/auth',
    );
    $form['indicator']['token'] = array(
      '#type' => 'fieldset',
      '#title' => t('Token and Token secret'),
      '#description' => t('Paste Token and Token Secret from above which are obtained after request call'),
      '#weight' => 11,
    );
    $form['indicator']['token']['oauth_token'] = array(
      '#title' => t('OAuth token'),
      '#description' => t('Please paste token from above which you obtain from request call'),
      '#type' => 'textfield',
      '#weight' => 12,
      '#default_value' => $form_state['data']['oauth_token'],
    );
    $form['indicator']['token']['oauth_token_secret'] = array(
      '#title' => t('OAuth token secret'),
      '#description' => t('Please paste token secret from above which you obtain from request call'),
      '#type' => 'textfield',
      '#weight' => 13,
      '#default_value' => $form_state['data']['oauth_token_secret'],
    );
    $form['indicator']['auth_call'] = array(
      '#value' => t('OAuth Authentication Call'),
      '#type' => 'submit',
      '#weight' => 14,
    );
  }
  if ($_SESSION['oauth']['operation'] == 'access') {
    $form['indicator']['endpoints']['access_url'] = array(
      '#title' => t('Access URL'),
      '#type' => 'textfield',
      '#weight' => 7,
      '#default_value' => 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . '?q=oauth/access',
    );
    $form['indicator']['access_call'] = array(
      '#value' => t('OAuth Access Token Call'),
      '#type' => 'submit',
      '#weight' => 15,
    );
  }
  switch ($_SESSION['oauth']['operation']) {
    case auth:
      $form['consumer_key'] = array(
        '#type' => 'hidden',
        '#value' => $form_state['values']['consumer_key'],
      );
      $form['consumer_secret'] = array(
        '#type' => 'hidden',
        '#value' => $form_state['values']['consumer_secret'],
      );
      $form['request_url'] = array(
        '#type' => 'hidden',
        '#value' => $form_values['request_url'],
      );
      break;
  }
  $form['back'] = array(
    '#value' => t('Back To Request Token Page'),
    '#type' => 'submit',
    '#weight' => 17,
  );
  return $form;
}
function oauth_request_call_validate($form, &$form_state) {
  if ($form_state['values']['op'] == 'Request Token Call') {
    if (!$form_state['values']['consumer_key'] || !$form_state['values']['consumer_secret'] || !$form_state['values']['request_url'] || !$form_state['values']['sig_method']) {
      form_set_error('form', t('All Fields are Required to produce Request Tokens'));
    }
  }
  if ($form_state['values']['op'] == 'OAuth Authentication Call') {
    if (!$form_state['values']['oauth_token'] || !$form_state['values']['oauth_token_secret'] || !$form_state['values']['auth_url']) {
      form_set_error('form', t('All Fields are Required to make Authentication Requests to Server'));
    }
  }
  if ($form_state['values']['op'] == 'OAuth Access Token Call') {
    if (!$form_state['values']['access_url']) {
      form_set_error('form', t('Please fill Access endpoint URL (eg. http://yourdrupalsite.com/?q=oauth/access)'));
    }
  }
  if ($form_state['values']['op'] == 'Back To Request Token Page') {
    $_SESSION['oauth']['operation'] = '';
    $_SESSION['oauth']['key'] = '';
    $_SESSION['oauth']['key_secret'] = '';
    $_SESSION['oauth']['oauth_token'] = '';
    $_SESSION['oauth']['oauth_token_secret'] = '';
    $_SESSION['oauth']['oauth_access_token'] = '';
    $_SESSION['oauth']['oauth_access_token_secret'] = '';
    $_SESSION['oauth']['oauth_signature_method'] = '';
    return;
  }
}
function oauth_request_call_submit($form, &$form_state) {
  $key = $form_state['values']['consumer_key'];
  $secret = $form_state['values']['consumer_secret'];
  $request_url = $form_state['values']['request_url'];
  global $user;

  // signature method declarations
  $plaintext_method = new OAuthSignatureMethod_PLAINTEXT();
  $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
  $rsa_method = new TestOAuthSignatureMethod_RSA_SHA1();
  if (!$_SESSION['oauth']['oauth_signature_method']) {
    if ($form_state['values']['sig_method'] == 0) {
      $user_sig_method = 'HMAC-SHA1';
      $_SESSION['oauth']['oauth_signature_method'] = 'HMAC-SHA1';
    }
    elseif ($form_state['values']['sig_method'] == 1) {
      $user_sig_method = 'PLAINTEXT';
      $_SESSION['oauth']['oauth_signature_method'] = 'PLAINTEXT';
    }
    elseif ($form_state['values']['sig_method'] == 2) {
      $user_sig_method = 'RSA-SHA1';
      $_SESSION['oauth']['oauth_signature_method'] = 'RSA-SHA1';
    }
  }
  if ($_SESSION['oauth']['oauth_signature_method'] == 'HMAC-SHA1') {
    $sig_method = $hmac_method;
  }
  else {
    if ($_SESSION['oauth']['oauth_signature_method'] == 'PLAINTEXT') {
      $sig_method = $plaintext_method;
    }
    else {
      if ($_SESSION['oauth']['oauth_signature_method'] == 'RSA-SHA1') {
        $sig_method = $rsa_method;
      }
    }
  }
  $test_token = NULL;
  $token = $form_state['values']['oauth_token'];
  $token_secret = $form_state['values']['oauth_token_secret'];
  $test_consumer = new OAuthConsumer($key, $secret, NULL);
  if ($form_state['values']['op'] == 'OAuth Authentication Call') {
    $_SESSION['oauth']['key'] = $form_state['values']['consumer_key'];
    $_SESSION['oauth']['key_secret'] = $form_state['values']['consumer_secret'];
    $_SESSION['oauth']['oauth_token'] = $token;
    $_SESSION['oauth']['oauth_token_secret'] = $token_secret;
    $test_token = new OAuthConsumer($token, $token_secret, $callback_url);
    $test_consumer = new OAuthConsumer($form_state['values']['consumer_key'], $form_state['values']['consumer_secret'], $callback_url);
    $parsed = parse_url($form_state['values']['auth_url']);
    $params = array();
    parse_str($parsed['query'], $params);
    $req_auth = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, "GET", $form_state['values']['auth_url'], $params);
    $req_auth
      ->sign_request($sig_method, $test_consumer, $test_token);
    $form_state['rebuild'] = TRUE;
    $_SESSION['oauth']['operation'] = 'access';
    $domain = $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
    $callback_url = 'http://' . $domain;
    Header("Location: {$req_auth}&oauth_callback={$callback_url}");
  }
  elseif ($form_state['values']['op'] == 'OAuth Access Token Call') {
    $test_consumer = new OAuthConsumer($_SESSION['oauth']['key'], $_SESSION['oauth']['key_secret'], NULL);
    $test_token = new OAuthConsumer($_SESSION['oauth']['oauth_token'], $_SESSION['oauth']['oauth_token_secret']);
    $parsed = parse_url($form_state['values']['access_url']);
    $params = array();
    parse_str($parsed['query'], $params);
    $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, "GET", $form_state['values']['access_url'], $params);
    $acc_req
      ->sign_request($sig_method, $test_consumer, $test_token);
    $result_access = drupal_http_request($acc_req, $headers = array(), $method = 'GET', $data = NULL, $retry = 3);
    parse_str($result_access->data);
    $_SESSION['oauth']['oauth_access_token'] = $oauth_token;
    $_SESSION['oauth']['oauth_access_token_secret'] = $oauth_token_secret;
    drupal_set_message('<pre>' . print_r("oauth_access_token  {$oauth_token}", TRUE) . '</pre>');
    drupal_set_message('<pre>' . print_r("oauth_access_token_secret  {$oauth_token_secret}", TRUE) . '</pre>');
    drupal_redirect_form($form, 'admin/build/services');
  }
  if ($form_state['values']['op'] == 'Request Token Call') {
    $parsed = parse_url($request_url);
    $params = array();
    parse_str($parsed['query'], $params);
    $req_req = OAuthRequest::from_consumer_and_token($test_consumer, NULL, "GET", $request_url, $params);
    $req_req
      ->sign_request($sig_method, $test_consumer, NULL);
    $result_request = drupal_http_request($req_req, $headers = array(), $method = 'GET', $data = NULL, $retry = 3);
    parse_str($result_request->data);
    drupal_set_message('<pre>' . print_r("oauth_token  {$oauth_token}", TRUE) . '</pre>');
    drupal_set_message('<pre>' . print_r("oauth_token_secret  {$oauth_token_secret}", TRUE) . '</pre>');
    $form_state['rebuild'] = TRUE;
    $form_state['data']['oauth_token'] = $oauth_token;
    $form_state['data']['oauth_token_secret'] = $oauth_token_secret;
    $_SESSION['oauth']['operation'] = 'auth';
  }
}

Functions

Namesort descending Description
oauth_access_token
oauth_authorize_access Authorize access from access token
oauth_authorize_request_token Authorize a request token
oauth_auth_token Authorize a request token.
oauth_cron Implementation of hook_cron
oauth_generate_consumer Generate a new consumer ID for a user.
oauth_get_consumer Return consumer object for a user
oauth_grant_access Form callback for granting access to the consumer
oauth_grant_access_submit Asks users for granting proper access/deny permissions for different services
oauth_menu Implementation of hook_menu
oauth_perm Implementation of hook_perm
oauth_request_call
oauth_request_call_submit
oauth_request_call_validate
oauth_request_token Generate a request token from the request
oauth_save_consumer Save consumer record to oauth_consumer table
oauth_services
oauth_test_calls this function is to make test calls to any oauth server for producing oauth tokens corresponding to your keys and secret
oauth_user Implementation of hook_user
_oauth_init_server Initialize and store an OAuthServer object.

Classes

Namesort descending Description
DrupalOAuthDataStore Database abstraction class