Kashiftufail
Kashiftufail

Reputation: 10885

The action 'google_oauth2' could not be found for Users::OmniauthCallbacksController

I'm using 'omniauth-google-oauth2' for sign in with google and follow all instruction here carefully

   https://github.com/plataformatec/devise/wiki/OmniAuth%3A-Overview

but i have error above.

my routes

    devise_for :users, :controllers => {
      :omniauth_callbacks => "users/omniauth_callbacks"

    }

devise.rb code

  config.omniauth :google_oauth2, "863625299460- 420n6c7lvad91dfvko60uamtvtr6huhf.apps.googleusercontent.com", "dcvA2aZRZi27KCQjWTYP30pw", {  access_type: "offline", approval_prompt: "" }

omniauth callback controller code

     def google_oauth2
       #@user = User.find_for_google_oauth2(request.env["omniauth.auth"], current_user)
       binding.pry #control not coming here
     end

i have error below after callback. see screenshot

    https://github.com/zquestz/omniauth-google-oauth2/issues/52

Upvotes: 3

Views: 2400

Answers (3)

Ankita.P
Ankita.P

Reputation: 442

It's very late but this answer might be useful for others

If you are using devise for authentication then devise by default generates routes in the route file devise_for :users and your omniouth_callback route should be above the default devise route so that it overwrites default devise route.

  devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks"}
  devise_for :users

Upvotes: 0

Jon M.
Jon M.

Reputation: 3548

I had exactly the same problem you described. Make sure you require the omniauth-google-oauth2 gem in config/initializers/deviser.rb

# ==> OmniAuth
# Add a new OmniAuth provider. Check the wiki for more information on setting
# up on your models and hooks.
require "omniauth-google-oauth2"
config.omniauth :google_oauth2, ENV["GOOGLE_KEY"], ENV["GOOGLE_SECRET"],
                                { access_type: "offline", approval_prompt: "force" }

I've added the entire portion of my devise.rb file to provide context.

Upvotes: 0

quest
quest

Reputation: 776

This looks like a route issue. If you do "rake routes | grep auth" what do you see?

Upvotes: 1

Related Questions