Ali Sajid
Ali Sajid

Reputation: 4329

Authentication failure: omniauth

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'

Upvotes: 0

Views: 319

Answers (1)

toddmetheny
toddmetheny

Reputation: 4443

you just have a typo:

from_omniauthsk 

should be

from_omniauth

Upvotes: 1

Related Questions