/** * Generate a signed hash of the base string using the consumer and * token * as the signing key. * * $sig = $signature->sign($request, $consumer, $token); * * [!!] This method implements [OAuth 1.0 Spec 9.2.1](http://oauth.net/core/1.0/#rfc.section.9.2.1). * * @param Request request * @param Consumer consumer * @param Token token * @return string * @uses Signature::key * @uses Request::base_string */ public function sign(Request $request, Consumer $consumer, Token $token = null) { // Get the signing key $key = $this->key($consumer, $token); // Get the base string for the signature $base_string = $request->base_string(); // Sign the base string using the key return base64_encode(hash_hmac('sha1', $base_string, $key, true)); }
public function get_user_info(Token $token, Consumer $consumer) { // Create a new GET request with the required parameters $request = Request::make('resource', 'GET', 'http://api.flickr.com/services/rest', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token, 'nojsoncallback' => 1, 'format' => 'json', 'method' => 'flickr.test.login')); // Sign the request using the consumer and token $request->sign($this->signature, $consumer, $token); $response = json_decode($request->execute(), true); // Create a response from the request return array('uid' => array_get($response, 'user.id'), 'name' => array_get($response, 'user.username._content'), 'nickname' => array_get($response, 'user.username._content')); }
public function get_user_info(Token $token, Consumer $consumer) { // Create a new GET request with the required parameters $request = Request::make('resource', 'GET', 'https://api.twitter.com/1.1/users/lookup.json', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token, 'user_id' => $token->uid)); // Sign the request using the consumer and token $request->sign($this->signature, $consumer, $token); $user = current(json_decode($request->execute())); // Create a response from the request return array('uid' => $token->uid, 'nickname' => $user->screen_name, 'name' => $user->name ?: $user->screen_name, 'location' => $user->location, 'image' => $user->profile_image_url, 'description' => $user->description, 'urls' => array('website' => $user->url, 'twitter' => 'https://twitter.com/' . $user->screen_name)); }
public function get_user_info(Token $token, Consumer $consumer) { // Create a new GET request with the required parameters $request = Request::make('resource', 'GET', 'https://api.dropbox.com/1/account/info', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token)); // Sign the request using the consumer and token $request->sign($this->signature, $consumer, $token); $user = json_decode($request->execute()); // Create a response from the request return array('uid' => $token->uid, 'name' => $user->display_name, 'location' => $user->country); }
public function get_user_info(Token $token, Consumer $consumer) { // Create a new GET request with the required parameters $request = Request::make('resource', 'GET', 'http://vimeo.com/api/rest/v2/', array('method' => 'vimeo.people.getInfo', 'oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token, 'format' => 'json')); // Sign the request using the consumer and token $request->sign($this->signature, $consumer, $token); $response = json_decode($request->execute()); $user = $response->person; $profile_image = end($user->portraits->portrait); $url = current($user->url); // Create a response from the request return array('uid' => $user->id, 'nickname' => $user->username, 'name' => $user->display_name ?: $user->username, 'location' => $user->location, 'image' => $profile_image->_content, 'description' => $user->bio, 'urls' => array('website' => $url, 'vimeo' => $user->profileurl)); }
public function get_user_info(Token $token, Consumer $consumer) { // Create a new GET request with the required parameters $request = Request::make('resource', 'GET', 'http://api.tumblr.com/v2/user/info', array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token)); // Sign the request using the consumer and token $request->sign($this->signature, $consumer, $token); $response = json_decode($request->execute()); $status = current($response); $response = next($response); $user = $response->user; // Create a response from the request return array('uid' => $user->name, 'name' => $user->name, 'likes' => $user->likes, 'following' => $user->following, 'default_post_format' => $user->default_post_format); }
public function get_user_info(Token $token, Consumer $consumer) { // Create a new GET request with the required parameters $url = 'https://api.linkedin.com/v1/people/~:(id,first-name,last-name,headline,member-url-resources,picture-url,location,public-profile-url)?format=json'; $request = Request::make('resource', 'GET', $url, array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token)); // Sign the request using the consumer and token $request->sign($this->signature, $consumer, $token); $user = json_decode($request->execute(), true); $nickname = null; // Split the profile url to get the user's nickname if ($linked_url = array_get($user, 'publicProfileUrl')) { $profile_nickname = explode('/', $linked_url); $nickname = end($profile_nickname); } // Create a response from the request return array('uid' => array_get($user, 'id'), 'name' => array_get($user, 'firstName') . ' ' . array_get($user, 'lastName'), 'image' => array_get($user, 'pictureUrl'), 'nickname' => $nickname, 'description' => array_get($user, 'headline'), 'location' => array_get($user, 'location.name'), 'urls' => array('linkedin' => $linked_url)); }
public function execute(array $options = null) { return OAuth_Response::make(parent::execute($options)); }
/** * Exchange the request token for an access token. * * $token = $provider->access_token($consumer, $token); * * @param Consumer consumer * @param Token_Request token * @param array additional request parameters * @return Token_Access */ public function access_token(Token\Request $token, Consumer $consumer, array $params = null) { // Create a new GET request for a request token with the required // parameters $request = Request::make('access', 'GET', $this->url_access_token(), array('oauth_consumer_key' => $consumer->key, 'oauth_token' => $token->access_token, 'oauth_verifier' => $token->verifier)); if ($params) { // Load user parameters $request->params($params); } // Sign the request using only the consumer, no token is available // yet $request->sign($this->signature, $consumer, $token); // Create a response from the request $response = $request->execute(); // Store this token somewhere useful return Token::make('access', array('access_token' => $response->param('oauth_token'), 'secret' => $response->param('oauth_token_secret'), 'uid' => $response->param($this->uid_key) ?: Input::get($this->uid_key))); }
/** * Execute the request and return a response. * * @param array additional cURL options * @return string request response body * @uses array_get * @uses Core::remote */ public function execute(array $options = null) { // Check that all required fields are set $this->check(); // Get the URL of the request $url = $this->url; if (!isset($options[CURLOPT_CONNECTTIMEOUT])) { // Use the request default timeout $options[CURLOPT_CONNECTTIMEOUT] = $this->timeout; } if (\Request::env() === 'local') { $options[CURLOPT_SSL_VERIFYPEER] = false; } if ($this->send_header) { // Get the the current headers $headers = array_get($options, CURLOPT_HTTPHEADER, array()); // Add the Authorization header $headers[] = 'Authorization: ' . $this->as_header(); // Store the new headers $options[CURLOPT_HTTPHEADER] = $headers; } if ($this->method === 'POST') { // Send the request as a POST $options[CURLOPT_POST] = true; if ($post = $this->as_query(null, empty($this->upload))) { // Attach the post fields to the request $options[CURLOPT_POSTFIELDS] = $post; } } elseif ($query = $this->as_query()) { // Append the parameters to the query string $url = "{$url}?{$query}"; } return Core::remote($url, $options); }