Facebook iframe app being redirected out of canvas after user authorization

亡梦爱人 提交于 2019-11-27 17:01:45

问题


My facebook app is being redirected to the canvas url (http://my-domain/app) after the user has authorized the app. The sequence of steps is described below:

1) A new user opens the app in canvas and is redirected to oauth permissions dialog via Javascript redirection

2) Once the user has authorized the app, the redirect_uri of the app is called and I get the access token which I save in session

3) I also get the user id of the authorized user and save it to session

4) When I redirect it to the canvas url, it moves out of the facebook canvas

5) If I try to redirect it to the canvas page (http://apps.facebook.com/app_name) it gets stuck in an infinite loop because the session values are cleared and the process is repeated - I don't know why.

It is a rails 3 app and I am using koala gem. The code is shown below:

  def index
    if (session[:access_token].blank?)
    session[:oauth] = Koala::Facebook::OAuth.new(APP_ID, APP_SECRET, oauth_redirect_url)
    end
    @app_id = APP_ID
  end

  def redirect
    session[:access_token] = session[:oauth].get_access_token(params[:code]) if params[:code]
    if session[:access_token].blank?
      flash[:error] = "You didn't authorize the application. Please authorize the application to throw a firecracker on your friend's wall!"
      redirect_to :action => "authorize_app" and return
    else
      session[:fb_user_id] = Koala::Facebook::API.new(session[:access_token]).get_object("me")["id"]
    end
    redirect_to :action => "index"
  end

I have wasted almost a day trying to fix it, and searching for a solution, but no luch as of now.


回答1:


Step 1, Step 2, Step 3 are ok

Step 4: When the user authorize your app, it will be redirected to yourapp.com (canvas url) at canvas url, you'll do:

<script>
window.top.location='https://apps.facebook.com/yourapp' //(canvas page)
</script>

step 5: as your canvas page is called you'll get signed_request then with your fb api you'll parse it.



来源:https://stackoverflow.com/questions/7831756/facebook-iframe-app-being-redirected-out-of-canvas-after-user-authorization

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!