OAuth2 with intridea ruby gem
There seems to be a problem how the oauth2 gem passes variabels inside the objects so mode and param_name seems to be lost on the way. A solution to the problem would be to create a new AccessToken object with the correct parameters instead of using the shorthand. This example is tested against Foursquares api and it works.
require "oauth2"
client = OAuth2::Client.new(
"CLIENT_ID",
"CLIENT_SECRET",
:authorize_url => "/oauth2/authorize",
:token_url => "/oauth2/access_token",
:site => "https://foursquare.com/"
)
puts client.auth_code.authorize_url(:redirect_uri => "http://localhost:4000")
code = gets.chomp
token = client.auth_code.get_token(code, :redirect_uri => "http://localhost:4000")
token = OAuth2::AccessToken.new(client, token.token, {
:mode => :query,
:param_name => "oauth_token",
})
response = token.get('https://api.foursquare.com/v2/users/self/checkins')
puts response.body
OAuth2 INTRIDEA gem and HTTP basic authentication header
After looking at the docs for the auth_code
strategy and the code for oauth2/strategy/password.rb
, oauth2/strategy/base.rb
and oauth2/client.rb
, it appears the OAuth2 gem will add the client_id
and client_secret
form parameters to the body but not the header. This is permitted but NOT RECOMMENDED
by IETF RFC 6749. To add the IETF recommended Authorization
header, it appears you need to add it as parameter as shown above.
More info: Pull request #192 covers this but may be stalled due to backward compatibility issues.
Related Topics
Why Rails Can Use 'If' as Hash Key But Not in Ruby
While Executing Gem ... (Argumenterror) Unknown Encoding Name - Cp720
Determining Method's Visibility on the Fly
Ruby on Rails: Fully Functional Tableless Model
How to Make Empty Tags Self-Closing with Nokogiri
How to Refer to a Submodule's "Full Path" in Ruby
Ruby#Index Method VS Binary Search
Getting Hash with Symbol as Keys for Mongo in Rails
What Is the Ruby Equivalent of Preg_Quote()
Disabling Irb Autocomplete on Heroku
Regexp Search Through a Very Large File
Iterate Through Array of Hashes in Ruby
Algorithm to Shuffle an Array Randomly Based on Different Weights
Uml Sequence Diagram - How to Represent Method Arguments That Instantiate Objects
How to Set the Mechanize Page Encoding
Chrome Asks to "Select a Certificate" for Ssl on My Rails App Using Thin