Application.new Rack::OAuth2::Client::Error #307

Closed
davidkovaccs opened this Issue Apr 4, 2013 · 8 comments

2 participants

@davidkovaccs

Hi,

I'm trying to create test users but somehow any call on my 'app' object returns Rack::OAuth2::Client::Error

My code:
app = FbGraph::Application.new("app_id", :secret => "app_secret")
(app_id and app_secret filled from the application's facebook page: Basic)

app.get_access_token OR
app.test_user!(:installed => true, :permissions => [:read_stream, :email, :user_birthday])

throws exception:
Rack::OAuth2::Client::Error: Rack::OAuth2::Client::Error
from /Users/kovacsd/.rvm/gems/ruby-1.9.3-p392/gems/rack-oauth2-1.0.3/lib/rack/oauth2/client.rb:110:in handle_error_response'
from /Users/kovacsd/.rvm/gems/ruby-1.9.3-p392/gems/rack-oauth2-1.0.3/lib/rack/oauth2/client.rb:87:in
handle_response'
from /Users/kovacsd/.rvm/gems/ruby-1.9.3-p392/gems/rack-oauth2-1.0.3/lib/rack/oauth2/client.rb:61:in access_token!'
from /Users/kovacsd/.rvm/gems/ruby-1.9.3-p392/gems/fb_graph-2.2.6/lib/fb_graph/application.rb:59:in
get_access_token'
from (irb):19
from /Users/kovacsd/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/commands/console.rb:47:in start'
from /Users/kovacsd/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/commands/console.rb:8:in
start'
from /Users/kovacsd/.rvm/gems/ruby-1.9.3-p392/gems/railties-3.2.12/lib/rails/commands.rb:41:in <top (required)>'
from script/rails:6:in
require'
from script/rails:6:in `

'

Thanks

@davidkovaccs

As I've debugged this problem it can be some rack-oauth2 gem version issue (I'm using 1.0.3). In this function:

def access_token!(client_auth_method = :basic)
headers, params = {}, @grant.as_json
if secret && client_auth_method == :basic
cred = ["#{identifier}:#{secret}"].pack('m').tr("\n", '')
headers.merge!(
'Authorization' => "Basic #{cred}"
)
else
params.merge!(
:client_id => identifier,
:client_secret => secret
)
)
end
handle_response do
Rack::OAuth2.http_client.post(
absolute_uri_for(token_endpoint),
Util.compact_hash(params),
headers
)
end
end

It goes to the first branch of the if because there is secret and the default client_auth_method is basic, so the client_id parameter not gets set and facebook returns:
"WWW-Authenticate", "OAuth \"Facebook Platform\" \"invalid_client\" \"Missing client_id parameter.\""], ["X-FB-Rev", "775015"

@davidkovaccs

I don't really now too much about oauth but probably we could fix this by:
self.access_token = auth.client.access_token!(:some_other_auth_method_?) in the get_access token function of the Application object

@nov
Owner
@davidkovaccs

(I've fixed my comment in the meentime from oauth2 to rack-oauth2).
I'm using fb_graph 2.2.6 and rack-oauth2 1.0.3 which seems to be the newest.

@davidkovaccs

Ok, I see there is 2.6.6, sorry for my comments.

@nov
Owner
nov commented Apr 5, 2013

Can I close this issue?

@davidkovaccs
@nov
Owner
nov commented Apr 5, 2013

OK, thanks

@nov nov closed this Apr 5, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment