2015-09-19 15 views
0

當我嘗試驗證,我得到的消息:我定義了一個控制器方法google_oauth2的色器件,但它仍然缺少

"Not found. Authentication passthru." 

我添加了一個action_missing方法得到一個線索:當它叫,它日誌:

Parameters: {"provider"=>"google_oauth2"} 

因此,看來我得到一個抱怨,我錯過了我定義的方法。爲什麼我的行爲在定義時缺失?

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController 
    def google_oauth2 
    @user = User.from_omniauth(request.env["omniauth.auth"]) 

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

    def action_missing(provider) 
    logger.debug provider 
    end 

end 

devise.rb:

config.omniauth :google_oauth2, 
    'my', 
    'secret', 
    { 
     :name => "google", 
     :scope => 'email, profile', 
     :prompt => 'select_account', 
     :image_aspect_ratio => 'square', 
     :image_size => 50 
    } 

User.rb:

class User < ActiveRecord::Base 
    devise :omniauthable, :omniauth_providers => [:google_oauth2] 
    def self.from_omniauth(access_token) 
    data = access_token.info 
    user = User.where(:email => data["email"]).first 

    # Uncomment the section below if you want users to be created if they don't exist 
    # unless user 
    #  user = User.create(name: data["name"], 
    #  email: data["email"], 
    #  password: Devise.friendly_token[0,20] 
    # ) 
    # end 
    user 
    end 
end 

回答

0

我發現我的錯誤,別人可能會覺得有啓發:

在devise.rb

,我有:

{ 
     :name => 'google', 
     :scope => 'email, profile', 
     :prompt => 'select_account', 
     :image_aspect_ratio => 'square', 
     :image_size => 50 
    } 

第一項:name從另一個omniauth教程中複製而來。這似乎是一個非常糟糕的主意。刪除它使事情發展下去。

相關問題