Ruby on Rails OmniAuth Facebook works for Live App on Heroku, but does not test application on Cloud9

I have been struggling to figure this issue out for several weeks, and I just can't figure it out.

I run a Ruby On Rails application that posts to Facebook. The development environment is in Cloud9, and the live site is hosted on Heroku. The application has an appropriate account with Developers.Facebook.com with the full application and the test application associated with it.

I have Heroku settings working great with the full Facebook app.

Problems start with Cloud9 settings in the Facebook testing app. Whenever I try to connect through the API, I get the following error:

enter image description here

Immediately after this error:

enter image description here

I tried using the following parameters for my url but nothing works:

https://{workspace}-{username}.c9.io/ https://{workspace}-{username}.c9.io:80/ https://{workspace}-{username}.c9.io:8080/ https://{workspace}-{username}.c9users.io/ https://{workspace}-{username}.c9users.io:80/ https://{workspace}-{username}.c9users.io:8080/ 

Here is my FacebookAccount model.

 class FacebookAccount < ActiveRecord::Base belongs_to :user has_many :facebook_pages if Rails.env.production? FACEBOOK_APP_ID = ENV["FACEBOOK_APP_ID"] FACEBOOK_SECRET = ENV["FACEBOOK_SECRET"] else FACEBOOK_APP_ID = "XXXXXXXXXXXXXXX" FACEBOOK_SECRET = "XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX" end def self.from_omniauth(auth) oauth = Koala::Facebook::OAuth.new(FACEBOOK_APP_ID, FACEBOOK_SECRET) new_access_info = oauth.exchange_access_token_info auth.credentials.token new_access_token = new_access_info["access_token"] new_access_expires_at = DateTime.now + new_access_info["expires"].to_i.seconds where(provider: auth.provider, uid: auth.uid).first_or_initialize.tap do |facebook_account| facebook_account.provider = auth.provider facebook_account.uid = auth.uid facebook_account.name = auth.info.name facebook_account.image = auth.info.image facebook_account.email = auth.info.email facebook_account.oauth_token = new_access_token facebook_account.oauth_expires_at = new_access_expires_at facebook_account.save! end end end 
+6
source share
2 answers

When you set the URLs of your website on the Facebook Developer Settings page, you must provide two URLs.

  • The base URL of your site (www.example.com)
  • Your website callback URL (www.example.com/auth/facebook/callback)

If one or the other is not there, you will get these errors telling you that the callback URL is not whitelisted or the website URL is not whitelisted.

Add the website as a platform in Settings> General, then find Add Platform. Add the URL of your website.

enter image description here

C9 seems to add the port number to the callback URI. Try adding this port number to the actual OAuth callback URI:

http: // [workspace] - [username] .c9.io: 80 / auth / facebook / callbac k

+2
source

This seems to be a problem with the way you registered and set up the application on Facebook. Make sure you add these URIs to your Facebook whitelist. See here for more details .

+1
source

Source: https://habr.com/ru/post/1012846/


All Articles