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


PHP OAuthRequest类代码示例

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


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

示例1: request

 function request($command, $args = array())
 {
     // NOTE: cache not implemented
     $args = array_merge(array("url" => $this->rest_endpoint, "method" => $command, "format" => "json", "nojsoncallback" => "1"), $args);
     $request = new OAuthRequest(Verb::POST, $args['url']);
     foreach ($args as $key => $value) {
         $request->addBodyParameter($key, $value);
     }
     $this->oauth_service->signRequest($this->token, $request);
     $response_object = $request->send();
     $response = $response_object->getBody();
     $this->parsed_response = json_decode($response, TRUE);
     if ($this->parsed_response['stat'] == 'fail') {
         if ($this->die_on_error) {
             die("The Flickr API returned the following error: #{$this->parsed_response['code']} - {$this->parsed_response['message']}");
         } else {
             $this->error_code = $this->parsed_response['code'];
             $this->error_msg = $this->parsed_response['message'];
             $this->parsed_response = false;
         }
     } else {
         $this->error_code = false;
         $this->error_msg = false;
     }
     return $response;
 }
开发者ID:spacelama,项目名称:Offlickr2,代码行数:26,代码来源:oPhpFlickr.php

示例2: __construct

 /**
  * Construct the request to be verified
  * 
  * @param string request
  * @param string method
  */
 function __construct($uri = null, $method = 'GET')
 {
     $this->store = elggconnect_get_oauth_store();
     //OAuthStore::instance();
     parent::__construct($uri, $method);
     OAuthRequestLogger::start($this);
 }
开发者ID:redvabel,项目名称:Vabelgg,代码行数:13,代码来源:OAuthRequestVerifier.php

示例3: build_request

 /**
  * Populates $_{SERVER,GET,POST} and whatever environment-variables needed to test everything..
  *
  * @param string $method GET or POST
  * @param string $uri What URI is the request to (eg http://example.com/foo?bar=baz)
  * @param string $post_data What should the post-data be
  * @param string $auth_header What to set the Authorization header to
  */
 public static function build_request($method, $uri, $post_data = '', $auth_header = '')
 {
     self::reset_request_vars();
     $method = strtoupper($method);
     $parts = parse_url($uri);
     $port = @$parts['port'];
     $scheme = $parts['scheme'];
     $host = $parts['host'];
     $path = @$parts['path'];
     $query = @$parts['query'];
     $port or $port = $scheme == 'https' ? '443' : '80';
     if ($scheme == 'https') {
         $_SERVER['HTTPS'] = 'on';
     }
     $_SERVER['REQUEST_METHOD'] = $method;
     $_SERVER['HTTP_HOST'] = $host;
     $_SERVER['SERVER_PORT'] = $port;
     $_SERVER['SCRIPT_NAME'] = $path;
     $_SERVER['REQUEST_URI'] = $path . '?' . $query;
     $_SERVER['QUERY_STRING'] = $query . '';
     parse_str($query, $_GET);
     if ($method == 'POST') {
         $_SERVER['HTTP_CONTENT_TYPE'] = 'application/x-www-form-urlencoded';
         $_POST = parse_str($post_data);
         OAuthRequest::$POST_INPUT = 'data:application/x-www-form-urlencoded,' . $post_data;
     }
     if ($auth_header != '') {
         $_SERVER['HTTP_AUTHORIZATION'] = $auth_header;
     }
 }
开发者ID:edmarmoretti,项目名称:i3geo,代码行数:38,代码来源:common.php

示例4: sendOAuthBodyPOST

function sendOAuthBodyPOST($method, $endpoint, $oauth_consumer_key, $oauth_consumer_secret, $content_type, $body)
{
    $hash = base64_encode(sha1($body, TRUE));
    $parms = array('oauth_body_hash' => $hash);
    $test_token = '';
    $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
    $test_consumer = new OAuthConsumer($oauth_consumer_key, $oauth_consumer_secret, NULL);
    $acc_req = OAuthRequest::from_consumer_and_token($test_consumer, $test_token, $method, $endpoint, $parms);
    $acc_req->sign_request($hmac_method, $test_consumer, $test_token);
    // Pass this back up "out of band" for debugging
    global $LastOAuthBodyBaseString;
    $LastOAuthBodyBaseString = $acc_req->get_signature_base_string();
    // echo($LastOAuthBodyBaseString."\m");
    $header = $acc_req->to_header();
    $header = $header . "\r\nContent-type: " . $content_type . "\r\n";
    $params = array('http' => array('method' => 'POST', 'content' => $body, 'header' => $header));
    try {
        $ctx = stream_context_create($params);
        $fp = @fopen($endpoint, 'rb', false, $ctx);
    } catch (Exception $e) {
        $fp = false;
    }
    if ($fp) {
        $response = @stream_get_contents($fp);
    } else {
        // Try CURL
        $headers = explode("\r\n", $header);
        $response = sendXmlOverPost($endpoint, $body, $headers);
    }
    if ($response === false) {
        throw new Exception("Problem reading data from {$endpoint}, {$php_errormsg}");
    }
    return $response;
}
开发者ID:ramanuv,项目名称:kennethware-2.0,代码行数:34,代码来源:OAuthBody.php

示例5: request

/**
 * Makes a request to the Yelp API and returns the response
 *
 * @param    $host    The domain host of the API
 * @param    $path    The path of the APi after the domain
 * @return   The JSON response from the request
 */
function request($host, $path) {
    $unsigned_url = "http://" . $host . $path;

    // Token object built using the OAuth library
    $token = new OAuthToken($GLOBALS['TOKEN'], $GLOBALS['TOKEN_SECRET']);

    // Consumer object built using the OAuth library
    $consumer = new OAuthConsumer($GLOBALS['CONSUMER_KEY'], $GLOBALS['CONSUMER_SECRET']);

    // Yelp uses HMAC SHA1 encoding
    $signature_method = new OAuthSignatureMethod_HMAC_SHA1();

    $oauthrequest = OAuthRequest::from_consumer_and_token(
        $consumer,
        $token,
        'GET',
        $unsigned_url
    );

    // Sign the request
    $oauthrequest->sign_request($signature_method, $consumer, $token);

    // Get the signed URL
    $signed_url = $oauthrequest->to_url();

    // Send Yelp API Call
    $ch = curl_init($signed_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $data = curl_exec($ch);
    curl_close($ch);

    return $data;
}
开发者ID:supermanrising,项目名称:virtual-photo-walks,代码行数:41,代码来源:request.php

示例6: newRequestMessage

 /**
  * @return OAuthRequest
  */
 public function newRequestMessage($method, $url, $parameters)
 {
     if (!isset($method)) {
         $method = $this->getProperty("httpMethod");
         if ($method == null) {
             $method = $this->consumer->getProperty("httpMethod");
             if ($method == null) {
                 $method = "GET";
             }
         }
     }
     $message = OAuthRequest::from_consumer_and_token($this->consumer, $this->accessToken, $method, $url, $parameters);
     $signatureMethod = null;
     if ($parameters[OAuth::$OAUTH_SIGNATURE_METHOD] == OAuth::$RSA_SHA1) {
         $signatureMethod = new OAuthSignatureMethod_RSA_SHA1();
     } else {
         if ($parameters[OAuth::$OAUTH_SIGNATURE_METHOD] == OAuth::$HMAC_SHA1) {
             $signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
         } else {
             //PLAINTEXT
             $signatureMethod = new OAuthSignatureMethod_PLAINTEXT();
         }
     }
     $message->sign_request($signatureMethod, $this->consumer, $this->tokenSecret);
     return $message;
 }
开发者ID:emma5021,项目名称:toba,代码行数:29,代码来源:OAuthAccessor.php

示例7: sign

 /**
  * Sign the request using OAuth. This uses the consumer token and key
  * but 2 legged oauth doesn't require an access token and key. In situations where you want to
  * do a 'reverse phone home' (aka: gadget does a makeRequest to your server
  * and your server wants to retrieve more social information) this is the prefered
  * method.
  *
  * @param string $method the method (get/put/delete/post)
  * @param string $url the url to sign (http://site/social/rest/people/1/@me)
  * @param array $params the params that should be appended to the url (count=20 fields=foo, etc)
  * @param string $postBody for POST/PUT requests, the postBody is included in the signature
  * @return string the signed url
  */
 public function sign($method, $url, $params = array(), $postBody = false, &$headers = array())
 {
     $oauthRequest = OAuthRequest::from_request($method, $url, $params);
     $params = $this->mergeParameters($params);
     foreach ($params as $key => $val) {
         if (is_array($val)) {
             $val = implode(',', $val);
         }
         $oauthRequest->set_parameter($key, $val);
     }
     if ($postBody && strlen($postBody)) {
         if ($this->useBodyHash) {
             $bodyHash = base64_encode(sha1($postBody, true));
             $oauthRequest->set_parameter("oauth_body_hash", $bodyHash);
         }
         if ($this->useBodyHack) {
             $oauthRequest->set_parameter($postBody, '');
         }
     }
     $oauthRequest->sign_request($this->signatureMethod, $this->consumerToken, $this->accessToken);
     if ($postBody && $this->useBodyHack) {
         unset($oauthRequest->parameters[$postBody]);
     }
     $signedUrl = $oauthRequest->to_url();
     return $signedUrl;
 }
开发者ID:nrajput,项目名称:widgetJs,代码行数:39,代码来源:osapiOAuth2Legged.php

示例8: oAuthUrl

 /**
  * Sign our target URL with OAuth auth stuff.
  *
  * @param string $url
  * @param array $params
  * @return string
  */
 protected function oAuthUrl($url, $params = array())
 {
     // In an ideal world this would be better encapsulated. :)
     $request = OAuthRequest::from_consumer_and_token($this->oauth->consumer, $this->oauth->token, 'GET', $url, $params);
     $request->sign_request($this->oauth->sha1_method, $this->oauth->consumer, $this->oauth->token);
     return $request->to_url();
 }
开发者ID:Grasia,项目名称:bolotweet,代码行数:14,代码来源:twitterstreamreader.php

示例9: sign

 /**
  * Adds a signature to the request
  *
  * @access public
  * @author Joel Bout, <joel@taotesting.com>
  * @param $authorizationHeader Move the signature parameters into the Authorization header of the request
  */
 public function sign(common_http_Request $request, common_http_Credentials $credentials, $authorizationHeader = false)
 {
     if (!$credentials instanceof tao_models_classes_oauth_Credentials) {
         throw new tao_models_classes_oauth_Exception('Invalid credentals: ' . gettype($credentials));
     }
     $oauthRequest = $this->getOauthRequest($request);
     $dataStore = new tao_models_classes_oauth_DataStore();
     $consumer = $dataStore->getOauthConsumer($credentials);
     $token = $dataStore->new_request_token($consumer);
     $allInitialParameters = array();
     $allInitialParameters = array_merge($allInitialParameters, $request->getParams());
     $allInitialParameters = array_merge($allInitialParameters, $request->getHeaders());
     //oauth_body_hash is used for the signing computation
     if ($authorizationHeader) {
         $oauth_body_hash = base64_encode(sha1($request->getBody(), true));
         //the signature should be ciomputed from encoded versions
         $allInitialParameters = array_merge($allInitialParameters, array("oauth_body_hash" => $oauth_body_hash));
     }
     //$authorizationHeader = self::buildAuthorizationHeader($signatureParameters);
     $signedRequest = OAuthRequest::from_consumer_and_token($consumer, $token, $oauthRequest->get_normalized_http_method(), $oauthRequest->getUrl(), $allInitialParameters);
     $signature_method = new OAuthSignatureMethod_HMAC_SHA1();
     //common_logger::d('Base string: '.$signedRequest->get_signature_base_string());
     $signedRequest->sign_request($signature_method, $consumer, $token);
     common_logger::d('Base string from TAO/Joel: ' . $signedRequest->get_signature_base_string());
     if ($authorizationHeader) {
         $combinedParameters = $signedRequest->get_parameters();
         $signatureParameters = array_diff_assoc($combinedParameters, $allInitialParameters);
         $signatureParameters["oauth_body_hash"] = base64_encode(sha1($request->getBody(), true));
         $signatureHeaders = array("Authorization" => self::buildAuthorizationHeader($signatureParameters));
         $signedRequest = new common_http_Request($signedRequest->getUrl(), $signedRequest->get_normalized_http_method(), $request->getParams(), array_merge($signatureHeaders, $request->getHeaders()), $request->getBody());
     } else {
         $signedRequest = new common_http_Request($signedRequest->getUrl(), $signedRequest->get_normalized_http_method(), $signedRequest->get_parameters(), $request->getHeaders(), $request->getBody());
     }
     return $signedRequest;
 }
开发者ID:nagyist,项目名称:tao-core,代码行数:42,代码来源:class.Service.php

示例10: __construct

 public function __construct($consumer, $token, $http_method, $http_url, $parameters = array())
 {
     $this->OAuthRequest = OAuthRequest::from_consumer_and_token($consumer, $token, $http_method, $http_url, $parameters);
     $this->OAuthRequest->sign_request(new OAuthSignatureMethod_HMAC_SHA1(), $consumer, $token);
     $this->method = $http_method;
     $this->parameters = is_array($parameters) ? $parameters : array($parameters);
 }
开发者ID:nise-nabe,项目名称:opCalendarPlugin,代码行数:7,代码来源:opCalendarApi.class.php

示例11: getYelp

function getYelp($term, $location)
{
    $unsigned_url = "http://api.yelp.com/v2/search?term=" . urlencode($term) . "&location=" . urlencode($location) . "&limit=1";
    // Set your keys here
    $consumer_key = "8LjXkvQ-lcUe7dSlvIHhAQ";
    $consumer_secret = "7AnAzMD4h6mthw27wT48qZFEJoo";
    $token = "B-j7tOmv_GPGzZsfc_VId-cjRMLlBcCq";
    $token_secret = "Hjq6GZOp61HR_JxUgB9_O7HpqKA";
    // Token object built using the OAuth library
    $token = new OAuthToken($token, $token_secret);
    // Consumer object built using the OAuth library
    $consumer = new OAuthConsumer($consumer_key, $consumer_secret);
    // Yelp uses HMAC SHA1 encoding
    $signature_method = new OAuthSignatureMethod_HMAC_SHA1();
    // Build OAuth Request using the OAuth PHP library. Uses the consumer and token object created above.
    $oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_url);
    // Sign the request
    $oauthrequest->sign_request($signature_method, $consumer, $token);
    // Get the signed URL
    $signed_url = $oauthrequest->to_url();
    // Send Yelp API Call
    $ch = curl_init($signed_url);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
    curl_setopt($ch, CURLOPT_HEADER, 0);
    $data = curl_exec($ch);
    // Yelp response
    curl_close($ch);
    // Handle Yelp response data
    //$response = json_decode($data);
    // Print it for debugging
    //print_r($response);
    return $data;
}
开发者ID:anirudhakarwa,项目名称:TravelSuggest,代码行数:33,代码来源:example.php

示例12: brukar_client_oauth_callback

function brukar_client_oauth_callback()
{
    require_once drupal_get_path('module', 'brukar_common') . '/OAuth.php';
    $method = new OAuthSignatureMethod_HMAC_SHA1();
    $consumer = new OAuthConsumer(variable_get('brukar_consumer_key'), variable_get('brukar_consumer_secret'));
    if (isset($_SESSION['auth_oauth']) && $_SESSION['auth_oauth']['oauth_token'] == $_GET['oauth_token']) {
        unset($_GET['oauth_token']);
        $tmp = new OAuthToken($_SESSION['auth_oauth']['oauth_token'], $_SESSION['auth_oauth']['oauth_token_secret']);
        $req = OAuthRequest::from_consumer_and_token($consumer, $tmp, 'GET', variable_get('brukar_url') . 'server/oauth/access_token', array());
        $req->sign_request($method, $consumer, $tmp);
        parse_str(trim(file_get_contents($req->to_url())), $token);
        unset($_SESSION['auth_oauth']);
        if (count($token) > 0) {
            $_SESSION['_brukar_access_token'] = array('token' => $token['oauth_token'], 'token_secret' => $token['oauth_token_secret']);
            $token = new OAuthToken($token['oauth_token'], $token['oauth_token_secret']);
            $req = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', variable_get('brukar_url') . 'server/oauth/user', array());
            $req->sign_request($method, $consumer, $token);
            brukar_client_login((array) json_decode(trim(file_get_contents($req->to_url()))));
        }
    }
    $debug_data = array('cookie' => $_COOKIE, 'request_uri' => request_uri(), 'auth_oauth' => isset($_SESSION['auth_oauth']) ? $_SESSION['auth_oauth'] : 'no auth_oauth');
    watchdog('brukar_client', 'User login failed.<br/>Debug data:<br/><pre>!debug_data</pre><br/>', array('!debug_data' => print_r($debug_data, TRUE)), WATCHDOG_ERROR);
    drupal_set_message(t('Noe gikk feil under innlogging.'), 'warning');
    drupal_goto('<front>');
}
开发者ID:evenos,项目名称:drupal7-module-brukar,代码行数:25,代码来源:brukar_client.oauth.php

示例13: user_oauth_sign

function user_oauth_sign(&$url, &$args = false)
{
    require_once 'OAuth.php';
    $method = $args !== false ? 'POST' : 'GET';
    if (preg_match_all('#[?&]([^=]+)=([^&]+)#', $url, $matches, PREG_SET_ORDER)) {
        foreach ($matches as $match) {
            $args[$match[1]] = $match[2];
        }
        $url = substr($url, 0, strpos($url, '?'));
    }
    $sig_method = new OAuthSignatureMethod_HMAC_SHA1();
    $consumer = new OAuthConsumer(OAUTH_KEY, OAUTH_SECRET);
    $token = NULL;
    if (($oauth_token = $_GET['oauth_token']) && $_SESSION['oauth_request_token_secret']) {
        $oauth_token_secret = $_SESSION['oauth_request_token_secret'];
    } else {
        list($oauth_token, $oauth_token_secret) = explode('|', $GLOBALS['user']['password']);
    }
    if ($oauth_token && $oauth_token_secret) {
        $token = new OAuthConsumer($oauth_token, $oauth_token_secret);
    }
    $request = OAuthRequest::from_consumer_and_token($consumer, $token, $method, $url, $args);
    $request->sign_request($sig_method, $consumer, $token);
    switch ($method) {
        case 'GET':
            $url = $request->to_url();
            $args = false;
            return;
        case 'POST':
            $url = $request->get_normalized_http_url();
            $args = $request->to_postdata();
            return;
    }
}
开发者ID:xctcc,项目名称:npt,代码行数:34,代码来源:user.php

示例14: get_yelp_data_for_truck

function get_yelp_data_for_truck($vendor_name, $lat, $long)
{
    // Configuration.
    $consumer_key = '';
    $consumer_secret = '';
    $token = '';
    $token_secret = '';
    // Search params.
    $params = array('term' => $vendor_name, 'category_filter' => 'foodtrucks,foodstands', 'location' => 'San Francisco, CA', 'cll' => (string) $lat . "," . (string) $long, 'limit' => 1);
    // Build the request.
    $unsigned_uri = "http://api.yelp.com/v2/search/?" . http_build_query($params);
    // Token object built using the OAuth library
    $token = new OAuthToken($token, $token_secret);
    // Consumer object built using the OAuth library
    $consumer = new OAuthConsumer($consumer_key, $consumer_secret);
    // Yelp uses HMAC SHA1 encoding
    $signature_method = new OAuthSignatureMethod_HMAC_SHA1();
    $oauthrequest = OAuthRequest::from_consumer_and_token($consumer, $token, 'GET', $unsigned_uri);
    // Sign the request
    $oauthrequest->sign_request($signature_method, $consumer, $token);
    // Get the signed URL
    $signed_url = $oauthrequest->to_url();
    $results = fetch_data($signed_url);
    // Ensure a business listing is returned and the location is not closed
    // permanently.
    if (array_key_exists("businesses", $results) && !$results["businesses"][0]["is_closed"]) {
        return $results["businesses"][0];
    }
    return null;
}
开发者ID:samgruskin,项目名称:sf-food-trucks,代码行数:30,代码来源:food_truck_data.php

示例15: immediate_update_outcome_in_canvas

function immediate_update_outcome_in_canvas($oauth_consumer_key, $secret, $lti_sourced_id, $lis_outcome_service_url, $score)
{
    set_time_limit(180);
    $xmlRequest = "<?xml version = \"1.0\" encoding = \"UTF-8\"?>\n<imsx_POXEnvelopeRequest xmlns=\"http://www.imsglobal.org/services/ltiv1p1/xsd/imsoms_v1p0\">\n    <imsx_POXHeader>\n        <imsx_POXRequestHeaderInfo>\n            <imsx_version>V1.0</imsx_version>\n            <imsx_messageIdentifier>999999123</imsx_messageIdentifier>\n        </imsx_POXRequestHeaderInfo>\n    </imsx_POXHeader>\n    <imsx_POXBody>\n        <replaceResultRequest>\n            <resultRecord>\n                <sourcedGUID>\n                    <sourcedId>{$lti_sourced_id}</sourcedId>\n                </sourcedGUID>\n                <result>\n                    <resultScore>\n                        <language>en</language>\n                        <textString>" . $score . "</textString>\n                    </resultScore>\n                </result>\n            </resultRecord>\n        </replaceResultRequest>\n    </imsx_POXBody>\n</imsx_POXEnvelopeRequest>";
    $hash = base64_encode(sha1($xmlRequest, TRUE));
    $params = array('oauth_body_hash' => $hash);
    $hmac_method = new OAuthSignatureMethod_HMAC_SHA1();
    $consumer = new OAuthConsumer($oauth_consumer_key, $secret, NULL);
    $req = OAuthRequest::from_consumer_and_token($consumer, NULL, 'POST', $lis_outcome_service_url, $params);
    $req->sign_request($hmac_method, $consumer, NULL);
    $params = $req->get_parameters();
    $header = $req->to_header();
    $header .= "\nContent-type: application/xml";
    $ext_response = do_post_request($lis_outcome_service_url, $xmlRequest, $header);
    $ext_doc = new DOMDocument();
    set_error_handler(array($this, 'HandleXmlError'));
    $ext_doc->loadXML($ext_response);
    restore_error_handler();
    $ext_nodes = domnode_to_array($ext_doc->documentElement);
    if (!isset($ext_nodes['imsx_POXHeader']['imsx_POXResponseHeaderInfo']['imsx_statusInfo']['imsx_codeMajor'])) {
        throw new Exception("No imsx_codeMajor from outcome service for " . $lti_sourced_id);
    }
    if ($ext_nodes['imsx_POXHeader']['imsx_POXResponseHeaderInfo']['imsx_statusInfo']['imsx_codeMajor'] != 'success' && isset($ext_nodes['imsx_POXHeader']['imsx_POXResponseHeaderInfo']['imsx_statusInfo']['imsx_description']) && $ext_nodes['imsx_POXHeader']['imsx_POXResponseHeaderInfo']['imsx_statusInfo']['imsx_description'] != 'User is no longer in course') {
        throw new Exception("No success code from outcome service for " . $lti_sourced_id);
    }
}
开发者ID:ryanboyd,项目名称:2015fall-psy301-writing-assn,代码行数:26,代码来源:process2.php


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