/** * Get a signing key from a consumer and token. * * $key = $signature->key($consumer, $token); * * [!!] This method implements the signing key of [OAuth 1.0 Spec 9](http://oauth.net/core/1.0/#rfc.section.9). * * @param Consumer consumer * @param Token token * @return string * @uses OAuth1::urlencode */ public function key(OAuth_Consumer $consumer, OAuth_Token $token = NULL) { $key = OAuth1::urlencode($consumer->secret) . '&'; if ($token) { $key .= OAuth1::urlencode($token->secret); } return $key; }
/** * Performs OAuth1 auth flow. * @param OAuth1 $client auth client instance. * @return Response action response. */ protected function authOAuth1($client) { // user denied error if (isset($_GET['denied'])) { return $this->redirectCancel(); } if (isset($_REQUEST['oauth_token'])) { $oauthToken = $_REQUEST['oauth_token']; } if (!isset($oauthToken)) { // Get request token. $requestToken = $client->fetchRequestToken(); // Get authorization URL. $url = $client->buildAuthUrl($requestToken); // Redirect to authorization URL. return Yii::$app->getResponse()->redirect($url); } else { // Upgrade to access token. $client->fetchAccessToken(); return $this->authSuccess($client); } }
public function __construct($body = NULL) { if ($body) { $this->params = OAuth1::parse_params($body); } }
/** * Execute the request and return a response. * * @param array additional cURL options * @return string request response body * @uses Request::check * @uses Arr::get * @uses Remote::get */ 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 (EXTERNAL_API_PROXY) { $options[CURLOPT_PROXYPORT] = EXTERNAL_API_PROXY_PORT; $options[CURLOPT_PROXYTYPE] = 'http'; $options[CURLOPT_PROXY] = EXTERNAL_API_PROXY_URL; } if (!isset($options[CURLOPT_CONNECTTIMEOUT])) { // Use the request default timeout $options[CURLOPT_CONNECTTIMEOUT] = $this->timeout; } if (ENVIRONMENT === 'development') { $options[CURLOPT_SSL_VERIFYPEER] = false; } if ($this->send_header) { // Get the the current headers $headers = isset($options[CURLOPT_HTTPHEADER]) ? $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 OAuth1::remote($url, $options); }
/** * Parse the parameters in a string and return an array. Duplicates are * converted into indexed arrays. * * // Parsed: array('a' => '1', 'b' => '2', 'c' => '3') * $params = OAuth1::parse_params('a=1,b=2,c=3'); * * // Parsed: array('a' => array('1', '2'), 'c' => '3') * $params = OAuth1::parse_params('a=1,a=2,c=3'); * * @param string parameter string * @return array */ public static function parse_params($params) { // Split the parameters by & $params = explode('&', trim($params)); // Create an array of parsed parameters $parsed = array(); foreach ($params as $param) { // Split the parameter into name and value list($name, $value) = explode('=', $param, 2); // Decode the name and value $name = OAuth1::urldecode($name); $value = OAuth1::urldecode($value); if (isset($parsed[$name])) { if (!is_array($parsed[$name])) { // Convert the parameter to an array $parsed[$name] = array($parsed[$name]); } // Add a new duplicate parameter $parsed[$name][] = $value; } else { // Add a new parameter $parsed[$name] = $value; } } return $parsed; }