예제 #1
0
function getSignedParams($method, $url, $params)
{
    $params['oauth_version'] = "1.0";
    $params['oauth_signature_method'] = "HMAC-SHA1";
    $params['oauth_timestamp'] = time();
    $params['oauth_nonce'] = rand();
    if (isset($params['oauth_consumer_secret'])) {
        $secret = $params['oauth_consumer_secret'];
        unset($params['oauth_consumer_secret']);
    }
    $secret .= "&";
    if (isset($params['oauth_token_secret'])) {
        $secret .= $params['oauth_token_secret'];
        unset($params['oauth_token_secret']);
    }
    //
    // Build signature from alphabetic sorted params, url & method
    //
    ksort($params);
    // Wichtig: alphabetische Reihenfolge für Signatur
    $enc_params = http_build_query($params);
    $enc_url = strtoupper($method) . "&" . encode_rfc3986($url) . "&" . encode_rfc3986($enc_params);
    $signature = base64_encode(hash_hmac('sha1', $enc_url, $secret, true));
    $params['oauth_signature'] = $signature;
    return $params;
}
예제 #2
0
function normalize_oauth_params(&$request, $to_header = FALSE)
{
    $buffer = array();
    ksort($request);
    foreach ($request as $k => $v) {
        $buffer[] = !$to_header ? $k . '=' . encode_rfc3986($v) : $k . '="' . encode_rfc3986($v) . '"';
    }
    return !$to_header ? implode('&', $buffer) : 'Authorization: OAuth ' . implode(',', $buffer);
}
예제 #3
0
    $consumer = curl_exec($call_twitter);
    curl_close($call_twitter);
    parse_str($consumer, $consumer);
    if (isset($consumer['oauth_token_secret'], $consumer['oauth_token'])) {
        $this->user->sess['oauth_token_secret'] = $consumer['oauth_token_secret'];
        header('Location: ' . AUTHENTICATE_URL . '?oauth_token=' . $consumer['oauth_token']);
        exit;
    } else {
        $D->noposts_box_title = $this->lang('global_twit_not_finished1_ttl');
        $D->noposts_box_text = $this->lang('global_twit_not_finished1_msg');
        $this->load_template('noposts_box.php');
    }
} elseif (isset($_GET['oauth_verifier'])) {
    $request_parameters = array('oauth_consumer_key' => $C->TWITTER_CONSUMER_KEY, 'oauth_signature_method' => 'HMAC-SHA1', 'oauth_timestamp' => time(), 'oauth_token' => $_GET['oauth_token'], 'oauth_nonce' => md5(rand() . time() . rand()), 'oauth_version' => '1.0');
    $params = normalize_oauth_params($request_parameters);
    $signature = base64_encode(hash_hmac('sha1', 'GET&' . urlencode(utf8_encode(ACCESS_TOKEN_URL)) . '&' . encode_rfc3986($params), $C->TWITTER_CONSUMER_SECRET . '&' . $this->user->sess['oauth_token_secret'], true));
    $call_twitter = curl_init();
    curl_setopt($call_twitter, CURLOPT_URL, ACCESS_TOKEN_URL . '?' . $params . '&oauth_signature=' . $signature);
    curl_setopt($call_twitter, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($call_twitter, CURLOPT_SSL_VERIFYPEER, FALSE);
    curl_setopt($call_twitter, CURLOPT_SSL_VERIFYHOST, FALSE);
    $consumer = curl_exec($call_twitter);
    curl_close($call_twitter);
    parse_str($consumer, $consumer);
    if (is_array($consumer) && isset($consumer['oauth_token'], $consumer['oauth_token_secret'], $consumer['user_id'], $consumer['screen_name'])) {
        $check = $db2->fetch_field('SELECT 1 FROM users_details WHERE extrnlusr_twitter="' . $consumer['screen_name'] . '" LIMIT 1');
        if (!$check) {
            $res = $db2->fetch_field('SELECT 1 FROM users_details WHERE user_id="' . $this->user->id . '" LIMIT 1');
            if ($res) {
                $db2->query('UPDATE users_details SET integr_twitter=\'' . json_encode($consumer) . '\', extrnlusr_twitter="' . $db2->e($consumer['screen_name']) . '" WHERE user_id="' . $this->user->id . '" LIMIT 1');
            } else {