17

该 URL 似乎是正确的(昨天最后更新了它们):

在此处输入图像描述

文件也是:

omn​​iauth.rb:

provider :google_oauth2, 'MY_CLIENT_ID.apps.googleusercontent.com', 'MY_CLIENT_SECRET',
           :scope => 'https://mail.google.com/mail/feed/atom/'

Error: redirect_uri_mismatch
The redirect URI in the request: http://localhost:3000/auth/google_oauth2/callback did not match a registered redirect URI

header.html.erb

<li><%= link_to "Sign in with Google", "auth/google_oauth2" %></li>

路线.rb:

match '/auth/:provider/callback', to: 'sessions#omniauth_create'

但我得到了这个:

> Error: redirect_uri_mismatch The redirect URI in the request:
> http://localhost:3000/auth/google_oauth2/callback did not match a
> registered redirect URI

(Twitter 和 Facebook OmniAuth 运行良好)

不知道是什么问题。有什么建议可以解决这个问题吗?

编辑

我将URI更改为http...:

在此处输入图像描述

但仍然得到同样的错误。

4

5 回答 5

22

看起来请求正在命中http://localhost:3000/auth/google_oauth2/callback,但您指定的与类似模式匹配的重定向 URI 是 for https。添加http://localhost:3000/auth/google_oauth2/callback到您的重定向列表可能会解决该问题。

编辑:另一个潜在的解决方法是在相应的重定向 URI 中包含一个尾随/,这在这种情况下似乎有效。

于 2012-11-03T00:50:57.627 回答
4

omniauth-oauth2gem 版本有一个相对较新的问题1.4 https://github.com/intridea/omniauth-oauth2/issues/81#issuecomment-151038559

临时修复是在Gemfile

gem 'omniauth-oauth2', '~> 1.3.1'
于 2015-10-29T16:05:37.937 回答
0

在此处输入图像描述

vi config/initializers/omniauth.rb OmniAuth.config.full_host = 'https://localhost:3000' Rails.application.config.middleware.use OmniAuth::Builder do provider :google_oauth2, 'google_client_id', 'google_client_secret' end

于 2014-04-14T06:09:22.600 回答
0

分享一个对我有用的非常简单的复制粘贴解决方案。

我将我在代码中指定的内容复制为redirectUriie"redirect_uri": "http://127.0.0.1:3001/"并将其粘贴value到要求Authorized redirect URIskeyGoogle 设置中。这样我可以确保两个参数是相同的。

如果url是计算出来的,我会console.log()在将其粘贴到谷歌设置之前从控制台窗口复制它。

于 2015-09-07T03:55:53.630 回答
0

我尝试了以上所有方法,但对我没有用。最后在我的错误消息中注意到我的回电略有不同。我在 localhost:3000 和 auth 之间有一个用户。不太清楚为什么。

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

改变它,等了30分钟,它起作用了。

于 2016-02-16T02:16:48.617 回答