rubyfacebookomniauthcuba

Omniauth: ArgumentError: wrong number of arguments (1 for 0)


I am using Omniauth for login with Facebook but when Callback phase is initiated I get this error:

[2015-01-07T02:26:31.113785 #11509]  INFO -- omniauth: (facebook) Request phase initiated.
127.0.0.1 - - [07/Jan/2015:02:26:31 +0100] "GET /auth/facebook HTTP/1.1" 302 239 0.0097
I, [2015-01-07T02:26:31.295848 #11509]  INFO -- omniauth: (facebook) Callback phase initiated.
ArgumentError: wrong number of arguments (1 for 0)
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:317:in `get'
    /home/ciro/workspace/iParty/app.rb:25:in `block in <top (required)>'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:127:in `instance_eval'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:127:in `block in call!'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:126:in `catch'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:126:in `call!'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/cuba-3.3.0/lib/cuba.rb:111:in `call'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:404:in `call_app!'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:362:in `callback_phase'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-oauth2-1.2.0/lib/omniauth/strategies/oauth2.rb:77:in `callback_phase'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-facebook-1.6.0/lib/omniauth/strategies/facebook.rb:71:in `callback_phase'
    /home/ciro/.rvm/gems/ruby-2.1.3/gems/omniauth-1.2.2/lib/omniauth/strategy.rb:227:in `callback_call'

I have used Cuba framework (which is very similar to Sinatra). This is my configuration:

app.rb

require "cuba"
require "omniauth-facebook"

Cuba.use Rack::Session::Cookie,
   key: ENV['COOKIE_KEY'],
   secret: ENV['COOKIE_SECRET'] 

 Cuba.use OmniAuth::Builder do
    provider :facebook, ENV['FBK_APP_ID'], ENV['FBK_APP_SECRET']
 end

Cuba.define do
   on get '/auth/facebook/callback' do 
      res.write "Autentication with Facebook was successful!"
   end

   on get '/auth/failure' do
     res.write "Something was wrong with Facebook authentication"
   end
end

What is missing?


Solution

  • There should be one on-get block defining multiple routes:

    Cuba.define do
       on get do
         on '/auth/facebook/callback' do 
           res.write "Autentication with Facebook was successful!"
         end
    
         on '/auth/failure' do
           res.write "Something was wrong with Facebook authentication"
         end
       end
    end