Reputation: 950
I'm trying to authenticate to a webservice using 2legged oauth. I have the next one working java example creating the authenticated URL using the signpost library:
String consumerKey = "KEY";
String consumerSecret = "SECRET";
DefaultOAuthConsumer consumer = new DefaultOAuthConsumer(consumerKey, consumerSecret);
consumer.setTokenWithSecret(consumerKey, consumerSecret);
return consumer.sign(targetUrl);
And this generates an URL like this
And I'm trying to recreate it using ruby's oauth. My code looks now like this:
consumer = OAuth::Consumer.new(@creds[:key], @creds[:secret],
:site => "URL",
:scheme => :query_string)
token = OAuth::AccessToken.new(consumer)
token.get "METHOD"
And generates URLS like:
But I'm always getting an Unauthorized error, even if I manually set oauth_token to key (as signpost do). Looks like the nonce is invalid, but both of them are valid libraries to oauth
Can anyone help me?
Thanks in advance
Upvotes: 3
Views: 1175
Reputation: 66
I'd been the same problem with 2-legged oauth, I fixed with:
consumer = OAuth::Consumer.new(key, secret, { :site => 'http://api.mysite.com' })
access_token = OAuth::AccessToken.from_hash(consumer, :oauth_token => key, :oauth_token_secret => secret)
Common issues comes from out of sync timestamps
Your requests must be synchronized with the server system clock, for instance in linkedin must be within 5 minutes of her system clock.
Hope it helps ;)
Upvotes: 3