Omniauth-facebook cancel button

I started integrating facebook authentication into my Rails 3.1 website, but ran into a problem when I click the cancel button in the fb auth dialog box. When I click cancel, I am redirected back to my site in / auth / facebook / callback, and then redirected to the / login page (I use Devise).

What I want to do is redirect the canceled auth to a page that allows the user to create an account in the standard way (email address, username, password, etc.). How can I override the redirect to the / login page?

By the way, I am using the omniauth-facebook gem.

Thanks!

+6
source share
2 answers

Add the denial method to your omniauth callback controller and define your customized behavior.

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController def facebook @user = User.find_for_facebook_oauth(request.env["omniauth.auth"], current_user) if @user.persisted? sign_in_and_redirect @user, :event => :authentication #this will throw if @user is not activated set_flash_message(:notice, :success, :kind => "Facebook") if is_navigational_format? else session["devise.facebook_data"] = request.env["omniauth.auth"] redirect_to new_user_registration_url end end def failure redirect_to root_path // here end end 
+3
source

I think you can override the default on_failure behavior in your omniauth configuration, I do not use devise, but I use omniauth-facebook gem and was successful with variations:

 OmniAuth.config.on_failure = Proc.new { |env| OmniAuth::FailureEndpoint.new(env).redirect_to_failure } 

or something more ordinary:

 OmniAuth.config.on_failure do |env| new_path = "#{env['SCRIPT_NAME']}#{OmniAuth.config.path_prefix}/failure?message=#{error_type}" [302, {'Location' => new_path, 'Content-Type'=> 'text/html'}, []] end 
0
source

Source: https://habr.com/ru/post/915343/


All Articles