'Facebook oAuth execution expired

I'm using Rails 5 with Ruby 2.3.1 and following gems:

gem 'omniauth'
gem 'omniauth-facebook'
gem "omniauth-rails_csrf_protection"

I have Facebook app that passed App Review and it's live. Everything worked fine since last week, now it's working 50% of the time and that's bugging me out.

My code is:

# config/initializers/omniauth.rb
Rails.application.config.middleware.use OmniAuth::Builder do
  provider :facebook, ENV['FB_APP_ID'], ENV['FB_APP_SECRET'], scope: 'user_likes', info_fields: 'id, likes'
end

# app/controllers/omniauth_callbacks_controller.rb
  def facebook
    return redirect_to root_path, notice: t('devise.failure.unsuccessful_authentication') unless request.env["omniauth.auth"]
    @user = User.from_omniauth(request.env["omniauth.auth"])

    if @user.persisted?
      bypass_sign_in(@user)
      redirect_to user_questionnaire_questions_path(Questionnaire.active), notice: t('message.logged_in_successfully')
    else
      session["devise.facebook_data"] = request.env["omniauth.auth"].except(:extra)
      redirect_to root_path, alert: t('message.something_wrong')
    end
  end

# models/user.rb
  def self.from_omniauth(auth)
    user = User.where(user_id: auth.uid).first
    unless user
      user = User.create!(
        user_id:      auth.uid,
        password:     Devise.friendly_token,
        access_token: auth.credentials.token
      )
    else
      user.update(access_token: auth.credentials.token)
    end
    user
  end

The problem is occurring on callback, when Facebook redirects to my callback URL /auth/facebook/callback?code=AQBwiDEg01d0KUo8M-2EHlzjmcw_dsdfgfXaTys...&state=38ebb100a7f32...., more than half of the time this request gets timed out with execution expired message:

Started GET "/auth/failure?message=execution+expired&origin=https%3A%2F%2Fmyapplication.com%2F&strategy=facebook"

I tested to see if the code from my callback controller method is causing the issue and it's not. Even tested another app with similar setup from my colleague (which, he said, worked previously) and i faced the same problem there.

Checked the limits in my Facebook dashboard and i never had more than 1.5% Call Count Usage Rate.

Did anyone had this problem? + test your FB logins if you are using the same gems and similar code and let me know if you have the same problem if you have the time and will to do so.

Sometimes i log in 3-4 times in a row before it gets timed out for the fifth time and sometimes it get's timed out for 5 times in a row.

Any help would be appreciated.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source