Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP Twitter proxy that supports XAuth on an Apache server
    text
    copied!<p>I've been banging my head against this problem for nearly two days now, and I'm hoping someone on this site can help me.</p> <p>I live in China and have a server (shared hosting) located in Hong Kong. I've set up a PHP Twitter proxy on the server, and I connect to the proxy using Twitter for iPhone (AKA Tweetie). It's worked beautifully for the past year or so.</p> <p>Twitter for iPhone was updated yesterday and now requires XAuth authorization to connect to twitter.com (previously, it used Basic Auth). Since the update, I haven't been able to authenticate myself using my proxy, in spite of making (what I believe to be) the appropriate changes to my proxy.</p> <p>Conceptually, this isn't a very difficult problem to crack. In order to authenticate with twitter.com using XAuth, an app must send a POST request to <a href="https://api.twitter.com/oauth/access_token" rel="nofollow noreferrer">https://api.twitter.com/oauth/access_token</a>. The POST body must be of the form:</p> <pre><code>x_auth_username=aUserName&amp;x_auth_mode=client_auth&amp;x_auth_password=aPassword </code></pre> <p>Additionally, the POST request must have an Authorization header in the form:</p> <pre><code>OAuth oauth_signature_method="HMAC-SHA1", oauth_consumer_key="IQKbtAYlXsomeLGkey0HUA", oauth_nonce="8B265865-3F57-44FF-BCD6-E009EA7D4615", oauth_signature="sbwblaho64blahr934mZQ+23DYQ=", oauth_timestamp="1277356846", oauth_version="1.0" </code></pre> <p>So, what I've done is used .htaccess to copy the Auth header to a $_REQUEST variable using this code:</p> <pre><code>RewriteCond %{HTTP:Authorization} ^OAuth.* RewriteRule (.*) index.php?OAuth=%{HTTP:Authorization} [QSA,L] </code></pre> <p>My proxy copies the contents of that $_REQUEST variable to an instance variable called $self->oauthHeader. Then, I make add it as a header to my cURL request using the following code:</p> <pre><code>if (isset($this-&gt;oauthHeader)) { $headers[] = 'Authorization: '.$this-&gt;oauthHeader; $headers[] = 'Content-Type: application/x-www-form-urlencoded'; $curl_options[CURLOPT_HTTPHEADER] = $headers; } </code></pre> <p>I also add the original request's POST body to the cURL's POST body using:</p> <pre><code>$curl_options[CURLOPT_POST] = true; $curl_options[CURLOPT_POSTFIELDS] = @file_get_contents("php://input"); </code></pre> <p>I send the cURL request to Twitter. Everything seems to work correctly, but I inevitably receive a response of "Failed to validate oauth signature and token."</p> <p>I'm at my wit's end, and I can't for the life of me think what I'm doing wrong. Any help would be much appreciated.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload