【发布时间】:2018-01-03 00:07:44
【问题描述】:
我一直在尝试将 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})
我还在我的谷歌开发者控制台中添加了以下重定向 uri:
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/
提前感谢您的回答!
【问题讨论】:
-
尝试从
{:redirect_uri => "http://localhost:3000/users/auth/google_oauth2/callback"}删除主机(http://localhost:3000) -
如果这不起作用,请将
redirect_uri替换为callback_path。这对我有用。 -
我明白为什么这应该有效但仍然没有骰子。不过感谢您的尝试!
标签: ruby-on-rails devise omniauth google-developers-console omniauth-google-oauth2