Why doesn't the Devise + Omniauth callback get into the correct controller?

Can someone help me deal with this issue?

I am using Devise + Omniauth in a Rails 3.2 application. I want to know what happens behind the scenes using the Devise method user_omniauth_authorize_path(provider) .

I had digging through rake routes and a source of gems, but I see nothing obvious that could cause a problem that I am facing.

I assume that this method simply calls the provider subscriber URL (e.g. Twitter) and then returns to the callback path defined in route.rb.

On my routes .rb I have

 devise_for :users, :controllers => { :omniauth_callbacks => 'users/omniauth_callbacks'} devise_scope :user do get '/users/auth/:provider' => 'users/omniauth_callbacks#passthru' end 

Users / omniauth _callbacks_controller.rb I have

 def twitter render :text => "This works" end def passthru render :text => "This doesn't work" end 

In the view, I have <%= link_to "Twitter", user_omniauth_authorize_path(:twitter) %> . By clicking on this link, you will go to Twitter, where I can log in, but after returning to my application I get an error message "You are already logged in".

I cannot understand how and why this error is generated. I should see only โ€œIt worksโ€ or โ€œIt does not workโ€.

I also have a Facebook provider installed exactly as expected.

If I replace the Devise omniauth link with <a href="/users/auth/twitter">Twitter</a> , then I get "It works."

So this solves my problem, but it is not perfect, and I would like to know why.

Can anyone shed some light?

EDIT

Route routes are as follows:

 user_omniauth_callback /users/auth/:action/callback(.:format) users/omniauth_callbacks#(?-mix:twitter|facebook) 
+6
source share
1 answer

Well, this works for me, so this is definitely something at your end. First of all, did you compare in the console the GET calls /users/auth/twitter and /users/auth/twitter?callback received in two different ways? They should look exactly the same (with the exception of the marker and verifier, of course).

Now I'm not sure if this is related, but you are not using the passthru route during development, so you can delete this route. Instead, in your callback controller, you should perform an action called failure, which processes the invalid request. See here for development.

I grab the straw here, but you should also have this at the end of your callback controller:

 # This is necessary since Rails 3.0.4 # See https://github.com/intridea/omniauth/issues/185 # and http://www.arailsdemo.com/posts/44 protected def handle_unverified_request true end 
+1
source

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


All Articles