Facebook身份验证无法使用devise + omniauth facebook(管理员用户或测试用户除外)

时间:2014-08-27 20:01:31

标签: facebook ruby-on-rails-4 heroku devise omniauth

我在我的rails 4.1 app中使用devise和omniauth facebook进行用户身份验证。用户身份验证与Facebook的管理员用户和测试用户完美配合。但问题是当我尝试与其他Facebook用户签约时,无法创建新用户并将我重定向到localhost:3000 / users / sign_up# = 。我也在heroku上传了这个项目,但我遇到了同样的问题。

这是devise.rb

require "omniauth-facebook"
config.omniauth :facebook, "App_ID", "App_Secret"

route.rb文件:

devise_for :users, :controllers => { :omniauth_callbacks => "omniauth_callbacks" }

User.rb型号:

class User < ActiveRecord::Base

  has_many :users
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable

  def self.find_for_facebook_oauth(auth, signed_in_resource=nil)
    user = User.where(:provider => auth.provider, :uid => auth.uid).first
    if user
      return user
    else
      registered_user = User.where(:email => auth.info.email).first
      if registered_user
        return registered_user
      else
        user = User.create(name:auth.extra.raw_info.name,
                            provider:auth.provider,
                            uid:auth.uid,
                            email:auth.info.email,
                            first_name:auth.info.first_name,
                            last_name:auth.info.last_name,
                            image:auth.info.image,
                            location:auth.extra.raw_info.location,
                            gender:auth.extra.raw_info.gender,
                            oauth_token:auth.credentials.token,
                            password:Devise.friendly_token[0,20],
                          )
      end

    end
  end

  def facebook
    @facebook ||= Koala::Facebook::API.new(oauth_token)
  end
end

Omniauth_call_back_controller.rb

class OmniauthCallbacksController < Devise::OmniauthCallbacksController   
    def facebook
        @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

查看文件:

<%= link_to "Sign in with Facebook", user_omniauth_authorize_path(:facebook) %>

1 个答案:

答案 0 :(得分:0)

我想这不起作用,因为当你想要使用与应用程序的管理员/开发人员/测试人员之外的其他用户的扩展权限时,你需要通过FB审核你的应用程序

查看https://developers.facebook.com/docs/apps/review/login#do-you-need-review

上的文档