当前位置: 首页>>代码示例>>PHP>>正文


PHP OAuthUtil类代码示例

本文整理汇总了PHP中OAuthUtil的典型用法代码示例。如果您正苦于以下问题:PHP OAuthUtil类的具体用法?PHP OAuthUtil怎么用?PHP OAuthUtil使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了OAuthUtil类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: build_http_body

 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);
 }
开发者ID:nachoruiz29,项目名称:javascript-api-samples,代码行数:30,代码来源:OAuthUtil.php

示例2: getPostvals

 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;
 }
开发者ID:nise-nabe,项目名称:opCalendarPlugin,代码行数:32,代码来源:opCalendarApi.class.php

示例3: getAccessToken

 /**
  * (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;
 }
开发者ID:ner0tic,项目名称:scss,代码行数:38,代码来源:sfOAuth2.class.php

示例4: http

 /**
  * @see TwitterOAuth::http()
  * @author Naomichi Yamakita <yamakita@dtx.co.jp>
  */
 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();
 }
开发者ID:naomichi-y,项目名称:mars_plugin,代码行数:33,代码来源:Mars_TwitterOAuth.class.php

示例5: getAccessToken

 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);
 }
开发者ID:rintaun,项目名称:oauth-consumer-component,代码行数:8,代码来源:oauth_consumer.php

示例6: build_signature

 /**
  * 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;
 }
开发者ID:EHER,项目名称:chegamos,代码行数:17,代码来源:OAuthSignatureMethod_PLAINTEXT.php

示例7: build_signature

 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));
 }
开发者ID:Nivl,项目名称:Ninaca_1,代码行数:9,代码来源:OAuthSignatureMethod_HMAC_SHA1.class.php

示例8: getTokenStringFromRequest

 /**
  * 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;
 }
开发者ID:newlongwhitecloudy,项目名称:OpenConext-engineblock,代码行数:13,代码来源:BasicSecurityToken.php

示例9: testGetHeaders

 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());
 }
开发者ID:srouthiau,项目名称:oauth,代码行数:9,代码来源:OAuthUtilTest.php

示例10: execute

 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;
 }
开发者ID:kenyonjohnston,项目名称:hott_theater,代码行数:56,代码来源:NetDNA.php

示例11: fetchQuery

 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__);
     }
 }
开发者ID:biribogos,项目名称:wikihow-src,代码行数:56,代码来源:dedupQuery.php

示例12: handleOAuthBodyPOST

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;
}
开发者ID:anilch,项目名称:Personel,代码行数:55,代码来源:OAuthBody.php

示例13: requestToken

 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;
 }
开发者ID:Quang2727,项目名称:Kaopass,代码行数:11,代码来源:Hatena.php

示例14: getAccessToken

 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;
 }
开发者ID:vinayshuklasourcefuse,项目名称:sareez,代码行数:11,代码来源:linkedinoauth.php

示例15: get_access_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;
 }
开发者ID:randyhoyt,项目名称:InstapaperOAuth,代码行数:11,代码来源:InstapaperOAuth.php


注:本文中的OAuthUtil类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。