etayluz
etayluz

Reputation: 16416

OAuth 1.0a “one-legged” authentication with Ruby on Rails

I need to make a request using OAuth 1.0a “one-legged” authentication with Ruby on Rails. How do I do that?

These are the two api's I would like to call:

I am provided with consumer key and consumer secret.

Please note, I am referring to this specific OAuth protocol and not the others:

http://oauthbible.com/#oauth-10a-one-legged

Upvotes: 0

Views: 1955

Answers (1)

Léo
Léo

Reputation: 810

This gem works well: https://github.com/oauth-xx/oauth-ruby

Install the oauth gem:

sudo gem install oauth

In your controller:

require 'oauth'

key = "YOUR_KEY"
secret = "YOUR_SECRET"
site_url = "YOUR_API_URL"
endpoint = "YOUR_ENDPOINT_URL"


consumer = OAuth::Consumer.new(key, secret, {site: site_url}) 

# for a POST request
response = consumer.request(:post, endpoint, nil, {}, {})

# for a GET request
response = consumer.request(:get, endpoint, nil, {}, {})

# display response
puts response

Upvotes: 1

Related Questions