Reputation: 563
I am currently stuck trying to make requests to a service's api using a 2 legged 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 anywhere online for using this library for a 2 legged request.
So currently from the service I have the following details:
And I want to be able to make a request to:
http://foo.com/api/test/whoami
To test that the authentication is working correctly so I can use the rest of the api.
Anybody got any pointers on how to use that php library to achieve this? or are there better methods for a simple 2 legged call like this?
Help!? :)
Upvotes: 2
Views: 4373
Reputation: 27023
You need just the consumer key and consumer secret to make authorized 2-legged oauth requests.
Download OAuthConsumer
. (comment out the class OAuthException
lines 6-8)
Code sample:
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);
Upvotes: 0
Reputation: 1373
This little example might help http://developer.yahoo.com/blogs/ydn/posts/2010/04/a_twolegged_oauth_serverclient_example/
Upvotes: 1