/** * attempt to build up a request from what was passed to the server */ public static function from_request($http_method = null, $http_url = null, $parameters = null) { $scheme = !isset($_SERVER['HTTPS']) || $_SERVER['HTTPS'] != 'on' ? 'http' : 'https'; $http_url = $http_url ? $http_url : $scheme . '://' . $_SERVER['SERVER_NAME'] . ':' . $_SERVER['SERVER_PORT'] . $_SERVER['REQUEST_URI']; $http_method = $http_method ? $http_method : $_SERVER['REQUEST_METHOD']; // We weren't handed any parameters, so let's find the ones relevant to // this request. // If you run XML-RPC or similar you should use this to provide your own // parsed parameter-list if (!$parameters) { // Find request headers $request_headers = Yoast_OAuthUtil::get_headers(); // Parse the query-string to find GET parameters $parameters = Yoast_OAuthUtil::parse_parameters($_SERVER['QUERY_STRING']); // It's a POST request of the proper content-type, so parse POST // parameters and add those overriding any duplicates from GET if ($http_method == 'POST' && isset($request_headers['Content-Type']) && strstr($request_headers['Content-Type'], 'application/x-www-form-urlencoded')) { $post_data = Yoast_OAuthUtil::parse_parameters(file_get_contents(self::$POST_INPUT)); $parameters = array_merge($parameters, $post_data); } // We have a Authorization-header with OAuth data. Parse the header // and add those overriding any duplicates from GET or POST if (isset($request_headers['Authorization']) && substr($request_headers['Authorization'], 0, 6) == 'OAuth ') { $header_parameters = Yoast_OAuthUtil::split_header($request_headers['Authorization']); $parameters = array_merge($parameters, $header_parameters); } } return new Yoast_OAuthRequest($http_method, $http_url, $parameters); }
/** * Exchange request token and secret for an access token and * secret, to sign API calls. * * @returns array( 'oauth_token' => 'the-access-token', * 'oauth_token_secret' => 'the-access-secret' ) */ function get_access_token($oauth_verifier = '') { $parameters = array(); if (!empty($oauth_verifier)) { $parameters['oauth_verifier'] = $oauth_verifier; } $request = $this->oauth_request(self::access_token_url, 'GET', $parameters); $token = Yoast_OAuthUtil::parse_parameters(wp_remote_retrieve_body($request)); $this->token = new Yoast_OAuthConsumer($token['oauth_token'], $token['oauth_token_secret']); return $token; }