Question

I have problem with omniauth-google-oath2 gem.

My code:

devise.rb

config.omniauth :google_oauth2, 'app_id','secret'

omniauth_callbacks_controller.rb

def google_oauth2
   auth = env["omniauth.auth"]

   @user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user) 
   if @user.persisted?
     flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
     sign_in_and_redirect @user, :event => :authentication
   else
     session["devise.google_uid"] = request.env["omniauth.auth"]
     redirect_to new_user_registration_url
   end
end

I also provide method for find_for_google_oauth2 in my user.rb model. In my html.erb I wrote:

<%= link_to "With Google", user_omniauth_authorize_path(:google_oauth2) %>

And in the end I have this error: No route matches {:controller=>"omniauth_callbacks", :action=>"passthru", :provider=>:google_oauth2, :format=>nil} missing required keys: [:provider]

Where is my mistake? Thanks for any advance!

Was it helpful?

Solution 2

I solved my problem. It was stupid :) I just restarted my local rails server and everything working fine.

OTHER TIPS

Check the user model for

devise :omniauthable, omniauth_providers: [:google_oauth2]

it's probably missing or wrong.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top