我在我的应用程序中使用Devise和Omniauth Google进行登录验证。一切正常,谷歌登录在我的本地主机上工作正常,但当我尝试在VPS上测试时,谷歌会抛出redirect_uri_mismatch。我无法弄清楚实际问题。请帮忙。
我的Gemfile
gem 'omniauth'
gem 'omniauth-oauth2', '~> 1.3.1'
gem 'omniauth-facebook'
gem "omniauth-google-oauth2"
VPS配置
Ruby v - ruby 2.0.0p643 (2015-02-25 revision 49749) [x86_64-linux]
Rails v - Rails 4.2.5
回调控制器
def google_oauth2
# 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?
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "Google"
sign_in_and_redirect @user, :event => :authentication
else
session["devise.google_data"] = request.env["omniauth.auth"].except("extra")
redirect_to new_user_registration_url
end
end
def failure
redirect_to root_path
end
路线
devise_for :users, :path => "member",:path_names => {:sign_in => 'login', :sign_out => 'logout', :sign_up => "register"}, :controllers => { :registrations => :registrations, :confirmations => 'confirmations', :omniauth_callbacks => "callbacks" }