ZF-10197: Zend Http Client problem with Delicious Oauth signature
Description
I implemented the yahoo Oauth login for delicious with Zend_Oauth. All is working as expected as long as there are no spaces in the description parameter. As soon as there is a space in the description a signature error is returned from yahoo.
The problem is, that Zend_Oauth_Client (or Zend_Http_Client) uses http_build_query to create the query. http_build_query replaces all spaces with + instead of %20. So the signature created by the server is not the same as created by the client.
The bug can be fixed by adding the following on line 959 (Zend_Http_Client).
$query .= http_build_query($this->paramsGet, null, '&');
$query = str_replace('+','%20',$query);
I'm not sure if this will break other requests or what could be a better way to implement it. At the moment I created a additional socket adapter the does the replacing because I'm able to inject the adapter into the client.
More about the problem here in this thread on the bottom: http://support.delicious.com/forum/comments.php/…
Comments
Posted by Pádraic Brady (padraic) on 2010-07-25T10:01:50.000+0000
May need a more detailed description as to how the client is being used (i.e. request method, authorisation scheme (any option passed into Zend_Oauth). Note that Zend_Oauth has been used elsewhere with no reported problems of this specific nature. Changing the encoding may alter signatures for working services (can't be allowed to occur), so I need to see whether this is something in the way the component is used specifically for Delicious but not for other service APIs. If this is only impacting Delicious when similar use cases work elsewhere, then it will not be fixed except for specific use cases in something like Zend_Service_Delicious where it becomes necessary but limited in scope.
Additionally, Zend_Oauth extends Zend_Http_Client which is responsible for URI encoding. This would require a fix to Zend_Http_Client if an incorrect behaviour.
Posted by Nicolas Ruflin (ruflin) on 2010-07-26T15:20:34.000+0000
I think the problem is only in the signature part of OAuth implementation. I use also OAuth with Twitter and here it works without a problem.
But as far as I can see Twitter doesn't use the whole signature sing as Delicious (Yahoo) does in step 6: http://delicious.com/help/oauthapi
Here is the code how I implemented it. The problem occurs in the third step (post) only if the variable $data['title'] has a space inside. Otherwise it works without a problem.
Here is also the code from my client. It only overloads the standard client and adds the str_replace function.
On thing I discovered during searching for the bug is, that the Yahoo also implements one function a bit different (the PHP library can be found here: http://developer.yahoo.com/social/sdk/#php )
The url encoding is done as following
In the Zend_Oauth_Http_Utility it is:
As defined in the OAuth Protocol, every URL should be encode with rfc3986. I'm not sure, if the second implementation is also RFC 3986 http://tools.ietf.org/html/rfc3986
But like I described before, in the end it wasn't a problem of all the oauth functions, which are creating the right signature. The problem is, that inside the signature the url is encode with rfc3986 which means, it replaces spaces with %20. But then Zend_Http_Client uses http://ch2.php.net/manual/de/… to create the queries, and replaces spaces with +. So the reponse server creates a different signature.
Posted by Pádraic Brady (padraic) on 2010-10-10T13:19:25.000+0000
Fixed in trunk via a patch to Zend_Http_Client to allow for RFC 3986 strict encoding
Posted by Nicolas Ruflin (ruflin) on 2010-10-10T13:55:30.000+0000
Thanks for the fix.