我一直在尝试将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:
{ "错误" :" 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/
提前感谢您的回答!
答案 0 :(得分: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
}
希望能提供帮助