在https://code.google.com/apis/console网站上,我已经注册了我的应用程序,设置生成的客户端ID:和客户端秘密到我的应用程序,并尝试登录谷歌。 不幸的是,我收到了错误信息:

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

scope=https://www.googleapis.com/auth/userinfo.profile https://www.googleapis.com/auth/userinfo.email
response_type=code
redirect_uri=http://127.0.0.1:3000/auth/google_oauth2/callback
access_type=offline
approval_prompt=force
client_id=generated_id

这条信息是什么意思,我该如何修复它? 我使用宝石omniauth-google-oauth2。


当前回答

重定向URI(返回响应的地方)必须在api控制台中注册,错误指示您没有这样做,或者没有正确地这样做。

转到项目的控制台,在API Access下查看。您应该在那里看到您的客户端ID和客户端秘密,以及一个重定向uri列表。如果您想要的URI没有列出,单击编辑设置并将URI添加到列表中。

编辑:(来自下面评价很高的评论)请注意,更新谷歌api控制台和当前的更改可能需要一些时间。通常只有几分钟,但有时似乎更长。

其他回答

在我的情况下,我必须检查客户端ID类型的web应用程序/已安装的应用程序。

已安装的应用程序:http://localhost[重定向uri] 在这种情况下,localhost就可以工作了

web应用程序:您需要有效的域名[重定向uri:]

检查表:

HTTP还是https? &或&? 后面的斜杠(/)还是打开? (CMD/CTRL)+F,在证书页面中搜索精确匹配。如果 没有找到,那就去找失踪的那个。 等待谷歌刷新它。可能每半小时发生一次,如果你 经常更换,否则可能会留在池中。就我的情况而言,几乎用了半个小时才生效。

1.您将看到类似这样的错误

2.然后单击请求详细信息

在此之后,您必须复制该url并将其添加到https://console.cloud.google.com/

访问https://console.cloud.google.com/

点击菜单-> API和服务->凭证

你会看到一个这样的仪表板,点击编辑OAuth客户端 现在在授权Javascript起源和授权重定向url 添加显示错误的url,称为redirect_uri_mismatch,即这里 http://algorithammer.herokuapp.com,所以我在这两个地方都加了 授权Javascript源和授权重定向url 点击保存,等待5分钟,然后尝试再次登录

The trick is to input the right redirect url at the point of creating the ID. I found that updating the redirect url once the ID has been created via an 'Edit' just doesn't get the job done. What also worked for me is duplicating the entire 'vendor' folder and copying it to the same location where the 'oauth' file is (just until you successfully generate the token and then you can delete the duplicate 'vendor' folder). This is because trying to point to the vendor folder via '../vendor/autoload' didn't work for me.

因此,删除您现有的麻烦客户端OAuth ID,并尝试这种方法,它将工作。

我在谷歌登录时也遇到了同样的问题。

我已经在谷歌开发人员控制台的谷歌凭据面板中正确输入了我的回调 这是我的重定向网址:

https://www.example.com/signin-google

https://www.example.com/signin-google/

https://www.example.com/oauth2callback

https://www.example.com/oauth2callback/

一切似乎都很好,对吧?但它仍然没有工作,直到我添加了一个更神奇的Url,我添加了sign -google Url(这是默认的谷歌回调)没有www和问题解决。

考虑到这一点(取决于你的域名),你可能需要或不需要同时添加www url