Search code examples
ruby-on-railsfacebookfacebook-graph-apioauthkoala

Rails (Koala): Can't login to Facebook - Load denied by X-Frame-Options


I am using this code to Facebook from my Rails app using Koala:

  def login #login on Facebook
    session['oauth'] = Koala::Facebook::OAuth.new(SITE_URL+'/callback')
    # redirect to facebook to get your code
    redirect_to session['oauth'].url_for_oauth_code(:permissions=>PERMISSIONS)
  end

When login is executed, I get the following error message:

Load denied by X-Frame-Options: https://www.facebook.com/dialog/oauth?
client_id=MYAPPID&redirect_uri=http%3A%2F%2Fexample.com%2Fcallback
&scope=public_profile does not permit framing.

Seems to be trying to show the canvas for login, but my app is just a website that needs Facebook authentication. Is there anything that I have to change in my Facebook App settings or in the code?


Solution

  • Add the following into your config/application.rb

    config.action_dispatch.default_headers = {
      'X-Frame-Options' => 'ALLOW-FROM https://www.facebook.com'
    }
    

    PS: don't forget to restart your server after you add this.