0

I created a gem to work with Box API V2 (https://github.com/youpdidou/omniauth-box/). I tested it in development. The authentication is created as needed and recorded in DB, but there is an error in the redirect to my page at the end of the process (cf. log below).

My app works fine with other providers (I have Twitter and Yammer, using the omniauth-twitter, and omniauth-yammer gem), so it seems the error could come something I am missing in my Gem (something related to the refresh token?), or maybe it is related to the fact The Box authentication process has 2 steps (1 for credentials, 1 to authorize access to files - cf. http://developers.box.com/oauth/)...

What am I missing here? How to debug this, and what should I look at?

(box) Callback phase initiated.


Started GET "/auth/box/callback?state=7d550f7c0d367d4af73ca3a1d82985c78730126887e3e813&code=fV19In0Elnq1GNX61t32N1h8anezbTiH" for 127.0.0.1 at 2013-01-30 00:28:18 -0800
Processing by AuthenticationsController#create as HTML
  Parameters: {"state"=>"7d550f7c0d367d4af73ca3a1d82985c78730126887e3e813", "code"=>"fV19In0Elnq1GNX61t32N1h8anezbTiH", "provider"=>"box"}
  User Load (0.4ms)  SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
  Authentication Load (0.5ms)  SELECT `authentications`.* FROM `authentications` WHERE `authentications`.`user_id` = 1 AND `authentications`.`provider` = 'box' AND `authentications`.`uid` = '288560' LIMIT 1
   (0.1ms)  BEGIN
  SQL (0.3ms)  INSERT INTO `authentications` (`created_at`, `oauth_secret`, `oauth_token`, `provider`, `uid`, `updated_at`, `user_id`) VALUES ('2013-01-30 08:28:19', NULL, NULL, 'box', '288560', '2013-01-30 08:28:19', 1)
   (1.5ms)  COMMIT
   (0.1ms)  BEGIN
   (0.4ms)  UPDATE `authentications` SET `oauth_token` = 'cZga3uA89eslNAURbJlZaySukIs9IxTF', `updated_at` = '2013-01-30 08:28:19' WHERE `authentications`.`id` = 26
   (0.5ms)  COMMIT
Redirected to http://localhost:3000/services
Completed 302 Found in 14ms (ActiveRecord: 3.7ms)
[2013-01-30 00:28:19] ERROR Errno::ECONNRESET: Connection reset by peer
    /Users/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:80:in `eof?'
    /Users/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/httpserver.rb:80:in `run'
    /Users/alex/.rvm/rubies/ruby-1.9.3-p0/lib/ruby/1.9.1/webrick/server.rb:191:in `block in start_thread'
alex
  • 1,900
  • 3
  • 24
  • 34

2 Answers2

1

This isn't related to box I think but rails itself, you might want to look at: ERROR Errno::ECONNRESET: Connection reset by peer as this person seems to have near enough the exact same error as you.

EDITED to include answer: quoted from @Matt Smith

My quick guess is this looks like you have a problem with your sessions and protect_from_forgery is kicking in.

I had a similar problem and smashed my head against the wall for a few days, it turned out to be I was assigning an entire object to a session object instead of just the id. A quick note, non-GET requests are the ones that trigger the protect_from_forgery.

Community
  • 1
  • 1
Thermatix
  • 2,757
  • 21
  • 51
0

I had a similar problem in a non-rails app. In my case I was doing some ajax requests on client and redirected to the box authentication page afterwards, without waiting for the server to complete the requests.

Using a promise and redirecting after the request is done fixed the issue. Something like:

$.ajax(my_url, {dataType: "json"}).then(function(data){window.location.replace(auth_url)};

Hope you find some inspiration here.

pcv
  • 2,121
  • 21
  • 25