Facebook Canvas Authentication Redirect Omniauth-facebook problem (redirect outside iframe)

I am new to Facebook authentication and have a redirect problem. I implemented my application with Rails 3.2.6 and used omniauth-facebook 1.4.0 to integrate with Facebook. “Sing on Facebook” on my website works, but canvas authentication doesn’t work properly.

EXPECTATIONS:

  • A user finds my web application on Facebook and accepts the Login dialog to launch my application.
  • The user is redirected to my application on the Facebook canvas page, and not outside the canvas iframe framework.

ACTUAL RESULT:

User authentication is performed, but then my application page is redirected outside the iframe.

Facebook app settings

Setting up the Facebook application is as follows. The canvas URL is set as "/ auth / facebook /" for immediate user authentication. (I added space to avoid sympathy for an invalid domain)

Facebook Website Login Site URL: http: // localhost: 3000 /

Canvas URL: http: // localhost: 3000 / auth / facebook /

omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do provider :facebook, FB_APP_ID, FB_APP_SECRET, {:image_size => 'large', :iframe => true, :client_options => {:ssl => {:ca_file => Rails.root.join('lib/assets/cacert.pem').to_s}}} end 

sessions_controller.rb

 class SessionsController < ApplicationController def create auth = Auth.from_omniauth(env["omniauth.auth"]) session[:user_id] = auth.id redirect_to root_url end def destroy session[:user_id] = nil redirect_to root_url end end 

Thanks in advance!

+7
source share
1 answer

An easy way to fix this is to determine if the user is in the frame and then bounce it on Facebook if it is not. I do this in my Facebook applications using the following JavaScript:

 <script type="text/javascript"> if ( top === self ) { window.top.location = '{fb_canvas_url}'; } </script> 
+1
source

All Articles