简体   繁体   English

未定义的方法skip_confirmation! - 设计,omniauth

[英]undefined method skip_confirmation! - devise, omniauth

Trying to set up facebook authentication using devise, omniauth (including facebook-omniauth) on an app hosted on heroku. 尝试使用devise,omniauth(包括facebook-omniauth)在heroku上托管的应用程序上设置facebook身份验证。 Call to facebook API works, but I do not manage to skip the confirmation step after callback. 调用facebook API有效,但我无法在回调后跳过确认步骤。

I followed the github tutorial on omniauth : https://github.com/plataformatec/devise/wiki/OmniAuth:-Overview 我关注了omniauth上的github教程: https ://github.com/plataformatec/devise/wiki/OmniAuth:-Overview

and also read and tried to implement this : Devise skip_confirmation! 并阅读并试图实现这一点: 设计skip_confirmation! not working 不工作

But I keep getting the following error in my heroku log : 但是我的heroku日志中不断出现以下错误:

NoMethodError (undefined method `skip_confirmation!')

Here is how my devise.rb looks : 以下是我的devise.rb的外观:

config.omniauth :facebook, "API_KEY", "API_SECRET"    

{:strategy_class => OmniAuth::Strategies::Facebook,
:scope => 'email, offline_access', :client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}}

Here is my omniauth_callbacks_controller.rb : 这是我的omniauth_callbacks_controller.rb:

class Users::OmniauthCallbacksController < Devise::OmniauthCallbacksController
  def facebook
   # You need to implement the method below in your model (e.g. app/models/user.rb)
   @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
end 

Here is my user.rb model : 这是我的user.rb模型:

def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
 user = User.where(:provider => auth.provider, :uid => auth.uid).first
 unless user
       user = User.new(name:auth.extra.raw_info.name,
                    provider:auth.provider,
                    uid:auth.uid,
                    email:auth.info.email,
                    password:Devise.friendly_token[0,20],
                    )
       user.skip_confirmation!
       user.save
  end
  user
end

Thanks for your help ! 谢谢你的帮助 !

So if I'm right (not 100% secure), you need to declare that your model has the module confirmable, add the confirmable module: 因此,如果我是对的(不是100%安全),您需要声明您的模型具有可确认的模块,添加可确认模块:

   devise :database_authenticatable, :registerable, :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :confirmable

And make sure that you have the fields for the confirmable module on your users table, you should have the fields confirmation_token and confirmed_at 并确保您的用户表上有可确认模块的字段,您应该有字段confirmation_token和confirmed_at

If you don't have those fields, check on this answer how to add them. 如果您没有这些字段,请查看此答案如何添加它们。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM