2

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:

  • $consumer_key - needs to be an empty string
  • $consumer_secret - needs to be an empty string
  • $access_token - my login name
  • $access_token_secret - your generated application token

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!? :)

navitronic
  • 563
  • 3
  • 15
  • 1
    What do you mean by "needs to be an empty string" for the key/secret? You need some value there to be able to sign the request. Also, you usually wouldn't use the access token/token secret for a 2 legged request - you just sign the params with the secret – madlep Oct 04 '09 at 10:09
  • The service I am authenticating against requires an empty consumer key and consumer secret to work. I am not sure why this is the case, I have almost worked out the issues though, hopefully will be able to formulate an answer to my own question in an hour or two... – navitronic Oct 04 '09 at 23:32
  • Was a solution found or was the OP hit by a bus? 1 or 2 hours has turned into 4 months :) – Ben Feb 24 '10 at 22:53
  • 2
    Nah, not hit by a bus. Although that would have been pretty apt given how annoying this process was. The project got cut due to this not working out and the budget blowing out. – navitronic Mar 09 '10 at 03:05
  • 1
    There's actually some really good wiki on 2-legged requests for this specific library at http://code.google.com/p/oauth-php/wiki/ConsumerHowTo but sorry to be a bit late :) – Doug Molineux Aug 25 '10 at 20:58

2 Answers2

1

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

ticallian
  • 1,631
  • 7
  • 24
  • 34
User
  • 1,363
  • 2
  • 13
  • 23
  • That example seem to request a key on itself, I seem no where any real API EndPoint, it's always the current script. Still looking for a plain simple example in pure php. – FMaz008 Sep 29 '11 at 12:48
0

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);
Muhammad Reda
  • 26,379
  • 14
  • 93
  • 105