function build_auth_array($baseurl, $key, $secret, $extra = array(), $method = 'GET', $algo = OAUTH_ALGORITHMS::RSA_SHA1)
 {
     $auth['oauth_consumer_key'] = $key;
     $auth['oauth_signature_method'] = $algo;
     $auth['oauth_timestamp'] = time();
     $auth['oauth_nonce'] = md5(uniqid(rand(), true));
     $auth['oauth_version'] = '1.0';
     $auth = array_merge($auth, $extra);
     $urlsegs = explode("?", $baseurl);
     $baseurl = $urlsegs[0];
     $signing = $auth;
     if (count($urlsegs) > 1) {
         preg_match_all("/([\\w\\-]+)\\=([\\w\\d\\-\\%\\.\$\\+\\*]+)\\&?/", $urlsegs[1], $matches);
         $signing = $signing + array_combine($matches[1], $matches[2]);
     }
     if (strtoupper($algo) == OAUTH_ALGORITHMS::HMAC_SHA1) {
         $auth['oauth_signature'] = sign_hmac_sha1($method, $baseurl, $secret, $signing);
     } else {
         if (strtoupper($algo) == OAUTH_ALGORITHMS::RSA_SHA1) {
             $auth['oauth_signature'] = sign_rsa_sha1($method, $baseurl, $secret, $signing);
         }
     }
     $auth['oauth_signature'] = urlencode($auth['oauth_signature']);
     return $auth;
 }
Ejemplo n.º 2
0
/**
 * Assemble an associative array with oauth values
 *
 * @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, 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 array of all the oauth parameters
 */
function build_auth_array($baseurl, $key, $secret, $extra = array(), $method = 'GET', $algo = OAUTH_ALGORITHMS::RSA_SHA1)
{
    $auth['oauth_consumer_key'] = $key;
    $auth['oauth_signature_method'] = $algo;
    $auth['oauth_timestamp'] = time();
    $auth['oauth_nonce'] = md5(uniqid(rand(), true));
    $auth['oauth_version'] = '1.0';
    $auth = array_merge($auth, $extra);
    if (strtoupper($algo) == OAUTH_ALGORITHMS::HMAC_SHA1) {
        $auth['oauth_signature'] = sign_hmac_sha1($method, $baseurl, $secret, $auth);
    } else {
        if (strtoupper($algo) == OAUTH_ALGORITHMS::RSA_SHA1) {
            $auth['oauth_signature'] = sign_rsa_sha1($method, $baseurl, $secret, $auth);
        }
    }
    $auth['oauth_signature'] = urlencode($auth['oauth_signature']);
    return $auth;
}
Ejemplo n.º 3
0
/**
 * Assemble an associative array with oauth values
 *
 * @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, 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 array of all the oauth parameters
 */
function build_auth_array($baseurl, $key, $secret, $extra = array(), $method = 'GET', $algo = OAUTH_ALGORITHMS::RSA_SHA1)
{
    $auth['oauth_consumer_key'] = $key;
    $auth['oauth_signature_method'] = $algo;
    $auth['oauth_timestamp'] = time();
    $auth['oauth_nonce'] = md5(uniqid(rand(), true));
    $auth['oauth_version'] = '1.0';

    $auth = array_merge($auth, $extra);
    
    //We want to remove any query parameters from the base url
    $urlsegs = explode("?", $baseurl);
    $baseurl = $urlsegs[0];
    
    //If there are any query parameters we need to make sure they
    //get signed with the rest of the auth data.
    $signing = $auth;
    if(count($urlsegs) > 1)
    {
        preg_match_all("/([\w\-]+)\=([\w\d\-\%\.\$\+\*]+)\&?/", $urlsegs[1], $matches);
        $signing = $signing + array_combine($matches[1], $matches[2]);
    }
    
    if(strtoupper($algo) == OAUTH_ALGORITHMS::HMAC_SHA1)$auth['oauth_signature'] = sign_hmac_sha1($method, $baseurl, $secret, $signing);
    else if(strtoupper($algo) == OAUTH_ALGORITHMS::RSA_SHA1)$auth['oauth_signature'] = sign_rsa_sha1 ($method, $baseurl, $secret, $signing);
  
    $auth['oauth_signature'] = urlencode($auth['oauth_signature']);
    return $auth;
}