Devise omniauth-facebook redirect_uri Url必须绝对 [英] Devise omniauth-facebook redirect_uri Url must absolute
本文介绍了Devise omniauth-facebook redirect_uri Url必须绝对的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的Rails应用程序,当我试图集成 gemomniauth-facebook
与设计,我在Facebook上收到以下错误: redirect_uri URL必须是绝对的
。
My Rails app when I tried to integrate gem "omniauth-facebook"
with devise, I receive the following error on facebook: The redirect_uri URL must be absolute
.
以下是我的配置
devise.rb
devise.rb
config.omniauth :facebook, "ID", "SECRET",callback_url: "/auth/facebook"
我的user.rb模型:
My user.rb model:
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"}
和控制器OmniauthCallbacksController
And 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
什么我在这里错过了吗?
What am I missing here?
推荐答案
添加
:client_options => {:ssl => {:ca_file => '/usr/lib/ssl/certs/ca-certificates.crt'}}
至<$初始化程序中的c $ c> config.omniauth 解决了我的问题。
我还配置了路径
绝对如此:
callback_url: ENV['SERVER_ROOT']+'/users/auth/facebook/callback'
这篇关于Devise omniauth-facebook redirect_uri Url必须绝对的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文