Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When mixing omniauth and fbgraph gems I am failing to get an access key

I am using Rails 3. I am getting a Rack::OAuth2::Client::Error in SessionsController#create error when I try to get the access key. I used omniauth to login to facebook and I am getting the param["code"] Now I try to use fbgraph to get the access code and I am getting the Rac::OAuth2::Client::Error.

  def create
    auth=request.env["omniauth.auth"]
    fb_auth=FbGraph::Auth.new("xxxxxxx", "xxxxxxxxxxxxxxxxxxxxxxxxxxx")
    client=fb_auth.client
    client.redirect_uri="http://localhost:3000/facebook/callback/"
    client.authorization_code=params[:code]
    access_token = client.access_token!  # => Rack::OAuth2::AccessToken
    user=User.find_by_provider_and_uid(auth["provider"], auth["id"]) ||User.create_with_omniauth(auth, access_token)
    session[:user_id]=user.id

    redirect_to root_url, :notice => "Signed In!"
  end

The access_token! line is what is returning the error.

like image 843
Tommie Jones Avatar asked Nov 14 '22 20:11

Tommie Jones


1 Answers

If you set the redirect_uri on the fb_auth instead of the client it should be fine e.g.

fb_auth = FbGraph::Auth.new(
   "xxxxxxx",
   "xxxxxxxxxxxxxxxxxxxxxxxxxxx",
   :redirect_uri = "http://localhost:3000/facebook/callback"
)
client=fb_auth.client
client.authorization_code=params[:code]
access_token = client.access_token!  # => Rack::OAuth2::AccessToken

You should also check out https://github.com/nov/fb_graph/issues/127#issuecomment-2244499, then have a read of the fb_graph_sample code and setup your FbGraph debugging.

like image 52
chris raethke Avatar answered Nov 24 '22 00:11

chris raethke