prabu
prabu

Reputation: 6171

OmniAuth NoAuthorizationCodeError

I'm using rails 3.2.11 and omniauth gem to authenticate users with their Facebook account.

Gemfile

gem 'omniauth-facebook', '1.4.0'. 

/config/initializers/omniauth.rb

require 'facebook'
Rails.application.config.middleware.use OmniAuth::Builder do
   provider :facebook, "#{Facebook::APP_ID.to_s}", "#{Facebook::SECRET.to_s}" ,{:scope => "email, offline_access, manage_pages"}
end

routes.rb

match "/auth/:provider/callback" => "public_new_pages#auth_callback", :as => :callback
match "/auth/failure" => "public_new_pages#failure", :as => :failure

I would like to access album's pictures using the Facebook graph API for big brand facebook pages. I cann't get all the time. Its works for some Facebook pages. unable to find out a proper solution why I received an error like below and my page crashed.

In browser I see Internal server error 500. and in console I see the error 
below when I tried to create a big site called "BMW"
Started GET "/auth/facebook/callback" for 66.249.74.126 at 2013-03-17 01:10:45
**OmniAuth::Strategies::Facebook::NoAuthorizationCodeError 
(must pass either a `code` parameter or a signed request** 
(via `signed_request` parameter or a `fbsr_XXX` cookie)):
omniauth-facebook (1.4.0) lib/omniauth/strategies/facebook.rb:177:in 
`with_authorization_code!'

Any solution ?

Thanks!

Upvotes: 2

Views: 3009

Answers (3)

Heather
Heather

Reputation: 1

From what I can tell, FB no longer permits the use of localhost:3000 as an App Domain or Site URL. You have to create a "new" localhost, basically, mask your localhost as an acceptable URL (i.e. http://my.computer.com:3000). Instruction on how to do it for Macs can be found here: https://www.imore.com/how-edit-your-macs-hosts-file-and-why-you-would-want . This new localhost URL needs to go in 3 places on the FB app setup - in the settings in the 'App Domain field', in 'Site URL' field at bottom of settings page, and in the 'Valid OAuth redirect URIs' field on the FB login products page. Also, don't forget to add jquery to your rails app if you are using Rails 5.1+.

Upvotes: 0

Mani
Mani

Reputation: 2553

I don't think root url is necessary for callback you can redirect to any url using the route.rb , I got the same error and I found that this was due to deprecated name of permission I was using in my authentication scope e.g At the time of error my provider looked like

 provider :facebook, '2947293729hwehrk', '036e67ce6345cf9',
  :scope => 'email,user_birthday,read_stream'

But when I removed read_stream , error disappeared :)

Note : I'm sure about call back url because I my self using the following configuration

In facebook console , my URL looks like

http://localhost:3000/

And my route for callback is following

  get 'auth/:provider/callback', to:  'sessions#create'

And it's working fine :)

Upvotes: 1

Srikanth Venugopalan
Srikanth Venugopalan

Reputation: 9049

Try changing your callback URL to the root of your site.

This issue in omniauth-facebook talks about the exact same error.

Upvotes: 0

Related Questions