OAuth in PHP make request with two legs

I am currently stuck trying to make requests to the api service using a 2 point oAuth request using PHP.

I am using the PHP library found here: http://code.google.com/p/oauth-php/ and there seems to be absolutely no documentation on the internet for using this library for a 2-leg request.

So, currently from the service, I have the following data:

  • $ consumer_key - must be an empty string
  • $ consumer_secret - must be an empty string
  • $ access_token is my username
  • $ access_token_secret - generated application token

And I want to be able to make a request:

http://foo.com/api/test/whoami

      

To test if the authentication is working properly, I can use the rest of the api.

Anyone have any pointers on how to use this php library for this? or are there any better methods for simple two-legged calls like this?

Help!?:)

+2


source to share


2 answers


This small example might help http://developer.yahoo.com/blogs/ydn/posts/2010/04/a_twolegged_oauth_serverclient_example/



+1


source


You only need the consumer key and the consumer secret to allow authorized two-way oauth requests.

Download OAuthConsumer

. (comment out the class on OAuthException

lines 6-8)



Sample code:

require_once 'OAuth.php';

$signatureMethod = new OAuthSignatureMethod_HMAC_SHA1();
$consumerKey = 'abc';
$consumerSecret = 'def';
$httpMethod = 'GET';
$url = 'http://path/to/endpoint';
$requestFields = array();

$oauthConsumer = new OAuthConsumer($consumerKey, $consumerSecret, NULL);
$oauthRequest = OAuthRequest::from_consumer_and_token($oauthConsumer, NULL, $httpMethod, $url, $requestFields);
$oauthRequest->sign_request($signatureMethod, $oauthConsumer, NULL);

      

0


source







All Articles