public function get_access_token($token = false, $secret = false, $verifier = false) { if ($token === false && isset($_GET['oauth_token'])) { $token = $_GET['oauth_token']; } if ($verifier === false && isset($_GET['oauth_verifier'])) { $verifier = $_GET['oauth_verifier']; } if ($token === false && $verifier === false) { $uri = $_SERVER['REQUEST_URI']; $uriparts = explode('?', $uri); $authfields = array(); parse_str($uriparts[1], $authfields); $token = $authfields['oauth_token']; $verifier = $authfields['oauth_verifier']; } $tokenddata = array('oauth_token' => urlencode($token), 'oauth_verifier' => urlencode($verifier)); if ($secret !== false) { $tokenddata['oauth_token_secret'] = urlencode($secret); } $baseurl = self::SCHEME . '://' . self::HOST . self::ACCESS_URI; $auth = get_auth_header($baseurl, $this->_consumer['key'], $this->_consumer['secret'], $tokenddata, $this->_consumer['method'], $this->_consumer['algorithm']); $response = $this->_connect($baseurl, $auth); parse_str($response, $oauth); return $oauth; }
/** * Builds out an http header based on the specified parameters. * * @param $url string the url this header will go to. * @param $prepend any header data that needs to be added to the header before it is built. * @param $append any header data that needs to be added after the header is built. * @param $method the http method to be used 'POST', 'GET', 'PUT' etc. * return string the http header. **/ private function _build_header($url = false, $prepend = false, $append = false, $method = self::METHOD) { $str = $prepend === false ? '' : $prepend; foreach ($this->_header as $key => $value) { $str .= $key . ": " . $value . self::LINE_END; } if ($this->_access !== false && $url !== false) { $this->CI->load->helper('oauth_helper'); $str .= get_auth_header($url, $this->_oauth['key'], $this->_oauth['secret'], $this->_access, $method, $this->_oauth['algorithm']); } $str .= $append === false ? '' : $append; return $str; }
private function _build_header($url, $method, $prepend, $append, $overwrite = array()) { $str = $prepend === false ? '' : $prepend; foreach ($this->_header as $key => $value) { if (array_key_exists($key, $overwrite)) { $str .= $key . ': ' . $overwrite[$key] . self::LINE_END; } else { $str .= $key . ': ' . $value . self::LINE_END; } } if ($this->_access !== false && $url !== false) { $str .= get_auth_header($url, $this->_consumer['key'], $this->_consumer['secret'], $this->_access, $method, $this->_consumer['algorithm']); } $str .= $append === false ? '' : $append; return $str; }
/** * This is called to finish the oauth token exchange. This too should * only need to be called once for a user. The token returned should * be stored in your database for that particular user. * * @param string $token this is the oauth_token returned with your * callback url * @param string $secret this is the token secret supplied from the * request (Only required if using HMAC) * @param string $verifier this is the oauth_verifier returned with * your callback url * * @return array access token and token secret */ public function get_access_token($token = false, $secret = false, $verifier = false) { //If no request token was specified then attempt to get one from the url if ($token === false && isset($_GET['oauth_token'])) { $token = $_GET['oauth_token']; } if ($verifier === false && isset($_GET['oauth_verifier'])) { $verifier = $_GET['oauth_verifier']; } //If all else fails attempt to get it from the request uri. if ($token === false && $verifier === false) { $uri = $_SERVER['REQUEST_URI']; $uriparts = explode('?', $uri); $authfields = array(); parse_str($uriparts[1], $authfields); $token = $authfields['oauth_token']; $verifier = $authfields['oauth_verifier']; } $tokenddata = array('oauth_token' => urlencode($token), 'oauth_verifier' => urlencode($verifier)); if ($secret !== false) { $tokenddata['oauth_token_secret'] = urlencode($secret); } $baseurl = self::SCHEME . '://' . self::HOST . self::ACCESS_URI; //Include the token and verifier into the header request. $auth = get_auth_header($baseurl, $this->_consumer['key'], $this->_consumer['secret'], $tokenddata, $this->_consumer['method'], $this->_consumer['algorithm']); $response = $this->_connect($baseurl, $auth); //Parse the response into an array it should contain //both the access token and the secret key. (You only //need the secret key if you use HMAC-SHA1 signatures.) parse_str($response, $oauth); //Return the token and secret for storage return $oauth; }