/** * Exchange a valid OAuth response code for a token object * * @param $response_code * * @return array|WP_Error */ private function get_token_for_code($response_code) { $options = $this->get_option(); //prepare request data for access token $data = array(); $data['client_id'] = $options[LaunchKey_WP_Options::OPTION_ROCKET_KEY]; $data['client_secret'] = $options[LaunchKey_WP_Options::OPTION_SECRET_KEY]; $data['redirect_uri'] = $this->wp_facade->admin_url(); $data['code'] = $response_code; $data['grant_type'] = "authorization_code"; //make oauth call $params = http_build_query($data); // Attempt to get an access token from the resposne code $oauth_get = $this->wp_facade->wp_remote_get("{$this->base_url}/access_token?" . $params, array('httpversion' => '1.1', 'sslverify' => $options[LaunchKey_WP_Options::OPTION_SSL_VERIFY], 'timeout' => $options[LaunchKey_WP_Options::OPTION_REQUEST_TIMEOUT], 'headers' => array('Connection' => 'close'))); if ($this->wp_facade->is_wp_error($oauth_get)) { // If the response is an error, return the error $response = $oauth_get; } else { // Otherwise, decode the response $response = json_decode($oauth_get['body'], true); } return $response; }