开发者

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

开发者 https://www.devze.com 2023-03-16 12:19 出处:网络
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 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开发者_JAVA百科_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.


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消