Omniauth_google_oauth2 Error: redirect_uri_mismatch

Omniauth_google_oauth2 Error: redirect_uri_mismatch

我在我的应用程序中使用 Devise 和 Omniauth Google 进行登录身份验证。一切正常,Google 登录在我的本地主机上工作正常,但是当我尝试在 VPS 上测试时,Google 抛出 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" }

您需要add new redirect URI您的凭据

访问 your OAuth client credentials page 并添加 URI