Handling OmniAuth::Strategies::OAuth2::CallbackError in OmniAuth

Michael Giovanni Pumo

How can I handle the error:

OmniAuth::Strategies::OAuth2::CallbackError

...generated by OmniAuth when a user goes through to the Facebook login, but decides to cancel?

I have seen a few threads about this, but none of the solutions worked for me.

I tried placing this:

OmniAuth.config.on_failure = UsersController.action(:oauth_failure)

...into the omniauth.rb initializer file with no success.

I am using the omniauth-facebook gem with Rails 4.0.2.

Any help greatly appreciated.

Many thanks! Michael.

My gemfile.lock file reveals the following gems related to the omniauth-facebook gem:

oauth2 (0.8.1)
  faraday (~> 0.8)
  httpauth (~> 0.1)
  jwt (~> 0.1.4)
  multi_json (~> 1.0)
  rack (~> 1.2)
omniauth (1.1.4)
  hashie (>= 1.2, < 3)
  rack
omniauth-facebook (1.5.1)
  omniauth-oauth2 (~> 1.1.0)
omniauth-oauth2 (1.1.1)
  oauth2 (~> 0.8.0)
  omniauth (~> 1.0)
Michael Giovanni Pumo

I upgraded the omniauth-facebook gem to version 1.0.6 and now it is working as expected.

For anyone else coming across this issue and would like to capture this error, here's what you need:

/config/initializers/omniauth.rb

Rails.application.config.middleware.use OmniAuth::Builder do

    provider :facebook, 'xxx', 'xxx', scope: "email,publish_stream,user_location,user_birthday"

end

/config/initializers/omniauth_failure_callback.rb

OmniAuth.config.on_failure = Proc.new do |env|

    UsersController.action(:omniauth_failure).call(env)

end

/app/controllers/users_controller.rb

def omniauth_failure

    flash[:danger] = "Unable to connect with Facebook at this time."
    redirect_to root_url

end

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

CallbackError with OmniAuth When Proxying Through Nginx

From Dev

difference between OAuth2 and Omniauth

From Dev

difference between OAuth2 and Omniauth

From Dev

Rails - Strategies for avoiding OmniAuth and sharing computer risks

From Dev

Omniauth and google oauth2 error without Devise - Rails 4

From Dev

Google oauth2 with devise and omniauth processed as failure

From Dev

Omniauth Callback

From Dev

Spotify Omniauth

From Dev

Omniauth Callback

From Dev

Getting "Authentication failure! invalid_credentials: OAuth2::Error" for custom omniauth strategy

From Dev

Google Oauth Login with omniauth-google-oauth2 failed frequently

From Dev

LinkedIn Omniauth OAuth 2 in Rails - Authentication failure for bad redirect

From Dev

Refresh token using Omniauth-oauth2 in Rails application

From Dev

Omniauth_google_oauth2 Error: redirect_uri_mismatch

From Dev

Rails 4 - Devise Omniauth and allowing a single user to authenticate with multiple social media strategies

From Dev

Omniauth-identity InvalidAuthenticityToken

From Dev

Omniauth facebook - fetch friends

From Dev

Devise with OmniAuth Facebook

From Dev

Devise + Omniauth No Initializer file

From Dev

Omniauth not responding to GET Request

From Dev

Rails omniauth not refreshing data

From Dev

"CSRF detected" with Omniauth and Google

From Dev

Adding omniauth to devise routes

From Dev

Error In Omniauth with Google

From Dev

OmniAuth Facebook added to Devise

From Dev

Omniauth/MYSQL awkwardness in Rails

From Dev

Rails omniauth not refreshing data

From Dev

Rails devise pundit omniauth

From Dev

Omniauth-identity InvalidAuthenticityToken