Rails google_omniauth2'错误:redirect_uri_mismatch'

问题描述 投票:2回答:1

我一直在尝试将google auth添加到我的注册页面,并按照guide中的步骤操作,但是一旦我登录到我的Google帐户,我就会被重定向到localhost:3000 /#并在我的控制台中出现以下错误:

E, [2018-01-02T18:21:05.351019 #57341] ERROR -- omniauth: (google_oauth2) Authentication failure! invalid_credentials: OAuth2::Error, redirect_uri_mismatch: 

{“error”:“redirect_uri_mismatch”}

我已经尝试了this existing stackoverflow线程中的所有解决方案,但这些用户都没有为我工作过。

我的设计.rb:

Devise.setup do |config|
config.stretches = Rails.env.test? ? 1 : 11
config.extend_remember_period = true
config.password_length = 2..72
config.sign_out_all_scopes = false
config.sign_out_via = :get



 OmniAuth.config.full_host = Rails.env.production? ? 
  'http://localhost:3000'
    config.omniauth(:facebook,
                  Rails.application.secrets.facebook_app_id,
                  Rails.application.secrets.facebook_api_key,
                  image_size: :large)
     config.omniauth(:google_oauth2,
                  Rails.application.secrets.google_client_id,
                  Rails.application.secrets.google_client_secret,
                  {:redirect_uri => 
     "http://localhost:3000/users/auth/google_oauth2/callback"}
     )
     require('devise/orm/active_record')
 end

的routes.rb

  r.devise_for(:users,
             only:        :omniauth_callbacks,
             controllers: {omniauth_callbacks: :omniauth})

我还将以下重定向uris添加到我的Google开发者控制台:

https://localhost:3000/users/auth/google_oauth2/callback https://localhost:3000/users/auth/google_oauth2/callback/ http://localhost:3000/users/auth/google_oauth2/callback http://localhost:3000/users/auth/google_oauth2/callback/

提前感谢您的回答!

ruby-on-rails devise omniauth google-developers-console omniauth-google-oauth2
1个回答
0
投票

我的问题结果只出现在添加:name选项时。一旦删除,这就像下面的工作正常:

config.omniauth :google_oauth2, ENV["GOOGLE_CLIENT_ID"], ENV["GOOGLE_CLIENT_SECRET"], {
  :scope => "email, profile",
  :prompt => "select_account",
  :image_aspect_ratio => "square",
  :image_size => 50
}

希望能有所帮助

© www.soinside.com 2019 - 2024. All rights reserved.