/**
  * This is called to begin the oauth token exchange. This should only
  * need to be called once for a user, provided they allow oauth access.
  * It will return a URL that your site should redirect to, allowing the
  * user to login and accept your application.
  *
  * @param string $callback the page on your site you wish to return to
  *                         after the user grants your application access.
  *
  * @return mixed either the URL to redirect to, or if they specified HMAC
  *         signing an array with the token_secret and the redirect url
  */
 public function get_request_token($callback)
 {
     $baseurl = self::SCHEME . '://' . self::HOST . self::REQUEST_URI;
     //Generate an array with the initial oauth values we need
     $auth = build_auth_array($baseurl, $this->_consumer['key'], $this->_consumer['secret'], array('oauth_callback' => urlencode($callback)), $this->_consumer['method'], $this->_consumer['algorithm']);
     //Create the "Authorization" portion of the header
     $str = "";
     foreach ($auth as $key => $value) {
         $str .= ",{$key}=\"{$value}\"";
     }
     $str = 'Authorization: OAuth ' . substr($str, 1);
     //Send it
     $response = $this->_connect($baseurl, $str);
     //We should get back a request token and secret which
     //we will add to the redirect url.
     parse_str($response, $resarray);
     //Return the full redirect url and let the user decide what to do from there.
     $redirect = self::SCHEME . '://' . self::HOST . self::AUTHORIZE_URI . "?oauth_token={$resarray['oauth_token']}";
     // If they are using HMAC then we need to return the
     // token secret for them to store.
     if ($this->_consumer['algorithm'] == OAUTH_ALGORITHMS::RSA_SHA1) {
         return $redirect;
     } else {
         return array('token_secret' => $resarray['oauth_token_secret'], 'redirect' => $redirect);
     }
 }
 public function get_request_token($callback)
 {
     $baseurl = self::SCHEME . '://' . self::HOST . self::REQUEST_URI;
     $auth = build_auth_array($baseurl, $this->_consumer['key'], $this->_consumer['secret'], array('oauth_callback' => urlencode($callback)), $this->_consumer['method'], $this->_consumer['algorithm']);
     $str = "";
     foreach ($auth as $key => $value) {
         $str .= ",{$key}=\"{$value}\"";
     }
     $str = 'Authorization: OAuth ' . substr($str, 1);
     $response = $this->_connect($baseurl, $str);
     parse_str($response, $resarray);
     $redirect = self::SCHEME . '://' . self::HOST . self::AUTHORIZE_URI . "?oauth_token={$resarray['oauth_token']}";
     if ($this->_consumer['algorithm'] == OAUTH_ALGORITHMS::RSA_SHA1) {
         return $redirect;
     } else {
         return array('token_secret' => $resarray['oauth_token_secret'], 'redirect' => $redirect);
     }
 }
 /**
  * This is called to begin the oauth token exchange. This should only
  * need to be called once for a user, provided they allow oauth access.
  * It will return a URL that your site should redirect to, allowing the
  * user to login and accept your application.
  *
  * @param string $callback the page on your site you wish to return to
  *                         after the user grants your application access.
  * @return mixed either the URL to redirect to, or if they specified HMAC
  *         signing an array with the token_secret and the redirect url
  */
 public function get_request_token($callback)
 {
     $baseurl = self::SCHEME . '://' . self::HOST . '/' . self::API_VERSION . self::REQUEST_URI;
     //Generate an array with the initial oauth values we need
     $auth = build_auth_array($baseurl, $this->_consumer['key'], $this->_consumer['secret'], array(), $this->_consumer['method'], $this->_consumer['algorithm']);
     //Create the "Authorization" portion of the header
     $str = "";
     foreach ($auth as $key => $value) {
         $str .= ",{$key}=\"{$value}\"";
     }
     $str = 'Authorization: OAuth ' . substr($str, 1);
     //Send it
     $response = $this->_connect($baseurl, $str, $this->_consumer['method']);
     //We should get back a request token and secret which
     //we will add to the redirect url.
     parse_str($response, $resarray);
     $callback = urlencode($callback);
     //Return the full redirect url and let the user decide what to do from there.
     $redirect = self::SCHEME . '://www.dropbox.com/' . self::API_VERSION . self::AUTHORIZE_URI . "?oauth_token={$resarray['oauth_token']}&oauth_callback={$callback}";
     return array('token_secret' => $resarray['oauth_token_secret'], 'redirect' => $redirect);
 }
Esempio n. 4
0
/**
 * Creates the authorization portion of a header NOTE: This does not
 * create a complete http header. Also NOTE: the oauth_token parameter
 * should be passed in using the $extra array.
 *
 * @param string $baseurl the base url we are authenticating against.
 * @param string $key your consumer key
 * @param string $secret either your consumer secret key or the file location of your rsa private key.
 * @param array $extra additional oauth parameters that should be included (you must urlencode a parameter, if appropriate, before calling this function)
 * @param string $method either GET or POST
 * @param string $algo either HMAC-SHA1 or RSA-SHA1 (NOTE: this affects what you put in for the secret parameter)
 * @return string the header authorization portion with trailing \r\n
 */
function get_auth_header($baseurl, $key, $secret, $extra = array(), $method = 'GET', $algo = OAUTH_ALGORITHMS::RSA_SHA1)
{
    $auth = build_auth_array($baseurl, $key, $secret, $extra, $method, $algo);
    return build_auth_string($auth);
}