You are here

function oauth_common_verify_request in OAuth 1.0 6.3

Same name and namespace in other branches
  1. 7.4 oauth_common.inc \oauth_common_verify_request()
  2. 7.3 oauth_common.inc \oauth_common_verify_request()

Verifies the request

Return value

array An array containing three elements. The first is TRUE if the request was signed, otherwise FALSE. Then comes the validated consumer and token objects.

1 call to oauth_common_verify_request()
_oauth_common_validate_request_callback in ./oauth_common.pages.inc
Combined menu callback for tests of consumers and access tokens

File

./oauth_common.inc, line 52

Code

function oauth_common_verify_request() {
  $req = DrupalOAuthRequest::from_request();

  // Verify
  $consumer_key = $req
    ->get_parameter('oauth_consumer_key');
  if (!empty($consumer_key)) {
    $consumer = DrupalOAuthConsumer::loadProviderByKey($consumer_key);
    if ($consumer) {
      $context = oauth_common_context_load($consumer->context);
      if (!$context) {
        throw new Exception('No OAuth context found');
      }
      _oauth_common_verify_body_hash($req);

      // Only verify request if we got a signature
      $signature = $req
        ->get_parameter('oauth_signature');
      if (!empty($signature)) {
        $server = new DrupalOAuthServer($context);
        return array_merge(array(
          TRUE,
        ), $server
          ->verify_request($req));
      }
      else {
        $token_key = $req
          ->get_parameter('oauth_token');
        if (empty($token_key) || !($token = DrupalOAuthToken::loadbyKey($token_key, $consumer))) {
          $token = NULL;
        }
        return array(
          FALSE,
          $consumer,
          $token,
        );
      }
    }
  }
  return array(
    FALSE,
    NULL,
    NULL,
  );
}