Eureka! I finally got PECL/OAuth provider examples working

Hurray! Today, I finally got the PECL/OAuth examples working. In the past couple of days, I have been working on OAuth for the Application Platform I am working on, which is a set of APIs. I am working on both the consumer and service provider aspect. The PECL/OAuth is in my opinion the best solution. It can be compiled with PHP, so no need for external PHP library. There is just one problem with it, lack of tutorials and documentation. But, today, I finally got it working. How ?

First, there are a couple of tutorials for it. The first is from Rasmus Lerdorf, which is quoted in the PECL/OAuth examples. It is a bit cryptic at times, he uses Kohana framework, so if you are familiar with Kohana, you may understand most of what he writes about. But, since I am not using any framework, a lot of things are missing.

The second tutorials is from Freek Litjen. His tutorial is a lot better, making a lot of things make sense, because he offers a more complete examples of the functions used behind the tutorials. So, I suggest you read his tutorial first.

So, to get the examples working, it is actually quite simple, you just need to pass the parameters for the provider using the method setParam(). Like this :

$provider = new OAuthProvider($params);
$provider->setParam("oauth_consumer_key", $_POST['oauth_consumer_key']);
 $provider->setParam("oauth_nonce", $_POST['oauth_nonce']);
 $provider->setParam("oauth_timestamp", $_POST['oauth_timestamp']);
 $provider->setParam("oauth_signature", $_POST['oauth_signature']);
 $provider->setParam("oauth_signature_method", $_POST['oauth_signature_method']);
$provider->your_own_member = "this is passed to every callback";

Note the bold section, which is the addition to the examples that I add. Naturally, you will need to changes $_POST with $_GET if you are not using OAUTH_AUTH_TYPE_FORM. The default for PECL/OAuth is $_GET. Or you can just use $_REQUEST.

And remember to change the URI used in checkOAuthRequest() method to your API call.

Next, to write a wrapper for the PECL/OAuth so life is a whole lot simpler…