设计omniauth-facebook redirect_uri网址必须绝对

时间:2015-12-16 05:19:38

标签: ruby-on-rails ruby facebook ruby-on-rails-3 devise

当我尝试将gem "omniauth-facebook"与设计集成时,

我的Rails应用,我在Facebook上收到以下错误:The redirect_uri URL must be absolute

以下是我的配置

devise.rb

config.omniauth :facebook, "ID", "SECRET",callback_url: "/auth/facebook"

我的user.rb型号:

class User < ActiveRecord::Base
  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable
  devise :database_authenticatable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable, :omniauthable, :omniauth_providers => [:facebook]

  def self.from_omniauth(auth)
        where(provider: auth.provider, uid: auth.uid).first_or_create do |user|
        user.email = auth.info.email
        user.password = Devise.friendly_token[0,20]
        user.name = auth.info.name   # assuming the user model has a name
        user.image = auth.info.image # assuming the user model has an image
      end
    end
end

我的路线:

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

和Controller OmniauthCallbacksController

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.from_omniauth(request.env["omniauth.auth"])

    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

  def failure
    redirect_to root_path
  end
end

我在这里缺少什么?

1 个答案:

答案 0 :(得分:0)

添加

:client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}} 

初始化程序中的config.omniauth为我解决了问题。

我还将path配置为绝对如此:

callback_url: ENV['SERVER_ROOT']+'/users/auth/facebook/callback'