身份验证失败:omniauth [英] Authentication failure: omniauth

查看:150
本文介绍了身份验证失败:omniauth的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在按照 omniauth-facebook 的以下教程在我的Rails应用程序中配置来自facebook的身份验证方法:

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>

和代码段:

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

以下是我的session_controller文件:

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

模型(user.rb)

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 'omniauth-facebook'

推荐答案

您只有一个错字:

from_omniauthsk 

应该是

from_omniauth

这篇关于身份验证失败:omniauth的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆