public static function build_http_body($params)
 {
     if (!$params) {
         return '';
     }
     // Urlencode both keys and values
     $keys = OAuthUtil::urlencode_rfc3986(array_keys($params));
     $values = OAuthUtil::urlencode_rfc3986(array_values($params));
     $params = array_combine($keys, $values);
     // Parameters are sorted by name, using lexicographical byte value ordering.
     // Ref: Spec: 9.1.1 (1)
     uksort($params, 'strcmp');
     $pairs = array();
     foreach ($params as $parameter => $value) {
         if (is_array($value)) {
             // If two or more parameters share the same name, they are sorted by their value
             // Ref: Spec: 9.1.1 (1)
             // June 12th, 2010 - changed to sort because of issue 164 by hidetaka
             sort($value, SORT_STRING);
             foreach ($value as $duplicate_value) {
                 $pairs[] = $parameter . '=' . $duplicate_value;
             }
         } else {
             $pairs[] = $parameter . '=' . $value;
         }
     }
     // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
     // Each name-value pair is separated by an '&' character (ASCII code 38)
     return implode('&', $pairs);
 }
 public function getPostvals($force = false)
 {
     if (opCalendarApiHandler::GET !== $this->method || $force) {
         if (!$this->parameters) {
             return null;
         }
         // Urlencode both keys and values
         $keys = OAuthUtil::urlencode_rfc3986(array_keys($this->parameters));
         $values = OAuthUtil::urlencode_rfc3986(array_values($this->parameters));
         $params = array_combine($keys, $values);
         // Parameters are sorted by name, using lexicographical byte value ordering.
         // Ref: Spec: 9.1.1 (1)
         uksort($params, 'strcmp');
         $pairs = array();
         foreach ($params as $parameter => $value) {
             if (is_array($value)) {
                 // If two or more parameters share the same name, they are sorted by their value
                 // Ref: Spec: 9.1.1 (1)
                 natsort($value);
                 foreach ($value as $duplicate_value) {
                     $pairs[] = $parameter . '=' . $duplicate_value;
                 }
             } else {
                 $pairs[] = $parameter . '=' . $value;
             }
         }
         // For each parameter, the name is separated from the corresponding value by an '=' character (ASCII code 61)
         // Each name-value pair is separated by an '&' character (ASCII code 38)
         return implode('&', $pairs);
     }
     return null;
 }
Example #3
0
 /**
  * (non-PHPdoc)
  * @see plugins/sfDoctrineOAuthPlugin/lib/sfOAuth::getAccessToken()
  */
 public function getAccessToken($verifier, $parameters = array())
 {
     $url = $this->getAccessTokenUrl();
     $this->setAccessParameter('client_id', $this->getKey());
     $this->setAccessParameter('client_secret', $this->getSecret());
     $this->setAccessParameter('redirect_uri', $this->getCallback());
     $this->setAccessParameter('code', $verifier);
     $this->addAccessParameters($parameters);
     $params = $this->call($url, $this->getAccessParameters(), 'GET');
     $params = OAuthUtil::parse_parameters($params);
     $access_token = isset($params['access_token']) ? $params['access_token'] : null;
     if (is_null($access_token) && $this->getLogger()) {
         $error = sprintf('{OAuth} access token failed - %s returns %s', $this->getName(), print_r($params, true));
         $this->getLogger()->err($error);
     } elseif ($this->getLogger()) {
         $message = sprintf('{OAuth} %s return %s', $this->getName(), print_r($params, true));
         $this->getLogger()->info($message);
     }
     $token = new Token();
     $token->setTokenKey($access_token);
     $token->setName($this->getName());
     $token->setStatus(Token::STATUS_ACCESS);
     $token->setOAuthVersion($this->getVersion());
     unset($params['access_token']);
     if (count($params) > 0) {
         $token->setParams($params);
     }
     $this->setExpire($token);
     $this->setToken($token);
     // get identifier maybe need the access token
     $token->setIdentifier($this->getIdentifier());
     $this->setToken($token);
     return $token;
 }
 /**
  * @see TwitterOAuth::http()
  * @author Naomichi Yamakita <*****@*****.**>
  */
 public function http($uri, $method, $postData = NULL)
 {
     // TwitterOAuth::http() はレスポンスヘッダを書き換えてるため使用しない
     // (Mars_ResponseParser の動作に影響するため)
     $sender = new Mars_HttpRequestSender($uri);
     $sender->setUserAgent($this->useragent);
     $sender->setReadTimeout($this->connecttimeout);
     $sender->addHeader('Expect', '');
     if (is_string($postData)) {
         parse_str($postData, $postData);
     }
     if ($method === 'POST') {
         $sender->setRequestMethod(Mars_HttpRequest::HTTP_POST);
         $sender->addParameters($postData);
     } else {
         if ($method === 'DELETE') {
             $sender->setRequestMethod(Mars_HttpRequest::HTTP_DELETE);
             if (sizeof($postData)) {
                 $uri = $uri . '?' . OAuthUtil::build_http_query($postData);
             }
         }
     }
     $sender->setBaseURI($uri);
     $parser = $sender->send();
     $this->http_code = $parser->getStatus();
     $this->http_info = $parser->getRawHeader();
     $this->url = $uri;
     return $parser->getContents();
 }
 public function getAccessToken($consumerName, $accessTokenURL, $requestToken, $httpMethod = 'POST', $parameters = array())
 {
     $this->url = $accessTokenURL;
     $queryStringParams = OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']);
     $parameters['oauth_verifier'] = $queryStringParams['oauth_verifier'];
     $request = $this->createRequest($consumerName, $httpMethod, $accessTokenURL, $requestToken, $parameters);
     return $this->doRequest($request);
 }
 /**
  * oauth_signature is set to the concatenated encoded values of the Consumer Secret and
  * Token Secret, separated by a '&' character (ASCII code 38), even if either secret is
  * empty. The result MUST be encoded again.
  *   - Chapter 9.4.1 ("Generating Signatures")
  *
  * Please note that the second encoding MUST NOT happen in the SignatureMethod, as
  * OAuthRequest handles this!
  */
 public function build_signature($request, $consumer, $token)
 {
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
     $request->base_string = $key;
     return $key;
 }
 public function build_signature($request, $consumer, $token)
 {
     $base_string = $request->get_signature_base_string();
     $request->base_string = $base_string;
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
     return base64_encode(hash_hmac('sha1', $base_string, $key, true));
 }
 /**
  * gets security token string from get, post or auth header
  * @return string
  */
 public static function getTokenStringFromRequest()
 {
     if (self::$rawToken) {
         return self::$rawToken;
     }
     $headers = OAuthUtil::get_headers();
     self::$rawToken = isset($_GET['st']) ? $_GET['st'] : (isset($_POST['st']) ? $_POST['st'] : (isset($headers['Authorization']) ? self::parseAuthorization($headers['Authorization']) : ''));
     return self::$rawToken;
 }
Example #9
0
 public function testGetHeaders()
 {
     if (function_exists('apache_request_headers')) {
         $this->markTestSkipped('We assume the apache module is well tested. Since this module is present, no need testing our suplement');
     }
     $_SERVER['HTTP_HOST'] = 'foo';
     $_SERVER['HTTP_X_WHATEVER'] = 'bar';
     $this->assertEquals(array('Host' => 'foo', 'X-Whatever' => 'bar'), OAuthUtil::get_headers());
 }
Example #10
0
 private function execute($selected_call, $method_type, $params)
 {
     // the endpoint for your request
     $endpoint = "{$this->netdnarws_url}/{$this->alias}{$selected_call}";
     //parse endpoint before creating OAuth request
     $parsed = parse_url($endpoint);
     if (array_key_exists("parsed", $parsed)) {
         parse_str($parsed['query'], $params);
     }
     //generate a request from your consumer
     require_once __DIR__ . '/OAuth/OAuthRequest.php';
     $req_req = OAuthRequest::from_consumer_and_token($this->consumer, null, $method_type, $endpoint, $params);
     //sign your OAuth request using hmac_sha1
     require_once __DIR__ . '/OAuth/OAuthSignatureMethod_HMAC_SHA1.php';
     $sig_method = new OAuthSignatureMethod_HMAC_SHA1();
     $req_req->sign_request($sig_method, $this->consumer, null);
     // create curl resource
     $ch = curl_init();
     // set url
     curl_setopt($ch, CURLOPT_URL, $req_req);
     // return the transfer as a string
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
     // Set SSL Verifyer off
     curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
     // set curl timeout
     curl_setopt($ch, CURLOPT_TIMEOUT, 60);
     // set curl custom request type if not standard
     if ($method_type != "GET" && $method_type != "POST") {
         curl_setopt($ch, CURLOPT_CUSTOMREQUEST, $method_type);
     }
     if ($method_type == "POST" || $method_type == "PUT" || $method_type == "DELETE") {
         require_once __DIR__ . '/OAuth/OAuthUtil.php';
         $query_str = OAuthUtil::build_http_query($params);
         curl_setopt($ch, CURLOPT_HTTPHEADER, array('Expect:', 'Content-Length: ' . strlen($query_str)));
         curl_setopt($ch, CURLOPT_POSTFIELDS, $query_str);
     }
     // retrieve headers
     curl_setopt($ch, CURLOPT_HEADER, 1);
     curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
     //set user agent
     curl_setopt($ch, CURLOPT_USERAGENT, 'PHP NetDNA API Client');
     // make call
     $result = curl_exec($ch);
     $headers = curl_getinfo($ch);
     $curl_error = curl_error($ch);
     // close curl resource to free up system resources
     curl_close($ch);
     // $json_output contains the output string
     $json_output = substr($result, $headers['header_size']);
     // catch errors
     if (!empty($curl_error) || empty($json_output)) {
         //throw new \NetDNA\RWSException("CURL ERROR: $curl_error, Output: $json_output", $headers['http_code'], null, $headers);
         return 'CURL ERROR: ' . $curl_error . ', Output: ' . $json_output;
     }
     return $json_output;
 }
Example #11
0
 public static function fetchQuery($query, $ts)
 {
     if (!$query) {
         return;
     }
     $dbr = wfGetDB(DB_SLAVE);
     $sql = "select min(ql_time_fetched) as ts from dedup.query_lookup where ql_query=" . $dbr->addQuotes($query);
     $res = $dbr->query($sql, __METHOD__);
     foreach ($res as $row) {
         $oldTs = $row->ts;
     }
     if ($oldTs > $ts) {
         $dbw = wfGetDB(DB_MASTER);
         $sql = "insert into dedup.query_lookup_log(qll_query, qll_result, qll_timestamp) values(" . $dbw->addQuotes($query) . "," . $dbw->addQuotes("exists") . "," . $dbw->addQuotes(wfTimestampNow()) . ")";
         $dbw->query($sql, __METHOD__);
         return;
     }
     try {
         $cc_key = WH_YAHOO_BOSS_API_KEY;
         $cc_secret = WH_YAHOO_BOSS_API_SECRET;
         $url = "http://yboss.yahooapis.com/ysearch/web";
         $args = array();
         $args["q"] = $query;
         $args["format"] = "json";
         $consumer = new OAuthConsumer($cc_key, $cc_secret);
         $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $url, $args);
         $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
         $url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
         $ch = curl_init();
         $headers = array($request->to_header());
         curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
         curl_setopt($ch, CURLOPT_URL, $url);
         curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
         $rsp = curl_exec($ch);
         $results = json_decode($rsp);
         if ($results->bossresponse->responsecode == 200) {
             $n = 0;
             $dbw = wfGetDB(DB_MASTER);
             foreach ($results->bossresponse->web->results as $result) {
                 $n++;
                 $sql = "insert into dedup.query_lookup(ql_query,ql_url,ql_pos,ql_time_fetched) values(" . $dbw->addQuotes($query) . "," . $dbw->addQuotes($result->url) . "," . $dbw->addQuotes($n) . "," . $dbw->addQuotes(wfTimestampNow()) . ")";
                 $dbw->query($sql, __METHOD__);
             }
             $sql = "insert into dedup.query_lookup_log(qll_query, qll_result, qll_timestamp) values(" . $dbw->addQuotes($query) . "," . $dbw->addQuotes('success') . "," . $dbw->addQuotes(wfTimestampNow()) . ")";
             $dbw->query($sql, __METHOD__);
         } else {
             $dbw = wfGetDB(DB_MASTER);
             $sql = "insert into dedup.query_lookup_log(qll_query, qll_result, qll_timestamp, qll_timestamp, qll_comment) values(" . $dbw->addQuotes($query) . "," . $dbw->addQuotes('badresponse') . "," . $dbw->addQuotes(wfTimestampNow()) . "," . $dbw->addQuotes("Response : " . ($results ? print_r($results, true) : ''));
             $dbw->query($sql, __METHOD__);
         }
     } catch (Exception $ex) {
         $dbw = wfGetDB(DB_MASTER);
         $sql = "insert into dedup.query_lookup_log(qll_query, qll_result, qll_timestamp, qll_comment) values(" . $dbw->addQuotes($query) . "," . $dbw->addQuotes("exception") . "," . $dbw->addQuotes(wfTimestampNow()) . "," . $dbw->addQuotes($ex->getMessage()) . ")";
         $dbw->query($sql, __METHOD__);
     }
 }
Example #12
0
function handleOAuthBodyPOST($oauth_consumer_key, $oauth_consumer_secret) 
{
    $request_headers = OAuthUtil::get_headers();
    // print_r($request_headers);

    // Must reject application/x-www-form-urlencoded
    if ($request_headers['Content-type'] == 'application/x-www-form-urlencoded' ) {
        throw new Exception("OAuth request body signing must not use application/x-www-form-urlencoded");
    }

    if (@substr($request_headers['Authorization'], 0, 6) == "OAuth ") {
        $header_parameters = OAuthUtil::split_header($request_headers['Authorization']);

        // echo("HEADER PARMS=\n");
        // print_r($header_parameters);
        $oauth_body_hash = $header_parameters['oauth_body_hash'];
        // echo("OBH=".$oauth_body_hash."\n");
    }

    if ( ! isset($oauth_body_hash)  ) {
        throw new Exception("OAuth request body signing requires oauth_body_hash body");
    }

    // Verify the message signature
    $store = new TrivialOAuthDataStore();
    $store->add_consumer($oauth_consumer_key, $oauth_consumer_secret);

    $server = new OAuthServer($store);

    $method = new OAuthSignatureMethod_HMAC_SHA1();
    $server->add_signature_method($method);
    $request = OAuthRequest::from_request();

    global $LastOAuthBodyBaseString;
    $LastOAuthBodyBaseString = $request->get_signature_base_string();
    // echo($LastOAuthBodyBaseString."\n");

    try {
        $server->verify_request($request);
    } catch (Exception $e) {
        $message = $e->getMessage();
        throw new Exception("OAuth signature failed: " . $message);
    }

    $postdata = file_get_contents('php://input');
    // echo($postdata);

    $hash = base64_encode(sha1($postdata, TRUE));

    if ( $hash != $oauth_body_hash ) {
        throw new Exception("OAuth oauth_body_hash mismatch");
    }

    return $postdata;
}
Example #13
0
 function requestToken($callback = null)
 {
     $parameters = array('scope' => 'read_public');
     if ($callback) {
         $this->redirect_uri = $parameters['oauth_callback'] = $callback;
     }
     $request = $this->signedRequest($this->request_token_url, $this->request_token_method, $parameters);
     $token = OAuthUtil::parse_parameters($request);
     $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
 }
 function getAccessToken($oauth_verifier = FALSE)
 {
     $parameters = array();
     if (!empty($oauth_verifier)) {
         $parameters['oauth_verifier'] = $oauth_verifier;
     }
     $request = $this->oAuthRequest($this->accessTokenURL(), 'GET', $parameters);
     $token = OAuthUtil::parse_parameters($request);
     $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
 }
 function get_access_token($username, $password)
 {
     $parameters = array();
     $parameters['x_auth_username'] = $username;
     $parameters['x_auth_password'] = $password;
     $parameters['x_auth_mode'] = 'client_auth';
     $request = $this->oAuthRequest($this->host . "oauth/access_token", 'POST', $parameters);
     $token = OAuthUtil::parse_parameters($request);
     $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
 }
Example #16
0
 function post($url, $params = array(), $multi = false)
 {
     $query = "";
     if ($multi) {
         $query = OAuthUtil::build_http_query_multi($params);
     } else {
         $query = OAuthUtil::build_http_query($params);
     }
     $response = $this->http($url, 'POST', $query, $multi);
     return $response;
 }
 /**
  * gets the request token for the first time
  */
 function getRequestToken($oauth_callback = NULL)
 {
     $params = array();
     if (!empty($oauth_callback)) {
         $params['oauth_callback'] = $oauth_callback;
     }
     $request = $this->makeRequest($this->requestTokenURL, false, $params);
     $token = OAuthUtil::parse_parameters($request);
     $this->token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
 }
Example #18
0
function api_content(&$a)
{
    if ($a->cmd == 'api/oauth/authorize') {
        /* 
         * api/oauth/authorize interact with the user. return a standard page
         */
        $a->page['template'] = "minimal";
        // get consumer/client from request token
        try {
            $request = OAuthRequest::from_request();
        } catch (Exception $e) {
            echo "<pre>";
            var_dump($e);
            killme();
        }
        if (x($_POST, 'oauth_yes')) {
            $app = oauth_get_client($request);
            if (is_null($app)) {
                return "Invalid request. Unknown token.";
            }
            $consumer = new OAuthConsumer($app['client_id'], $app['pw'], $app['redirect_uri']);
            $verifier = md5($app['secret'] . local_channel());
            set_config("oauth", $verifier, local_channel());
            if ($consumer->callback_url != null) {
                $params = $request->get_parameters();
                $glue = "?";
                if (strstr($consumer->callback_url, $glue)) {
                    $glue = "?";
                }
                goaway($consumer->callback_url . $glue . "oauth_token=" . OAuthUtil::urlencode_rfc3986($params['oauth_token']) . "&oauth_verifier=" . OAuthUtil::urlencode_rfc3986($verifier));
                killme();
            }
            $tpl = get_markup_template("oauth_authorize_done.tpl");
            $o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$info' => t('Return to your app and insert this Securty Code:'), '$code' => $verifier));
            return $o;
        }
        if (!local_channel()) {
            //TODO: we need login form to redirect to this page
            notice(t('Please login to continue.') . EOL);
            return login(false, 'api-login', $request->get_parameters());
        }
        //FKOAuth1::loginUser(4);
        $app = oauth_get_client($request);
        if (is_null($app)) {
            return "Invalid request. Unknown token.";
        }
        $tpl = get_markup_template('oauth_authorize.tpl');
        $o = replace_macros($tpl, array('$title' => t('Authorize application connection'), '$app' => $app, '$authorize' => t('Do you want to authorize this application to access your posts and contacts, and/or create new posts for you?'), '$yes' => t('Yes'), '$no' => t('No')));
        //echo "<pre>"; var_dump($app); killme();
        return $o;
    }
    echo api_call($a);
    killme();
}
Example #19
0
 public function getAccessToken($verifier = false)
 {
     $params = array();
     if (!empty($verifier)) {
         $params['oauth_verifier'] = $verifier;
     }
     $response = $this->_request($this->_accessTokenUrl, 'GET', $params);
     $token = OAuthUtil::parse_parameters($response);
     $this->_token = new OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']);
     return $token;
 }
Example #20
0
	/**
   * Get the authorize URL
   *
   * @returns a string
   */
  function getAuthorizeURL($response_type, $scope=null, $state=null, $display=null) {
    $params = array(
    	'client_id' => $this->client_id,
    	'response_type' => $response_type,
    	'redirect_uri' => $this->redirect_uri,
    );
    if(!empty($scope))	$params['scope'] = $scope;
    if(!empty($state))	$params['state'] = $state;
    if(!empty($display))	$params['display'] = $display;
  	$query = OAuthUtil::build_http_query($params);
	return $this->authorizeURL . "?{$query}";  
  }
 public function userInfo()
 {
     $recinfo = Openbiz::$app->getSessionContext()->getVar($this->type . '_access_token');
     $postfields = array('access_token' => $recinfo['oauth_token'], 'format' => 'json');
     $user = json_decode(OAuthUtil::Curl_Post($this->userUrl, $postfields), true);
     if (!$user) {
         return false;
     }
     $user['id'] = $user['userid'];
     $user['type'] = $this->type;
     $user['uname'] = $user['username'] . $this->suffix;
     return $user;
 }
 public function geocode($location = FALSE)
 {
     $args = $this->args();
     $request = $this->authorize($args);
     $url = sprintf("%s?%s", $this->baseUrl, OAuthUtil::build_http_query($args));
     $ch = curl_init();
     $headers = array($request->to_header());
     curl_setopt($ch, CURLOPT_ENCODING, "gzip");
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     return curl_exec($ch);
 }
 public function build_signature($request, $consumer, $token)
 {
     $sig = array(OAuthUtil::urlencode_rfc3986($consumer->secret));
     if ($token) {
         array_push($sig, OAuthUtil::urlencode_rfc3986($token->secret));
     } else {
         array_push($sig, '');
     }
     $raw = implode("&", $sig);
     // for debug purposes
     $request->base_string = $raw;
     return OAuthUtil::urlencode_rfc3986($raw);
 }
 public function build_signature($request, $consumer, $token)
 {
     $base_string = $request->get_signature_base_string();
     $base_string = preg_replace_callback("/(%[A-Za-z0-9]{2})/", array($this, "replace_callback"), $base_string);
     //convert base string to lowercase
     $request->base_string = $base_string;
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
     $key = preg_replace_callback("/(%[A-Za-z0-9]{2})/", array($this, "replace_callback"), $key);
     //convert to lowercase
     return base64_encode(hash_hmac('sha1', $base_string, $key, true));
 }
 public function makeSignedRequest($url, $fields)
 {
     if (isset($this->access_token)) {
         $params = array("nk_token" => $this->access_token, "fields" => $fields);
         $consumer = new OAuthConsumer($this->client_id, $this->client_secret);
         $req = OAuthRequest::from_consumer_and_token($consumer, null, 'GET', $url, $params);
         $req->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, null);
         $auth_header = $req->to_header();
         $options['headers'] = array($auth_header, 'Content-Type: application/json');
         $url = $url . "?" . OAuthUtil::build_http_query($params);
         return $this->makeRequest($url, $options);
     }
 }
 public function build_signature($request, $consumer, $token)
 {
     global $OAuth_last_computed_signature;
     $OAuth_last_computed_signature = false;
     $base_string = $request->get_signature_base_string();
     $request->base_string = $base_string;
     $key_parts = array($consumer->secret, $token ? $token->secret : "");
     $key_parts = OAuthUtil::urlencode_rfc3986($key_parts);
     $key = implode('&', $key_parts);
     $computed_signature = base64_encode(hash_hmac('sha256', $base_string, $key, true));
     $OAuth_last_computed_signature = $computed_signature;
     return $computed_signature;
 }
 public function executeAuthorizeToken(sfWebRequest $request)
 {
     $this->token = $request->getParameter('oauth_token');
     $this->information = $this->getTokenTable()->findByKeyString($this->token);
     $this->forward404Unless($this->information);
     if ($request->isMethod(sfWebRequest::POST)) {
         $url = $this->information->getCallbackUrl();
         $params = array('oauth_token' => $this->token, 'oauth_verifier' => $this->information->getVerifier());
         $query = (false === strpos($url, '?') ? '?' : '&') . OAuthUtil::build_http_query($params);
         $this->information->setIsActive(true);
         $this->information->save();
         $this->redirectUnless('oob' === $url, $url . $query);
         return sfView::SUCCESS;
     }
     return sfView::INPUT;
 }
Example #28
0
 function callback()
 {
     //请求参数
     $postfields = array('grant_type' => 'authorization_code', 'client_id' => $this->akey, 'client_secret' => $this->skey, 'code' => $_REQUEST['code'], 'redirect_uri' => $this->callBack);
     $token = json_decode(OAuthUtil::Curl_Post($this->tokenUrl, $postfields), true);
     if ($token['access_token']) {
         $recinfo['oauth_token'] = $token['access_token'];
         $recinfo['oauth_token_secret'] = '';
         $recinfo['access_token_json'] = $token;
         Openbiz::$app->getSessionContext()->setVar('alitao_access_token', $recinfo);
         $userInfo = $this->userInfo();
         $this->check($userInfo);
     } else {
         throw new Exception('验证非法!');
         return false;
     }
 }
Example #29
0
 public static function fetchQueryFromYBoss($row)
 {
     $query = self::makeHowToQuery($row[KeywordIdeasCSV::KEY_KEYWORD]);
     if (empty($query)) {
         return;
     }
     $cc_key = WH_YAHOO_BOSS_API_KEY;
     $cc_secret = WH_YAHOO_BOSS_API_SECRET;
     $url = "http://yboss.yahooapis.com/ysearch/web";
     $args = array();
     $args["q"] = $query;
     $args["format"] = "json";
     $consumer = new OAuthConsumer($cc_key, $cc_secret);
     $request = OAuthRequest::from_consumer_and_token($consumer, NULL, "GET", $url, $args);
     $request->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, NULL);
     $url = sprintf("%s?%s", $url, OAuthUtil::build_http_query($args));
     $ch = curl_init();
     $headers = array($request->to_header());
     curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
     curl_setopt($ch, CURLOPT_URL, $url);
     curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
     $rsp = curl_exec($ch);
     $results = json_decode($rsp);
     $totalResults = 0;
     if ($results->bossresponse->responsecode == 200) {
         $totalResults = $results->bossresponse->web->totalresults;
         $titles = array();
         foreach ($results->bossresponse->web->results as $idx => $result) {
             $title = self::getShortTitle($result->title);
             if (self::isHowToResult($title) == 1) {
                 $csvRow = array();
                 $csvRow[self::KEY_POS_IN_RESULTS] = $idx;
                 $csvRow[self::KEY_ORIG_TITLE] = $result->title;
                 $csvRow[self::KEY_SHORT_TITLE] = $result->title;
                 $csvRow[self::KEY_SHORT_TITLE] = $title;
                 $csvRow[self::KEY_SITE] = self::getDomain($result->url);
                 $csvRow[self::KEY_URL] = $result->url;
                 $titles[] = $csvRow;
             }
         }
     } else {
         $err = "Error in fetching reults from boss for kw=[{$query}]. Resp code = " . $results->bossresponse->responsecode . "<br>\n";
     }
     return array($err, $totalResults, $titles);
 }
Example #30
0
 /**
  * リクエストトークンの取得方法サンプル
  */
 function howToGetRequestToken()
 {
     //
     // Google Data APIを利用する場合には"scope"パラメータが必須
     // 参考:http://code.google.com/intl/ja/apis/accounts/docs/OAuth_ref.html#RequestToken
     // 参考:http://code.google.com/intl/ja/apis/gdata/faq.html#AuthScopes
     //
     $additional_param = array('scope' => 'https://www.google.com/calendar/feeds/');
     //
     // request tokenを取得
     //
     $req_token = OAuthWrapUtil::get_request_token($this->target_consumer, $additional_param);
     print $req_token . "\n";
     //
     // user authorizatio url
     //
     $auth_url = OAuthWrapUtil::get_user_authorization_url($this->target_consumer);
     print $auth_url . '?' . OAuthUtil::build_http_query(array('oauth_token' => $req_token->key)) . "\n";
 }