Authentication failure: omniauth

﹥>﹥吖頭↗ 提交于 2019-12-12 01:42:58

问题


I am following the below tutorial of omniauth-facebook for configuring the authentication method from facebook in my rails application:

http://railscasts.com/episodes/360-facebook-authentication

Everything is running fine but after callback I'm getting the following error:

undefined method `from_omniauth' for #<Class:0x007ff05a58de30>

and the code snippet:

class SessionsController < ApplicationController
  def create
    user = User.from_omniauth(env["omniauth.auth"]) #Highligted line as red
    session[:user_id] = user.id
    redirect_to root_url
  end

Following is my session_controller file:

class SessionsController < ApplicationController
  def create
    user = User.from_omniauth(env["omniauth.auth"])
    session[:user_id] = user.id
    redirect_to root_url
  end

  def destroy
    session[:user_id] = nil
    redirect_to root_url
  end
end

Model (user.rb)

class User < ActiveRecord::Base
  def self.from_omniauthsk(auth)
    where(auth.slice(:provider, :uid)).first_or_initialize.tap do |user|
      user.provider = auth.provider
      user.uid = auth.uid
      user.name = auth.info.name
      user.oauth_token = auth.credentials.token
      user.oauth_expires_at = Time.at(auth.credentials.expires_at)
      user.save!
    end
  end
end

Gem I'm using is

gem 'omniauth-facebook'

回答1:


you just have a typo:

from_omniauthsk 

should be

from_omniauth


来源:https://stackoverflow.com/questions/36114675/authentication-failure-omniauth

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!